Troubles with POSEDGE mode in SPIN counter
Atal1101
Posts: 11
in Propeller 1
Hey all,
Having issues with my latest project. I'm driving a computer fan with a PWM output from the Propeller then trying to sense the frequency through the onboard sensor on the fan (yellow wire of a 3-wire fan). I'm seeing where as the PWM duty cycle (and such the speed of the fan) increases, the counter is reading back decreasing values, which tells me something is definitely off.
End goal is to be able to query the user for a PWM value, run the fan at that set duty cycle, sense the number of pulses that come from the fan (2 per revolution is what I've heard everywhere) and convert this to RPM before sending the value back over the serial connection. I know that the PHSA conversion for RPM isn't accurate at the moment, just trying to find something that might work with no luck. Any tips would be greatly appreciated.
Having issues with my latest project. I'm driving a computer fan with a PWM output from the Propeller then trying to sense the frequency through the onboard sensor on the fan (yellow wire of a 3-wire fan). I'm seeing where as the PWM duty cycle (and such the speed of the fan) increases, the counter is reading back decreasing values, which tells me something is definitely off.
End goal is to be able to query the user for a PWM value, run the fan at that set duty cycle, sense the number of pulses that come from the fan (2 per revolution is what I've heard everywhere) and convert this to RPM before sending the value back over the serial connection. I know that the PHSA conversion for RPM isn't accurate at the moment, just trying to find something that might work with no luck. Any tips would be greatly appreciated.
{Propeller Attempt 1 The debug terminal will request a PWM duty cycle percentage. The user will enter this into the terminal and hit enter. One cog of the Propeller will drive a 5kHz signal at the set percentage for a span of 5 seconds. Simultaneously, a second core will measure the number of pulses in a 1 second period and multiply this by 30 to get the fan's RPM. The fan speed will be output to the user in the debug terminal, and then the program will wait for another duty cycle to test.} CON _clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz _xinfreq = 5_000_000 PWMFreq = 10000 Fan=0 Sense=1 VAR long duty long OnTime long OffTime long RPM long Period long FreqCounterStack[100] OBJ PST :"Parallax Serial Terminal" PUB Main Period:=clkfreq/PWMFreq PST.Start(115200) dira[Fan]~~ outa[Fan]~ repeat PST.Str(String("Please input a duty cycle in percent for the fan to be run at: ")) duty:=PST.DecIn OnTime:=(Period/100)*duty OffTime:=Period-OnTime cognew(FreqCounter,@FreqCounterStack) repeat (PWMFreq*5) outa[Fan]~~ waitcnt(OnTime+cnt) outa[Fan]~ waitcnt(OffTime+cnt) PST.NewLine PST.Str(String("The fan is running at ")) PST.Dec(RPM) PST.Str(string(" RPM.")) waitcnt(5*clkfreq+cnt) PST.Clear PUB FreqCounter waitcnt(clkfreq+cnt) ctra[30..26]:=%01010 ctra[5..0]:=%01010 frqa:=1 phsa:=0 waitcnt(clkfreq+cnt) RPM:=phsa*30 cogstop(cogid)
Comments
CTRA :=0
CTRA := (%01010<<26) | (%001 <<23) | (0 <<9) | (Pin)
FRQA := 1000
PHSA := 0
WaitCnt( 80_000_000 + CNT)
Frequency := PHSA/1000
Here's the updated program. I've removed the second cog program and am just watching the sense pin for now to try to clock how many counts go by between falling edges of the sense pulses. Current issues I'm running into are that the timeDifferential reading always seems to be the exact same regardless of the fan speed, and that the PeriodTime and RPM calculations do not appear to be running. Does anybody have any ideas for me or stupid mistakes to point out?
Your program sets the NEGDET mode on pin 1 for ctra, but it does not make use of that. Instead you have a sequence using waitcnt. If you want to shy away from using the cog counters, you'll be better off using waitpeq and waitpne. Maybe something like this...
By the way, waitcnt(2+cnt) is bound to give you problems, because spin takes 381 ticks to execute the command. The minimum value is, I think, waticnt(381+cnt). That is about 5 microseconds at 80MHz clkfreq.