Hi
I am new to PICs and my main interest is in RC models.
I need to time an input pulse from the reciever. These are typically 1 to 2 milliseconds long and occur every 20 milliseconds.
I was trying to setup a basic timing loop with a 10us resolution but cannot set a delay in the loop below 1ms using flowcode.
The loop was something like this;
Is input high
if yes wait for 10us
is the input still high
if yes continue loop
if no store vale and move on
Anyone any ideas on how to do this?
The second part im trying to achieve is ;
Is this time <= 1.4 ms
if yes set an output high
if no is time>=1.6ms
if yes set output high
if no set output low
go back and wait for next pulse
Any help appreciated
Iain
timing an input pulse
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
To get a shorter delay, you could use a 'C' icon with one of the following lines in it:
As for the second part, maintain a variable that is increased for each 10us delay. When this variable has reached 140, this should equate (roughly) to 1400us, i.e. 1.4ms.
This approach will not take into account the time of the other code to execute (e.g. the loops), so will not be 100% accurate. For better accuracy, I would suggest you use interrupts with an appropriate crystal clock (but this will be more difficult to program).
Code: Select all
delay_us(10); //Use this for Flowcode v2
delay_10us(1); //Use this for Flowcode v3
This approach will not take into account the time of the other code to execute (e.g. the loops), so will not be 100% accurate. For better accuracy, I would suggest you use interrupts with an appropriate crystal clock (but this will be more difficult to program).