Unresponsive SPIN counter FRQA
MJHanagan
Posts: 189
I am having trouble getting my Propeller to count a 1Hz input signal. For debugging purposes I am simulating the 1 Hz signal using a simple tactile switch to momentarily connect Vdd to the input on pin 5 which is normally grounded via a nominal 20k ohm resistor. The input pin correctly sees the high and low inputs. The problem is in nothing is accumulating in the FRQA or PHSA registers - they both remain at zero despite the input on pin 5 going high and low. I seem to be missing something fundamental here. Can anyone shed some light?
Here is the code:
CON
_clkmode = xtal1 + pll16x 'Must stay with the 16x (80 MHz for IR to work reliably)
_xinfreq = 5_000_000
' serial terminal baud rate (default I/O pins are 30 and 31):
PSTBaud = 115200
' The remote display module hosts the IR receiver, two push button switches and the LCD screen:
IRPin = 15, LCDPin = 16, LCDBaud = 9600, SW1Pin = 8, SW2Pin = 9, Altmsec = 1000
' Maxim DS1306 real time clock (RTC) pins:
RTCData = 5, RTCEnable = 6, RTCClock = 7
OBJ
pst : "Parallax Serial Terminal"
VAR
long CounterSetup, CNTValue, FRQAValue, PHSAValue
byte OneHzPin
PUB Main | i, j, k, l, m, n
pst.Start( PSTBaud )
pst.Clear
pst.Beep
pst.str(String("Initializing..."))
' Program the counter to count inputs on pin 5
OneHzPin := 5
DIRA[ OneHzPin ]~ 'Set pin for input
' Set control mode to LOGIC A
CounterSetup := %11010 << 26 ' Logic A count - see page 98
' CounterSetup := %01000 << 26 ' Postive edge counting on APIN - see page 98
' CounterSetup := %11111111 << 23 ' Logic always count - see page 98
' CounterSetup := %01000111 << 23
CounterSetup += OneHzPin ' add the pin numberto the counter setup mask
pst.str( string( pst#NL, "Counter control: " ) )
pst.bin( CounterSetup, 32 )
CTRA := CounterSetup ' program the counter
FRQA := 0 ' Initialize the counter register
PHSA := 0 ' Initialize the counter register
repeat
' 'repeat until FRQA > 0
' i++
CNTValue := CNT
FRQAValue := FRQA
PHSAValue := PHSA
'pst.Beep
pst.str( string( pst#NL, "FRQA: " ) )
pst.dec( FRQAValue )
pst.str( string( " PHSA: " ) )
pst.dec( PHSAValue )
pst.str( string( " INA[5]: " ) )
pst.dec( INA[OneHzPin] )
pst.str( string( " CNT: " ) )
pst.dec( CNTValue )
waitcnt( cnt+ clkfreq )One Hz Counter V0.spin
Here is the code:
CON
_clkmode = xtal1 + pll16x 'Must stay with the 16x (80 MHz for IR to work reliably)
_xinfreq = 5_000_000
' serial terminal baud rate (default I/O pins are 30 and 31):
PSTBaud = 115200
' The remote display module hosts the IR receiver, two push button switches and the LCD screen:
IRPin = 15, LCDPin = 16, LCDBaud = 9600, SW1Pin = 8, SW2Pin = 9, Altmsec = 1000
' Maxim DS1306 real time clock (RTC) pins:
RTCData = 5, RTCEnable = 6, RTCClock = 7
OBJ
pst : "Parallax Serial Terminal"
VAR
long CounterSetup, CNTValue, FRQAValue, PHSAValue
byte OneHzPin
PUB Main | i, j, k, l, m, n
pst.Start( PSTBaud )
pst.Clear
pst.Beep
pst.str(String("Initializing..."))
' Program the counter to count inputs on pin 5
OneHzPin := 5
DIRA[ OneHzPin ]~ 'Set pin for input
' Set control mode to LOGIC A
CounterSetup := %11010 << 26 ' Logic A count - see page 98
' CounterSetup := %01000 << 26 ' Postive edge counting on APIN - see page 98
' CounterSetup := %11111111 << 23 ' Logic always count - see page 98
' CounterSetup := %01000111 << 23
CounterSetup += OneHzPin ' add the pin numberto the counter setup mask
pst.str( string( pst#NL, "Counter control: " ) )
pst.bin( CounterSetup, 32 )
CTRA := CounterSetup ' program the counter
FRQA := 0 ' Initialize the counter register
PHSA := 0 ' Initialize the counter register
repeat
' 'repeat until FRQA > 0
' i++
CNTValue := CNT
FRQAValue := FRQA
PHSAValue := PHSA
'pst.Beep
pst.str( string( pst#NL, "FRQA: " ) )
pst.dec( FRQAValue )
pst.str( string( " PHSA: " ) )
pst.dec( PHSAValue )
pst.str( string( " INA[5]: " ) )
pst.dec( INA[OneHzPin] )
pst.str( string( " CNT: " ) )
pst.dec( CNTValue )
waitcnt( cnt+ clkfreq )One Hz Counter V0.spin
Comments
This time for sure, Rocky:
From the counter application note:
The PHSA / PHSB register is the heart of the counter; it is the accumulator that stores the counters
current value. This value can be read from or written to by a program; though for many applications
writing to the register is not necessary.
The FRQA / FRQB register holds the value which is added to the accumulator whenever an
accumulate condition is true. The accumulate condition is specified by the mode of operation set in
the CTRMODE field of the CTRA / CTRB register.
Go to this page and find AN001 under "Propeller AppNotes and Objects". You might have to click on the "show more" button to see it.
http://www.parallax.com/tabid/442/Default.aspx
Otherwise, try the attached file:
My switch seems to have some debounce noise which got a bit better change from rizing to falling edge detection. I assume this won't be an issue with the 1 hz signal off the RTC. Otherwise I assume some small capacitor would help clean up that problem.
Thank you! That helps to clear things up quire a bit.
A capacitor is more likely to cause problems (unless followed by a schmidt-trigger gate). RTC output is a logic signal, not a mechanical switch, it won't bounce...