Normally it's at 550hz although some modules output at 850hz. The manufacturer doesn't understand why.
I knew the math I put up was still based on whole numbers.
Sorry it was a typo, but I'm very curious what you have up your sleeve, maybe I'll learn something new "again" and I'm sure it will look much neater as well <grin>
PulsIn F_pin1, 1, pHigh ' get high portion of input
PulsIn F_pin1, 0, pLow ' get low portion of input
' calculate cycle width
Period = pHigh + pLow
'Display Zero - Avoid rest of Math
IF Period = 0 Then
Steps = 0
Period = 0
DutyCycle = 0
Oxygen = 0
GoTo DoIt
EndIF
'*****************************************
'Calculate Duty Cycle in format 37.7% = 377
t2 = plow
t3 = phigh
t3 = t2 + t3
t3 = t3 / 10
t2 = t2 * 100
DutyCycle = t2/t3 'Duty Cycle Value
'Actual Duty Cycle is Zero then Display Zero'
IF DutyCycle < 301 Then
Steps = 0
Period = 0
DutyCycle = 0
Oxygen = 0
GoTo DoIt
EndIF
'*************************************
'Calculate % Oxygen
TmpVar = DutyCycle - 300 'TmpVar = 377 - 300 = 77
Oxygen = TmpVar * 42 '77 * 42 = 3234 or 3.234% o2
OxygenTens = Oxygen // 1000
Oxygen = Oxygen / 1000
'Scale PWM Output Steps for % of oxygen
TmpVar = DutyCycle - 300 '377 - 300 = 77
TmpVar1 = TmpVar // 10 '77 // 10 = Remainder of 7
TmpVar = TmpVar / 10 '77 / 10 = 7 We loose too much here so get remainder and add back
TmpVar = TmpVar * 256 '7 * 256 = 1792
TmpVar1 = TmpVar1 * 256 '7 * 256 = 1792
TmpVar1 = TmpVar / 10 '1792 / 10 = 179
TmpVar = TmpVar + TmpVar1 'Add remainder 179 back
TmpVar = TmpVar / 50 '1971 / 50 = 39 Steps
Steps = TmpVar
DoIt:
PWM VOut1, Steps, PulseLen
Debug " 02: ", #Oxygen,".",#OxygenTens," Steps: ",#Steps, " Duty: ",#DutyCycle, 13,10
Toggle LED
GoTo Loop
Bookmarks