Fixed. Just dumped raw value of what is written BtnVal and it is either around 80 or 110, so I modified the code and now it works!
But why so low values? due to slower PIC ?
Fixed. Just dumped raw value of what is written BtnVal and it is either around 80 or 110, so I modified the code and now it works!
But why so low values? due to slower PIC ?
The value returned by PULSIN for a specific pulse width is dependent of the speed at which the PIC runs.
At 4MHz the resoulution is 10us, at 20MHz it's 2us (all according to the manual).
This means that the PULSIN values corresponding to a logic "1" and "0" will be different depending on oscillator frequency.
I reccon the code you copied comes from Bruce's post #18 in the thread? Is that correct?
Yes, correct.
I tried to make this code respond faster, by changing the pause value from 1000 to 100 (works fine), but when I change it from 100 to 10, now it improperly detects half of the statements.
I want to use this code to remote control a clock, and as I understand, PULSIN can't run in background, so it will be slowing down the clock routines, right? The clock code has to read from RTC, update display, check for alarms, adjust backlight leds and so on....
As I understand, there will be a need to use timer somehow, for lead pulse detection, and based on it, interrupt will be generated and IR decoding code will be run?
A fast ISR is the best way to go.
But you may get away with other routes too.
For example, if you read the RTC interrupt every second to update the time and test the other things you want. Finally read the IR code.
Since IR transmission is not repeated quickly, you have plenty of time to do the above tasks. The worse that can happen is to loose one transmission but will grab the second.
I believe your RTC does have an Interrupt output, so that MCU can be triggered, either poll or by interrupt regularly.
Ioannis
Bookmarks