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);
}
ATmega168 ad testing
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 60
- Joined: Sat Mar 29, 2008 3:01 pm
ATmega168 ad testing
- Attachments
-
- servo.jpg (48.87 KiB) Viewed 2164 times
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: ATmega168 ad testing
Where are you getting the servo signal?
-
- Posts: 60
- Joined: Sat Mar 29, 2008 3:01 pm
Re: ATmega168 ad testing
It's from a basic stamp2.
- westfw
- Posts: 2008
- Joined: Fri Apr 27, 2007 1:01 pm
Re: ATmega168 ad testing
Why are you using the A-D to read the servo signal?
I didn't see a call to a2dinit()...
I didn't see a call to a2dinit()...
-
- Posts: 60
- Joined: Sat Mar 29, 2008 3:01 pm
Re: ATmega168 ad testing
a2dinit() is there just got cut away. I tryed it whit just reading if the port was high to same result.
- davidbear
- Posts: 21
- Joined: Wed Feb 25, 2009 12:21 am
Re: ATmega168 ad testing
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/
Please be positive and constructive with your questions and comments.