ADC problems on Mega168

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

I'm having a strange problem with the ADC on a Mega168. I'm using it in a fairly high power voltage converter for one of my high voltage projects. I've made dozens of these without any trouble, but this one is a bit higher powered than the rest. Anyway, the problem is the ADC interrupt stops. Everything runs nicely until suddenly there are no more ADC interrupts and the converter just sticks at whatever value it happens to be. I don't know whether it's because it aborts the conversion, or because the int enable bit or the int flag itself gets reset, or maybe the entire ADC subsystem gets reset. This only happens during load shedding, when it switches from a large load (3A peak current) to a light load (1A or less). Obviously when that happens there's some overshoot from the energy stored in the inductor, so I'm hoping it's just a noise problem that will go away if I make another prototype. I'll try emulating it with DebugWire when I have time and hopefully find out exactly what's going on, but meantime I throw it out here in case anyone else has seen this and has some advice.

Edit: correction: I'm running it on a Mega48 at present, not a 168.

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

Hi,

do you have CKOPT set? Maybe it´s confusing your clock.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

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

No, I'm running on 8MHz internal RC. The clock continues running just fine because switching pulses still come out of the PWM pins. That reminds me, though. When I'm in no-ADC-int mode, I still have some HV output, but no regulation. If I increase the output load at that time, the voltage drops, and so does the ADC input voltage drop in proportion. As it does, I noticed the PWM pulses slow down a little, meaning the main RC clock slows down a little. The Vcc doesn't change, however. The only thing that changes is the analog voltage into the ADC. But it shouldn't be injecting any meaningful current, because it can source less than 250uA and never goes above 1V.

I'm sure this is "fault behavior", not something that can be fixed in software. My money is on some kind of noise induced SCR latchup on the analog pin, causing some mysterious internal side effects. But I do need to know exactly what happens and how to prevent it and, if possible, how to recover from it without a reset. Configuring the pin as an output and driving it high and low might clear it. I'll try that tomorrow.

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

How are you handling the analogue signal input into the ADC?

--

"If it wasn't for bad luck I'd have no luck at all"

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

Quote:
Configuring the pin as an output and driving it high and low might clear it. I'll try that tomorrow.

I think you mean this:
for example toggeling a pin every time you start/read the ADC.

That´s what i recommend.
Maybe different pins for different pieces of software...
using a scope to see their state

Klaus
********************************
Look at: www.megausb.de (German)
********************************

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

Quote:
I think you mean this: for example toggeling a pin every time you start/read the ADC.

No, I already do that - it's how I know the interrupts stop. I mean turning the ADC off entirely, changing its analog input to a digital output and driving it up and down in an attempt to clear the latchup, if that's what it is. I'm also going to sync the ADC with the PWM, instead of letting them free run independently.

@DaveEvans: currently 470k and ferrite bead to high voltage, 1k plus 0.001 cap to ground. I generally use jusr the two Rs alone, since the cap greatly increases the output ripple.

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

Quote:
As it does, I noticed the PWM pulses slow down a little, meaning the main RC clock slows down a little.

Not sure if this is related to your situation, but,
I have observed erratic behaviour of the internal
RC clock when certain i/o pins are driven beyond
the supply rails with *low* currents, in the vicinity
of only 200-250 ua! I was using a 100k series
resistor from 24 vac to a PORTD pin on the M88.
When the signal would swing negative, large frequency
shifts in the clock frequency whould happen. The
problem was noticed as serial comms errors when
some arbitrary threshold current at the port pin was
crossed. Very unexpected and strange, and something
to watch out for when applying these devices!

Tom Pappano
Tulsa, Oklahoma

Tom Pappano
Tulsa, Oklahoma

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

Quote:
I have observed erratic behaviour of the internal RC clock ...

Yes, I've noticed that too. When I was working on the scope clock power supply I found that at startup, when the converter was working hardest, the internal clock would slow by a huge factor, like 8 or 10. This of course extended the PWM pulse way beyond what was safe and wasted several power FETs before I worked out what was going on. Layout cured that, but still it seems these devices are not as robust and trouble free as I used to believe.

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

Reviving this thread to round it off, I believe I tracked the problem down. It was nothing to do with the ADC - it was drain-to-gate breakdown in a damaged power FET. On the flyback, when the drain voltage rose above some threshold, some or all of the inductor energy crossed over to the gate and thence to the AVR pin driving it. Since the PWM pin was being driven low whenever this happened, there was nothing to see with a scope; but the current spike must have been bouncing the chip ground internally and causing some parts of it to reset. With a replacement FET, the several AVRs I set aside as "possibly broken" all work just fine, so there's no permanent damage. The FET breakdown is easily explained - suddenly removing the load on a high(ish) power convertor made the output jump up high enough above the FET rated voltage to compromise the gate insulation.

I found it because another board that had been working fine suddenly developed this problem after I had an "accident" with the high voltage. Naturally the power FET was the very last component I thought of, because there was nothing else left on the board that hadn't already been replaced :oops: What confused me is that the sucker still worked, switching on and off as prescribed, until the output reached about 130V when it all went haywire. Putting a resistor in series with the gate disclosed the cause of the problem.

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

Quote:

Anyway, the problem is the ADC interrupt stops.

Quote:

...but the current spike must have been bouncing the chip ground internally and causing some parts of it to reset. ...

We had an app with the same symptom (among others). It was driving a pilot relay which drove a motor contractor. When there was not proper varistor protection, the app would "fail" in weird ways, one of which was that an ADC conversion appeared to never complete. Since the ADC ISR starts the next conversion ...

Add varistors and then zap the heck out of it--works fine.

This was on a Mega64. We >>did<< capture some spikes on a 'scope and they were indeed ugly.

AVR's ain't bad for noise immunity, but if you hit them hard enough, something will muck up.

The app over-sampled and averaged A/D readings over a half-second period anyway, so I had a convenient way of knowing about this particular failure and re-starting the ADC. Repeated traps and I force a watchdog and restart. Not a solution, but it took us a long time to narrow down the source of the problem as it did you.

Lee

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.