Don't use PWM output to drive the unit. Have you seen
http://www.barello.net/Papers/GP2D02?
The assembly code is complex since it multiplexes three sensors but at it's
core it is simple, it does the clocking and shifting of data in s/w which is
more than fast enough and easy to control. I paraphrase below, for one
sensor (I used 9 for the loop to discard the first bit, you could re-arrange
and make it 8 loops):
Set control port pin low
wait for input pin to go high (or a max of 30ms IIRC)
for (i = 0; i< 9; i++)
{
if input high
output |= 1; // Set low bit
output << 1; // Left shift
set control pin low // Clock in next bit
wait 1 us
set control pin high
wait 16 us
}
set control pin high.
At the end of the routine your data should be in "output" and the sensor
should be in a low-power state ready for another reading. Please make sure
the code you write follows the clock diagram in the data sheet. I just
paraphrased assembly code I wrote over 7 years ago and might have made a
mistake or two...
-----------
Larry Barello
www.barello.net
| -----Original Message-----
| From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
| Of katraven1
| Sent: Thursday, August 31, 2006 8:54 AM
| To: AVR-Chat@yahoogroups.com
| Subject: [QUARANTINE] [AVR-Chat] GP2D02 + ATmega32
| Importance: Low
|
| Hey guys, me again =P
|
| I've been spending the last couple of days trying to get one ex-Sharp
| infrared sensor to communicate wif my ATmega32. It's jst connected to
| the OC0 pin on PORTB generating a pwm to read a signal and the output
| of the sensor to one of the other IO pins, similar as used on the
| Dilberts (thx Larry!)
|
| However, as the output of the sensor is in serial, I can't quite get
| the timing right to read it properly...
|
| I've read the previous post which converts code for the BSII to C
| (http://groups.yahoo.com/group/AVR-Chat/message/7190) but I'm not
| quite sure how to build on top of that...
|
| *boggled yet again....
|
|
|
|
|
|
|
| Yahoo! Groups Links
|
|
|
|
|Message
RE: [AVR-Chat] GP2D02 + ATmega32
2006-08-31 by Larry Barello
Attachments
- No local attachments were found for this message.