Hi Barry,
TMR0 starts counting as soon as you set to BE a counter (OPTION_REG.5=1) and it will keep counting the incoming pulses. It will overflow att 255->0. The idea was that, because both newCount and TMR0 is a BYTE, that it will/should automatically give you the correct result but I think I may have made a little mistake there.
Lets try this instead:When we have TMR0 counting pulses reliably we'll move to the next step which will be set TMR1 up to generate an interrupt periodically (using DT Ints). This interrupt will then "capture" the current count, calculate the "speed" using the above code and run the PID-loop. But lets make sure we have TMR0 and the code above working properly first. Basically it should now display the frequency of the incoming signal but the timebase will be a bit off due to LCDOUT statements taking a bit of time on top of the PAUSE 1000.Code:newCount VAR BYTE oldCount VAR BYTE newCount = 0 oldCount = 0 Main: newCount = TMR0 - oldCount oldCount = TMR0 LCDOUT "TMR0 Count: ", #TMR0 LCDOUT $FE, $C0 LCDOUT "Count since: ", #newCount Pause 1000 Goto Main
/Henrik.




Bookmarks