Shop OBEX P1 Docs P2 Docs Learn Events
Unresponsive SPIN counter FRQA — Parallax Forums

Unresponsive SPIN counter FRQA

MJHanaganMJHanagan Posts: 189
edited 2012-01-09 19:10 in Propeller 1
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

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-01-09 13:02
    attachment.php?attachmentid=78421&d=1297987572
  • MJHanaganMJHanagan Posts: 189
    edited 2012-01-09 13:07
    Oh, so that's how you post code!! Thank you!!

    This time for sure, Rocky:
    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 )
    
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-01-09 13:10
    Maybe I'm missing something but I don't see where you've assigned values to your FRQA register.

    From the counter application note:

    The PHSA / PHSB register is the heart of the counter; it is the accumulator that stores the counter’s
    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:
  • MJHanaganMJHanagan Posts: 189
    edited 2012-01-09 14:17
    Oh, now I see!! So I set FRQA = 1 and the control mode to POSEDGE %01010 and I now see accumulation occuring in the PHSA register for each switch activation! Boy, that wasn't very clear as I read the Propeller Manual

    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.
  • Mark_TMark_T Posts: 1,981
    edited 2012-01-09 19:10
    MJHanagan wrote: »
    Oh, now I see!! So I set FRQA = 1 and the control mode to POSEDGE 010 and I now see accumulation occuring in the PHSA register for each switch activation! Boy, that wasn't very clear as I read the Propeller Manual

    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...
Sign In or Register to comment.