go_away

Author Topic: Help with atmega timer (RC5 decoder)  (Read 7055 times)

0 Members and 1 Guest are viewing this topic.

Offline izuaTopic starter

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Help with atmega timer (RC5 decoder)
« on: July 27, 2008, 04:42:00 PM »
Hi. I'm building an RC5 decoder via interrupts. It worked flawlessly with _delay_us (1778), yet it sucks with sampling timers.

Basically, I have a 16MHz atmega16.
RC5 has a sample time of 1778 us (if we use only one phase of manchester). That goes to something around 562 hz, if we divide 16Mhz at that 562 something, we get exactly 28448 instructions.

Divided by 256 prescaler, i get 111. it works on timer0 only if it goes down to 108.
It works on timer1 if it goes down to 27648 (basically, 108 * 256).

I'm using, of course CTC mode, and sampling my data inside the interrupt. It works, but sometimes it drifts (from some point, all 0 bytes become ones, because the chip samples the other half of the signal). Any hints?


Of course, i can also resort to using an interrupt pin and a free running timer, every time the interrupt triggers i measure the timer, and via some histeresis, i decide if i got a 0 or 1. But I don't want to do that.
« Last Edit: July 27, 2008, 04:43:01 PM by izua »
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline izuaTopic starter

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: Help with atmega timer (RC5 decoder)
« Reply #1 on: July 29, 2008, 11:16:46 AM »
Hmm, I've done some tweaking and I got RC5 decoded on timer0 flawlessly.
I'm going to add it to my long overdue robot, as a remote control (hehe, controlling a robot with a TV remote control is weird).

I wrote a tutorial on how to do RC5 decoding. It still misses the UART libraries, but I'm sure you can make your own functions to send a C string or a byte. If not, ask. RC5 decoding is done on timer0, so except the 14 samples, your uc will be free to do whatever it needs to. You will still need to poll for a start signal, though (you can use an interrupt line instead)
Here is the link.

Do let me know what you think - style, complexity, language, code, etc.. I've recently installed a syntax highlighter, so I'm particularly interested in problems related to that. I'm not a native English speaker, so corrections are on their way. Do point out if you find any.
« Last Edit: September 06, 2008, 12:35:28 AM by izua »
Check out my homepage for in depth tutorials on microcontrollers and electronics.

 


Get Your Ad Here

data_list