Ok, I got the code working the way i wanted but had to make some alterations.
First of all - I'm definitely going to have to have a separate power supply for my board as it keeps resetting at full throttle. Even with PWRTE set.
I had to change:
Since the 2µs resolution puts it well beyond 255.Code:Width var byte to Width var word
And after a few minutes of just looking at hundreds if not thousands of pulses on my Logic analyzer it hit me![]()
Look for the on pulse > turn the light on
Look for the off pulse > Turn the light off
Here is my final code:
Code:define osc 20 '20Mhz oscillator CMCON = 7 'Turn off Comparators Width var word '@ 20Mhz channel 3 is 1900µs in the on state. with 2µs resolution thats a value of 950. byte only holds a value of 255. Main: Pulsin Porta.0, 1, Width 'Wait for a high pulse store the pulse width in the variable "Width." if (Width >= 925 ) and ( Width <= 975) then '1900µs is on state. 1900µs /2 = 950 high porta.1 else goto Check_pulse endif goto Check_pulse Check_pulse: Pulsin Porta.0, 1, Width 'Wait for a high pulse store the pulse width in the variable "Width." if (Width >= 475 ) and ( Width <= 525) then '1000µs is off state. 1000µs /2 = 500 low porta.1 'If channel 3 is indeed in the off state turn the LED off. else goto Main endif goto Main
Thanks for all of the help.




Bookmarks