NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » RC5 infra red decoding
October 15, 2012 by ankush_karche |
Hello All, Earlier I had created one thread on infra red programming. For that I received advice to study basics again and I am progressing on that and getting comfortable. Now I am looking in to below code, all credit goes to Peter Fleury for his program. I have few basic questions. For any combination of F_CPU and Prescaler how to calculate value of TIMER_0_CNT value. I want to know how 111us with CLK/8 prescale has been calculated ? Peter Fleury�s Rc5 code http://jump.to/fleury Code: include <inttypes.h>include <avr/io.h>include <avr/interrupt.h>include <avr/signal.h>/ this should be in <avr/io8515.h> !! / define TMC8_STOP 0define TMC8_CK8 _BV(CS01)/ Macros and constants / define RC5BitHigh() (bit_is_set(PIND,PD3))define RC5BitLow() (bit_is_clear(PIND,PD3))define WAITFORTIMER() { while ( timerflag == 0); timerflag = 0; }define TIMER_0_CNT 0xCA // 111us with CLK/8 prescaledefine RC5BITREF1 6define RC5BITREF2 11define RC5BITREF3 14/ function prototypes / unsigned int rc5decode( void ); / module global variables / static volatile uint8_t timerflag; //must be volatile because modified by interrupt handler SIGNAL(SIG_OVERFLOW0) / signal handler for timer0 overflow interrupt / { timerflag = 1; // set global variable
} unsigned int rc5decode( void ) / decoded RC5 data is returned, or 0x0000 if RC5 data not recognized / { unsigned int rc5data; unsigned char timer, i;
}//rc5decode Your valuable help is appreciated. Thanks in advance for your time and help. With kind regards,
|
---|---|
October 15, 2012 by ankush_karche |
Code:
For any combination of F_CPU and Prescaler how to calculate value of TIMER_0_CNT value. I want to know how 111us with CLK/8 prescale has been calculated ? |
October 15, 2012 by Noter |
For F_CPU = 14745600hz scaled 14745600hz / 8 = 1843200hz timer tick is 1 / 1843200hz = 0.000000543sec or once every 0.543us counter is 111us / 0.543us = 204.4 I would use a count of 204 to get 111us when F_CPU is 14745600hz and scaler is 8. |
October 16, 2012 by ankush_karche |
Thanks Noter for the explaination. Now it makes sense to me and will help at many steps ahead. Regards, Ankush |
Please log in to post a reply.
Did you know that you need to think about wires differently when you're transmitting signals more than a few inches? Learn more...
|