ADC Noise Canceller

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I want to use the ADC noise canceler on the ATMEGA328PB. If there is an other interrupt before the ADC conversion completes, the ADC conversion continues in active mode.

 

Is there any simple method to figure out that this happened when the ADC conversion is complete? I'd like to throw away those "interrupted" ADC conversions to get most accurate results.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Have a volatile global variable. When you start the adc, zero the variable. Any isrs will increment the variable. When the adc completes, test the value of the variable. If not 0, it was interrupted.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Can you not just disable interrupts until after the conversion completes?

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I thought the way "noise cancel" works in most AVRs is you set everything up for the ADC reading then "SLEEP" and it does the ADC conversion in sleep mode then awakes at the end - as so nothing can occur to "interrupt" the ADC process. Is this not what you are using?

 

EDIT: I mean this....

 

Last Edited: Tue. Oct 15, 2019 - 12:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I thought the way "noise cancel" works in most AVRs is you set everything up for the ADC reading then "SLEEP" and it does the ADC conversion in sleep mode then awakes at the end - as so nothing can occur to "interrupt" the ADC process.

Which isn't what you quoted; OP's question is on

 If
another interrupt wakes up the CPU before the ADC conversion is complete, that
interrupt will be executed, and an ADC Conversion Complete interrupt request will be
generated when the ADC conversion completes.

And thus OP's question.

 

Now, I have quite a few thoughts/questions on that:

A)  What difference does it matter to you, the OP?

A1)  Can't you just take Jim's advice and not have any other interrupt sources active?

 

B)  A conversion takes about 100us.  What is so important during that time?

 

C)  Kartman recommends a global variable.  Be still, my heart!  Anyway, that won't tell what source, as OP requested.  Now I have to look at the ADC-sleep chart -- are timers running?  It appears not.  I was going to suggest the triggered interrupt(s) read TCNT and store that as the flag.  If 0, then no hit.  Inf non-0 then earliest wins.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 so nothing can occur to "interrupt" the ADC process

 The ADC process isn't interrupted, but the CPU can still be woken up by some other interrupt during the conversion. This would defeat the benefits of the noise cancel mode. He wants to detect it that has happened. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mrono wrote:
the CPU can still be woken up by some other interrupt during the conversion

so disable other interrupt sources during this time....

The mpu is sleeping so not doing anything anyway, and timers are stopped...

any external interrupt source will set a flag that can be processed after ADC complete wakeup.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Tue. Oct 15, 2019 - 03:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
that won't tell what source, as OP requested

Did (s)he?

 

My reading was that OP just wanted to know that it had happened.

 

But Kartman's suggestion could easily be adapted to identify the specific source(s); eg, make it a bitmap ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks, thats a good idea. I hoped there might be some register bit that's automatically set (or cleared) by the hardware.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

clawson wrote:
I thought the way "noise cancel" works in most AVRs is you set everything up for the ADC reading then "SLEEP" and it does the ADC conversion in sleep mode then awakes at the end - as so nothing can occur to "interrupt" the ADC process.

Which isn't what you quoted; OP's question is on

 If
another interrupt wakes up the CPU before the ADC conversion is complete, that
interrupt will be executed, and an ADC Conversion Complete interrupt request will be
generated when the ADC conversion completes.

And thus OP's question.

 

Now, I have quite a few thoughts/questions on that:

A)  What difference does it matter to you, the OP?

A1)  Can't you just take Jim's advice and not have any other interrupt sources active?

 

B)  A conversion takes about 100us.  What is so important during that time?

 

C)  Kartman recommends a global variable.  Be still, my heart!  Anyway, that won't tell what source, as OP requested.  Now I have to look at the ADC-sleep chart -- are timers running?  It appears not.  I was going to suggest the triggered interrupt(s) read TCNT and store that as the flag.  If 0, then no hit.  Inf non-0 then earliest wins.

 

 

 

I don't care about the interrupt source, I just wan't to know if there was an interrupt at all. Even a single flag bit will be sufficient.

However, after reading the section about noise reduction mode again I recognized that most interrupts are disabled in ADC noise reduction mode anyway. In my case only the async timer would be left as interrupt source.

 

 

Last Edited: Tue. Oct 15, 2019 - 03:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can also take a few averages & that will also account for noise in your system or sensor signal...that may be more beneficial.   I've never used the noise canceler & can get within one count.

Interrupts themselves don't cause any noise (any more than any other code). Are you seeing lots of noise?  How many counts?  If so, you may have a layout or wiring or bypass cap issue. Did you include an inductor on Avcc? If you are using Vcc as the reference, it needs to be clean (or take averages).  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Oct 15, 2019 - 04:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This idea is completely untested. AVR's always execute one instruction after an interrupt before another interrupt is serviced. IF this also applies to exiting sleep (as I believe I once read somewhere), then this should work:

 

Immediately after the sleep command, disable interrupts. Then save a copy of ADC status. Finally re-enable interrupts and let whatever interrupt that initiated the wakeup, happen. After that, you can examine the saved ADC status. If the ADC wasn't finished when you took the copy, it was another interrupt waking the AVR.

The advantage of this approach is that you don't need to increment a counter in all other possible interrupts, or forgetting to do so when you revisit the code some years from now.

 

But, as I wrote, completely untested.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Eauth,

 

It would be really interesting if, after all of your research and coding, you posted some graphs of your signal vs ADC output without the Noise Canceler and with then Noise Canceler.

It would be nice to see how big of an improvement it made in your real-world project.

 

JC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

Eauth,

 

It would be really interesting if, after all of your research and coding, you posted some graphs of your signal vs ADC output without the Noise Canceler and with then Noise Canceler.

It would be nice to see how big of an improvement it made in your real-world project.

 

JC

 

 

I'll post the results as soon as I'm finished with my prototypes, the software is still in progress.