1
\$\begingroup\$

My code is supposed to check a 50Hz signal with AVR ATMEGA32's ADC. It works at 6MHz with an external clock in both real and simulator. But when I use a 12MHz external clock the ADC doesn't work well at all in real and it almost missed the AC signals.

When I use the simulator, it's perfect but in real it's not.. I have set the fuse bit and I turn the ADC on and off before any reading.

Any idea? thx

\$\endgroup\$
  • 1
    \$\begingroup\$ With some AVRs you need certain minimum voltages for higher clock speeds, could be that? \$\endgroup\$ – Toby Jaffey Aug 19 '10 at 12:54
  • \$\begingroup\$ It would help guessing if you could show what exactly doesn't work and how. Maybe make a minimal test program that works on slow clock but not on a fast one. \$\endgroup\$ – XTL Aug 20 '10 at 5:28
3
\$\begingroup\$

You might need to slow down the ADC. The analog to digital converter runs at half the system clock frequency by default so at 6MHz the ADC's input clock is at 3MHz. Setting ADCSRA |= 2 (for the ATmega328, datasheet section 23.9.2, page 265) divides the clock by 4 instead of by 2. 12MHz / 4 = 6MHz / 2 = 3MHz.

\$\endgroup\$
  • \$\begingroup\$ Hi, I have tried these division factors: 128, 64, 32, 16. in 6Mhz it works with every one of them, but in 12Mhz it has no effect at all. I used ADCSRA=0x87 (for example) in my CodeVision initialization code. thanks \$\endgroup\$ – soheil Aug 21 '10 at 13:46
  • \$\begingroup\$ Are you using a bypass capacitor between Vcc and GND? Have you tried filtering the analog vcc / aref as recommended in the datasheet? Are you using a solderless breadboard that can't handle high frequencies instead of a PCB? \$\endgroup\$ – joeforker Aug 22 '10 at 1:38
0
\$\begingroup\$

Make sure the the atmega itself support 12 Mhz

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy