spin equivalent to arduino pulsin
in Propeller 1
Dear forum users
Is ther a spin equivalent to the arduino comand pulsin?
With best regards Ben
Is ther a spin equivalent to the arduino comand pulsin?
With best regards Ben
Comments
pub ez_pulse_in(pin) | ticks waitpne(|<pin, |<pin, 0) ' wait for pin to be low waitpeq(|<pin, |<pin, 0) ' wait for pin to go high ticks := -cnt ' start timing waitpne(|<pin, |<pin, 0) ' wait for pin to go low ticks += cnt ' stop timing return ticks / (clkfreq / 1_000_000) ' return pulse width in microseconds
Note that this method doesn't have any tuning for command overhead. The great thing about the Propeller is that you could use another cog to create precision pulses on a pin, then use this method is a second cog to measure them to determine a tuning constant.
return ticks / constant(clkfreq / 1_000_000)
to make it microseconds.In my own programs I use this header (mod of something someone posted in these forums) to create compile-time constants for clock frequency, and ticks in milliseconds and microseconds.
con { timing } _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' use 5MHz crystal CLK_FREQ = (_clkmode >> 6) * _xinfreq ' system freq as a constant MS_001 = CLK_FREQ / 1_000 ' ticks in 1ms US_001 = CLK_FREQ / 1_000_000 ' ticks in 1us