Pulsin Threshold
Eric R
Posts: 225
I have a square wave that is from an encoder that gives off 4 pulses per rev. Reading this with pulsin gives me 3750 counts at 2000 rpm and 750 counts at 10,000 rpm. I would like to set a threshold value that will hold true regardless of the decrease in pulsewidth.
Sample code is·as follows:
___________________________________________________________________________________________
sample1 var word
sample2 var word
totalSample1 var word
sample3 var word
sample4 var word
totalSample2 var word
grandtotal var word
threshold var word
Grandtenth var word
pulsin 13, 1, sample1
pulsin 13, 0, sample2
totalSample1 = sample1 + sample2········· 'sample 1 collection
pause 100··········································'100Ms update pause
pulsin 13, 1, sample3
pulsin 13, 0, sample4
totalSample2 = sample3 + sample4········· 'sample·2 collection
if totalSample1 > totalsample2 then GrandTotal = totalsample1 - totalsample2···· 'Subtraction only takes place if encoder is accelerating.
grandtenth = 50000 / grandtotal··········· 'best I could come up with for·100mS.·conversion
if grandtenth· > threshold then.....
__________________________________________________________________________________________
There lies my problem, I··would like to look for wild acceleration at anypoint in the RPM range of say 500rpm gain per second or higher, however, as the width of the pulse decreases with rpm my threshold value will also need to decrease in proportion. How could one do this? I had a few ideas that didn't work out well, so I am seeking suggestions!
Thanks,
Eric
Sample code is·as follows:
___________________________________________________________________________________________
sample1 var word
sample2 var word
totalSample1 var word
sample3 var word
sample4 var word
totalSample2 var word
grandtotal var word
threshold var word
Grandtenth var word
pulsin 13, 1, sample1
pulsin 13, 0, sample2
totalSample1 = sample1 + sample2········· 'sample 1 collection
pause 100··········································'100Ms update pause
pulsin 13, 1, sample3
pulsin 13, 0, sample4
totalSample2 = sample3 + sample4········· 'sample·2 collection
if totalSample1 > totalsample2 then GrandTotal = totalsample1 - totalsample2···· 'Subtraction only takes place if encoder is accelerating.
grandtenth = 50000 / grandtotal··········· 'best I could come up with for·100mS.·conversion
if grandtenth· > threshold then.....
__________________________________________________________________________________________
There lies my problem, I··would like to look for wild acceleration at anypoint in the RPM range of say 500rpm gain per second or higher, however, as the width of the pulse decreases with rpm my threshold value will also need to decrease in proportion. How could one do this? I had a few ideas that didn't work out well, so I am seeking suggestions!
Thanks,
Eric
Comments
The formula to get from total pulse width to rpm is, according to your figures,
rpm = 7500000 / totalsample = 50000 * 150 / totalsample
for example, rpm is 100000 when the pulsin result, totalsample, is 750 counts.
The division takes two steps on the Stamp to get enough precision for you to make the comparison.
rpm1=(50000/totalsample1*10)+(50000//totalsample1*10/totalsample1)*15
· rpm2=(50000/totalsample2*10)+(50000//totalsample2*10/totalsample2)*15
rpmChange = rpm2 - rpm1 ' with a resolution of 15 rpm
IF rpmChange.bit15=0 AND rpmChange > 30 THEN ... ' positive and enough
Quantitatively, an acceleration of 500 rpm per second is 50 rpm in your 0.1 second sampling period. So the above formula with a resolution of 15 rpm should be able to pick it up. The resolution of the BS2 PULSIN command is 2 microseconds.
The above seems to fit okay with the range of values that you specified, with a minimum of 2000 rpm. The formula can be incorrect if rpm < 1144, totalsample>6553.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Quick question, The stamp will accept 7500000?
"rpm = 7500000 / totalsample = 50000 * 150 / totalsample"
In this formula,
rpm1=(50000/totalsample1*10)+(50000//totalsample1*10/totalsample1)*15
the remainder from the division inside the first () is used in the second () to get one more decimal digit of precision.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com