Author Topic: Doubt in ADC on atmega8, unable to locate fault.  (Read 2562 times)

0 Members and 1 Guest are viewing this topic.

Offline brainwaveTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Doubt in ADC on atmega8, unable to locate fault.
« on: June 09, 2011, 03:53:01 AM »
I want to blink an led using the 'timer' peripheral on atmega8. But the delay between switching of the led is to be determined by an analog voltage applied on port C 5.

The program attached is to do the following function-
1. Initialise the ADMUX register to use port C 5 as input of analog voltage, with Aref as the reference voltage.

2. Initialize the timer0 on the chip to start counting

3. Enclose adc start in single conversion mode in a while loop

4. A variable 'volt' stores the result of the a/d conversion (only ADCH is read, last 2 lsb's are ignored)

5. The Timer0 Overflow interrupt, when triggered, switched the adc interrupt off, reads value of 'volt' and appropriately sets the delay period of the led switching

But this isnt working. Can you tell me where i made a mistake?

Offline brainwaveTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #1 on: June 09, 2011, 01:39:00 PM »
no ones helping!!!!! whats wrong?

Offline adanvasco

  • Full Member
  • ***
  • Posts: 107
  • Helpful? 6
  • Necessity is the mother of invention.
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #2 on: June 09, 2011, 02:10:45 PM »
i is initialised to 0 and vlt to 4. If the ADC does not reach that threshold, i is never going to be >=4. Also, are you getting an integer from the ADC? If you're not, then the value might be getting truncated.
I'm pretty new to embedded programming but that's what I get from your code. I hope it helps.
Knowledge does not weigh.

Offline brainwaveTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #3 on: June 09, 2011, 02:21:16 PM »
i did not understand your first statement- 'adc does not reach that threshold'...can u explain it?

a problem i found was i wasnt prescaling the frequency to a good range....and then i programmed my adps bits properly.....still its not working.

Offline adanvasco

  • Full Member
  • ***
  • Posts: 107
  • Helpful? 6
  • Necessity is the mother of invention.
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #4 on: June 09, 2011, 02:24:45 PM »
What I meant is the value you are getting might be smaller than 4 which is what your vlt variable is set to initially.
Knowledge does not weigh.

Offline brainwaveTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #5 on: June 09, 2011, 02:36:42 PM »
doesnt matter, its ok if its smaller than volt initial value which is 4. the delay between the led blink should get smaller thats the only idea. But the outcome is a constant delay, much much longer than 4. Thats the problem.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #6 on: June 09, 2011, 10:36:39 PM »
Which part isn't working? What's it doing instead?

I recommend breaking this up into smaller parts, and try to figure out which part works and which doesn't.

Offline brainwaveTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #7 on: June 09, 2011, 10:46:56 PM »
The LED should blink initially with a 2-3 second delay, as i am applying( the circuit i made is such) around 2.3 volts. But, it isnt doing that. Instead it is woeking with a large delay of around 10 seconds.

Further on changing the voltage to something close to zero, the led should blink fast. Thats not happening either.

[EDIT]

One bug i found was that the condition in ISR(TIMER0_OVF_vect) says that 'i==volt'...i changed it to i>volt in case thats some problem.
« Last Edit: June 09, 2011, 10:49:51 PM by brainwave »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #8 on: June 09, 2011, 11:00:18 PM »
Did you unprogram the clock div8 fuse?

Also, check for timer prescaling mistakes . . .




it's late and I'm sleepy . . . good luck! :P

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Doubt in ADC on atmega8, unable to locate fault.
« Reply #9 on: June 26, 2011, 12:35:09 PM »
I know this is a kinda old thread but...

I don't know about enclosing the "ADC start in single conversion mode" in a while loop is a problem or not.

You're basically telling it to start over and over and over and over and over again until the ADC or timer interrupt happens.  Maybe it just keeps starting but you never let it finish? 

 


Get Your Ad Here