c_moore
- 29th May 2012, 10:44
Hello everyone,
I have been working on a project and I am making some progress,but not as good as I would have liked. I was wondering if I could get some help. Below is some code and it works,but what I would like to know is is there a better / easier way to do what I am doing. In a nutshell what I am trying to do is I see input from a hall sensor I wait a specific amount of time and then toggle a output. Thanks for any help or advice or code(grin)that can be given. It seems that using a lookup table is not the way to go here because I have several and can't seem to get the curve I want.
While 1 = 1 ' This code measures the low dwell of the input or the time that the input is low.
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
If tmr0if = 1 Then ' check to see if tmr0 rollover flag is set
tmr0if = 0 ' if so clear the flag
PauseUS 21000 ' and delay 21000 micro seconds
' this retards the timing from 28 degrees
' to about 5 degrees for starting
Else
'_________________________________________________ __________________________________________________ ____________________________________________
' to change the curve just shift the table to the right or left using 0s.
' to lower the curve at idle just remove 0s.To increase the curve at idle add 0s.
' curve is 5 degrees @ 1300 to 28 degrees @ 2500
' LDWELL value is 97 @1300 and 32 @4000 rpm
' lookUp ldwell,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,_ '0 - 31
' 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,7,10 ,13,16,19,22,26,29,33,_ '32 - 63
' 37,42,47,51,57,63,69,75,82,90,98,107,117,128,141,1 54,169,176,188,188,188,_ ' 63 - 84
' 189,190,191,191,191,191,194,195,195,196,196,197,19 8,212,212,206,208,205,206,_ '85 - 103
' 207,208,209,210,211,212,213,214,215,216,216,217,21 8,220,221,222,223,224,225,226,_ ' 104- 123
' 228,229,230,231,232,234,235,236,237,239,240,241,24 2,244,245,247,248,250,251,253],delayangle ' 124 - 143
' to change the curve just shift the table to the right or left using 0s.
' to lower the curve at idle just remove 0s.To increase the curve at idle add 0s.
' curve is 5 degrees @ 1300 to 28 degrees @ 4000
' LDWELL value is 97 @1300 and 32 @4000 rpm
' lookUp ldwell,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,1,2,3,5,6,7,8,_
' 10,11,12,14,15,17,18,20,21,23,24,26,28,30,32,33,35 ,38,40,42,44,46,49,51,54,56,59,_
' 62,65,68,71,74,78,81,85,89,93,97,101,106,110,115,1 21,126,132,138,144,151,158,166,_
' 174,182,191],delayangle
' to change the curve just shift the table to the right or left using 0s.
' to lower the curve at idle just remove 0s.To increase the curve at idle add 0s.
' curve is 5 degrees @ 1300 to 28 degrees @ 4000
' LDWELL value is 97 @1300 and 32 @4000 rpm
lookUp ldwell,[0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,1 8,19,20,21,22,23,24,25,26,27,28,29,30,_
32,33,34,35,37,38,39,41,42,43,45,46,48,49,51,52,54 ,56,57,59,61,63,65,67,69,71,73,75,77,79,_
81,84,86,89,91,94,97,99,102,105,108,111,114,118,12 1,125,128,132,136,140,144,148,153,157,162,_
165,169,172,176,179,183,187,191,196,200,205,210,21 5,221,227,233,239,246,254],delayangle
EndIf
'_________________________________________________ __________________________________________________ ____________________________________________
T2CON = 7 ' turn timer2 on ans set prescale to 1:16
TMR2 = 0 ' clear tmr2
While TMR2 < delayangle :Wend ' wait here until timer2 = delayangle
npn = 1 ' turn base of npn on
pauseus 1280 ' pause for 1.280 ms
npn = 0 ' turn base of npn off
INTCON = 0 ' just making sure the intcon register is cleared
Wend
end ' end of code
I have been working on a project and I am making some progress,but not as good as I would have liked. I was wondering if I could get some help. Below is some code and it works,but what I would like to know is is there a better / easier way to do what I am doing. In a nutshell what I am trying to do is I see input from a hall sensor I wait a specific amount of time and then toggle a output. Thanks for any help or advice or code(grin)that can be given. It seems that using a lookup table is not the way to go here because I have several and can't seem to get the curve I want.
While 1 = 1 ' This code measures the low dwell of the input or the time that the input is low.
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
If tmr0if = 1 Then ' check to see if tmr0 rollover flag is set
tmr0if = 0 ' if so clear the flag
PauseUS 21000 ' and delay 21000 micro seconds
' this retards the timing from 28 degrees
' to about 5 degrees for starting
Else
'_________________________________________________ __________________________________________________ ____________________________________________
' to change the curve just shift the table to the right or left using 0s.
' to lower the curve at idle just remove 0s.To increase the curve at idle add 0s.
' curve is 5 degrees @ 1300 to 28 degrees @ 2500
' LDWELL value is 97 @1300 and 32 @4000 rpm
' lookUp ldwell,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,_ '0 - 31
' 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,7,10 ,13,16,19,22,26,29,33,_ '32 - 63
' 37,42,47,51,57,63,69,75,82,90,98,107,117,128,141,1 54,169,176,188,188,188,_ ' 63 - 84
' 189,190,191,191,191,191,194,195,195,196,196,197,19 8,212,212,206,208,205,206,_ '85 - 103
' 207,208,209,210,211,212,213,214,215,216,216,217,21 8,220,221,222,223,224,225,226,_ ' 104- 123
' 228,229,230,231,232,234,235,236,237,239,240,241,24 2,244,245,247,248,250,251,253],delayangle ' 124 - 143
' to change the curve just shift the table to the right or left using 0s.
' to lower the curve at idle just remove 0s.To increase the curve at idle add 0s.
' curve is 5 degrees @ 1300 to 28 degrees @ 4000
' LDWELL value is 97 @1300 and 32 @4000 rpm
' lookUp ldwell,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,1,2,3,5,6,7,8,_
' 10,11,12,14,15,17,18,20,21,23,24,26,28,30,32,33,35 ,38,40,42,44,46,49,51,54,56,59,_
' 62,65,68,71,74,78,81,85,89,93,97,101,106,110,115,1 21,126,132,138,144,151,158,166,_
' 174,182,191],delayangle
' to change the curve just shift the table to the right or left using 0s.
' to lower the curve at idle just remove 0s.To increase the curve at idle add 0s.
' curve is 5 degrees @ 1300 to 28 degrees @ 4000
' LDWELL value is 97 @1300 and 32 @4000 rpm
lookUp ldwell,[0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,1 8,19,20,21,22,23,24,25,26,27,28,29,30,_
32,33,34,35,37,38,39,41,42,43,45,46,48,49,51,52,54 ,56,57,59,61,63,65,67,69,71,73,75,77,79,_
81,84,86,89,91,94,97,99,102,105,108,111,114,118,12 1,125,128,132,136,140,144,148,153,157,162,_
165,169,172,176,179,183,187,191,196,200,205,210,21 5,221,227,233,239,246,254],delayangle
EndIf
'_________________________________________________ __________________________________________________ ____________________________________________
T2CON = 7 ' turn timer2 on ans set prescale to 1:16
TMR2 = 0 ' clear tmr2
While TMR2 < delayangle :Wend ' wait here until timer2 = delayangle
npn = 1 ' turn base of npn on
pauseus 1280 ' pause for 1.280 ms
npn = 0 ' turn base of npn off
INTCON = 0 ' just making sure the intcon register is cleared
Wend
end ' end of code