PDA

View Full Version : Code help



c_moore
- 28th March 2012, 23:03
OK This is what I am doing. I am working on auto advance for a cdi unit. I have working code that I have ran the test engine on and it works ok,but I was wanting some advice on if there is a better way to do what I am doing. in a nutshell I use timer0 with a prescale set to 32 to measure the time the input is low and I use that value to look up another value I use for the delay with tmr2 set to 1:16. This method works,but has flaws. for one I only have a certain rpm range I can work with.I tried using math formulas the calculate the delay I need, but it takes too long the do the calculations. I am running the pic at 4 mhz. the code below is what I am using to measure the input dwell. it works, one question I have is how would I measure the time the input is high? Like it is the code below gives me a good steady value through out the rpm range. I changed some things,but I never could get the high dwell time as steady as the low dwell time.Any advice is greatly appreciated.



While GPIO.2 = 1 :TMR0 = 0 :Wend ' wait for input to go high and clear tmr0

While GPIO.2 = 0 :ldwell = TMR0:Wend , wait for input to go low and load var with tmr0 value