ATmega168 ad testing

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
geir102
 
Posts: 60
Joined: Sat Mar 29, 2008 3:01 pm

ATmega168 ad testing

Post by geir102 »

Hi, im playing around a little whit the Atmega168 AD, just for learning. Im trying to "read" a servo signal. That is a pwm whit 1,5ms high and 20ms low. So it's a low frequency. The problem is, when the signal is high it just reads hi some times. I've attached a file, i shows better what i mean. The avr is running om 8 mhz. Any one know way it's like this?
The code I'm using:
a2dSetPrescaler(ADC_PRESCALE_DIV32);
a2dSetReference(ADC_REFERENCE_AVCC);
while(1)
{
v=a2dConvert8bit(5);
uart_send(v);
}
Attachments
servo.jpg
servo.jpg (48.87 KiB) Viewed 2164 times

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: ATmega168 ad testing

Post by Franklin97355 »

Where are you getting the servo signal?

geir102
 
Posts: 60
Joined: Sat Mar 29, 2008 3:01 pm

Re: ATmega168 ad testing

Post by geir102 »

It's from a basic stamp2.

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: ATmega168 ad testing

Post by westfw »

Why are you using the A-D to read the servo signal?

I didn't see a call to a2dinit()...

geir102
 
Posts: 60
Joined: Sat Mar 29, 2008 3:01 pm

Re: ATmega168 ad testing

Post by geir102 »

a2dinit() is there just got cut away. I tryed it whit just reading if the port was high to same result.

User avatar
davidbear
 
Posts: 21
Joined: Wed Feb 25, 2009 12:21 am

Re: ATmega168 ad testing

Post by davidbear »

Why don't you try adding some 100 microsecond delays and store the info in an array. After doing this for a couple of periods, upload the stored data. I suspect that your communication is causing the intermittent data drop out, although I could be wrong. I have written some relavent code for an arduino that can be found here: http://www.byrote.org/arduino/

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”