Shop OBEX P1 Docs P2 Docs Learn Events
RESOLVED:Counter will not increment. — Parallax Forums

RESOLVED:Counter will not increment.

WurlitzerWurlitzer Posts: 237
edited 2009-07-04 14:07 in Propeller 1
HARDWARE ISSUE: Pins 0-4 did not make contact in my breadboard so while the waveform was right it never go to the pin.


I have a routine that generates 64 clock pulses (OK) and @ clock pulse 51 I have a L/R circuit that is connected to Pin 1 and I want to count the system clocks until the input drops below 1.65vdc.

The waveform is perfect and exactly what I expect. I created an extra delay at count 51 so it is easy to spot on my scope in the string of clock pulses.

Anyway, I do a MOV PHSA, #0 just before I do a return from #ClockSet then if I am at ScanCnt 51 I add some delay then do a
MOV InputCount, PHSA but the value is always zero. In looking at the scope I expected something like ~~50 or so. but it is always zero.

Just to make sure the Write routine works I have place different values in InputCount and they get written perfectly via the FullDuplex code.

I set the CTR MODE as follows: I think I have this right but perhaps another set of eyes will help

CntrA_Cfg     long %0_01000_000_00000000_000000_000_000001 'pos detection pin 1 for APIN



My Initialize routine:
Initialize_I_O
             {=========    SET PINS TO OUTPUT MODE =======================}
                        or      dira,ClockPin
                        or      dira,DataPin
                        mov     CirQueStartADDR, par
                        mov     CirQueWritePtr, par
                        mov     CirQueEnd, par
                        add     CirQueEnd, #200                      
                        mov     ctra, CntrA_Cfg   'pos detection pin 0 for Counter A APIN
                        mov     frqa, #1        'a 1 is added every clock cycle when cntr is counting                         
                        mov     KbMask, #1     'pin 0
                        mov     ScanCnt, #61
Initialize_I_O_Ret ret




And the main routine:
entry          
                        call    #Initialize_I_O
                        call    #StartNewScan
                                            
'=========================================================================================
'==========================================================================================                                    
MainLoop      
                       mov      InputCount, #$1ff 
                       call    #Clockset  'phsa is set to zero just before the return
                        cmp      ScanCnt, #51  wc,wz,nr 
             if_ne      jmp #skp1
'REMOVE TEST ONLY
mov     time,cnt              ' REMOVE Current clock loaded into time
add     time,on_time          ' on_time added to time
add     time,on_time          ' on_time added to time                                             
waitcnt time,on_time
'END REMOVE                            
                        mov    InputCount, phsa
tstLoop                
                        call    #WriteCircQueue
       
skp1                       
                        mov     tmpKBAddr, #KB_ImageArray   ' address of 1st dword in KB_Image array
                        add     tmpKBAddr, ScanCnt
                        movs    GetKBImage, tmpKBAddr                         
                        nop   '                            
GetKBImage              mov     tmpKBImage, 0_0      'source address is modified above
                       { ' tmpKBImage DWord contains calibration data for 1st and 2nd tch and
                                on off status for each touch
                       --------------------------------------------
                       | 31....16 | 15.......2 | 1....0                  |
                       | 2nd Touch| First Touch| 2nd On/off, 1st On/off  |
                       | Count    |  Count     |                         |
                       ------------------------------------------------         }
                       'determine if current count is greater or less than 1st touch                        
                        mov     tmp1, tmpKBImage
                        and     tmp1, FirstTouchMask
                        ror     tmp1, #2
                        cmp     tmp1, InputCount wc, wz, nr     'C flag set if tmp1 < Input count
              if_b      jmp     #LessThanFirstTouch
              
                        mov     tmp1, tmpKBImage
                        and     tmp1, SecondTouchMask
                        ror     tmp1, #16       'Second touch calibration value
                        cmp     tmp1, InputCount wc, wz, nr     'C flag set if tmp1 < Input count
              if_be     jmp     #AtFirstTouch   'current count is between first touch threshold and
                                                'below 2nd touch threshold.
                                                        
                        
'=========================================================================================
'==========================================================================================
AtSecondTouch


'=========================================================================================
'==========================================================================================
AtFirstTouch


'=========================================================================================
'==========================================================================================
LessThanFirstTouch


'=========================================================================================
'==========================================================================================
tmpjmp                        'end of Main Loop
                        call    #Clockclear   'NOTE: some time as already expired
                        djnz    ScanCnt, #MainLoop 'loop until all 61 keys are scanned
                        call    #StartNewScan
                        jmp     #MainLoop
'=========================================================================================
'==========================================================================================                        
ClockSet              
                        mov     time,cnt              ' Current clock loaded into time
                        add     time,on_time          ' on_time added to time
                                            
                        waitcnt time,on_time
                        mov     t, #0         wz      ' all this does is set the zero flag
                        
                        muxz outa, ClockPin         ' Sets Pin high
                         mov     phsa, #0            'set counter to zero     
ClockSet_Ret            ret
'=========================================================================================
'==========================================================================================
ClockClear
                        mov     time,cnt              ' Current clock loaded into time
                        
                        add     time,on_time          ' on_time added to time                      
                        waitcnt time,on_time 
                        mov     t, #0         wz      ' all this does is set the zero flag
                        muxnz outa, ClockPin           'sets pin low
ClockClear_Ret          ret
'=========================================================================================
'==========================================================================================
StartNewScan   'sets a single HIGH into S/R for scanning the keyboard/s
                        mov     t, #0 wz      ' all this does is set the zero flag
                        muxz    outa, DataPin
                        
                        mov     ScanCnt, #61
                        mov     WriteAddr, CirQueStartADDR
                        add     WriteAddr, ScanCnt        
                       
                        call    #ClockSet
        
      '     waitpeq KbMask,KbMask ' Wait for input to rise above 1.5 vdc.  'waitpne KbMask,KbMask
                 'RESTOR THIS BELOW                    ' 
                       '''''' wrlong  phsa, WriteAddr
       
                        sub     WriteAddr, #1
                        sub     ScanCnt, #1
           
                        call    #ClockClear
                        mov     t, #0 wz
                        muxnz   outa, DataPin               
StartNewScan_ret        ret                        
'===========================================================================================
'===========================================================================================
WriteCircQueue          wrlong InputCount, CirQueWritePtr
                        'add     CirQueWritePtr, #4
                        cmp     CirQueWritePtr, CirQueEnd  wc,wz,nr                 
              if_nc      mov     CirQueWritePtr, CirQueStartADDR

WriteCircQueue_ret      ret
'===========================================================================================

Post Edited (Wurlitzer) : 7/4/2009 2:32:18 PM GMT

Sign In or Register to comment.