Time Out ?


Closed Thread
Results 1 to 13 of 13

Thread: Time Out ?

Hybrid View

  1. #1

    Default Time Out ?

    Hello,
    Awhile back Bruce had an article about a simple remote control, here's the link:
    http://www.picbasic.co.uk/forum/showthread.php?t=12554

    I do not understand ASM that why I purchase PBP, but within the example it appears to timeout if no serial data is received in a certain amount of time. However with the RXM-418-LR series the output is always noisy with 1's and 0's as everyone knows unless a squelch circuit is used. Of course then range is compromised.

    My question is how can I modify the ASM code to timeout on RA.0 (PortA.0, my serin port on a 16F628A) but not clearing any other port, or shall I say outputs?

    Also, I am using an external 4MHZ oscillator, how can I change OSCCON = %01100000 ' Internal 4MHz select, to be external?

    I see the area that say "clrf GPIO ; Clear outputs on button release (or timeout)"
    which looking over the 16F628A datasheet I could go :
    "clrf PORTA ; Clear outputs on button release (or timeout)"
    "clrf PORTB ; Clear outputs on button release (or timeout)"
    but all I am trying to accomplish is to jump away from receiving junk if

    By the way my TRISA = %00000001 TRISB= %00000000

    Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The 628A does not have an OSCCON , the internal if used is a fixed 4MHz.
    You need to modify the chip's *.inc file to change the OSC.
    http://www.picbasic.co.uk/forum/cont...o-your-Program

    Bruce's code...
    Read this part
    Code:
     ' Fire up Timer1 before entry to serial input routine
        T1CON.0 = 1
        
        ' @4MHz Timer1 overflows in 65536 * 1uS (~65.5mS) if no Synch byte
        ' and serial data arrive on time. SERIN2 timeout & label options
        ' are useless with a noisy RF receiver output - as noise continually
        ' resets the timeout period causing it to hang forever.
        
        ' Wait for Synch byte, then get new inbound data & checksum
        SERIN2 D_IN,BAUD,[WAIT(Synch),DAT_IN1,DAT_IN2,CHK_SUM]
        
        T1CON.0 = 0    ' Stop Timer1 once we've received data
        TMR1L = 0      ' Clear low byte
        TMR1H = 0      ' Clear high byte
    Basically if the "WAIT(SYNCH)" does not happen the interrupt timer kicks in to reset/clear what ever.

    If "WAIT(SYNCH)" condition is met then the code falls through to stop the timer. So it does not matter what pin you receive on.

    If you do not want to clear anything just remove that portion of the ASM.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks for the info, but still not sure what to delete or keep. Here is what I have so far:
    Code:
    INCLUDE "MODEDEFS.BAS"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    @ DEVICE pic16F628a, PWRT_ON
    @ DEVICE pic16F628a, MCLR_ON
    @ DEVICE pic16F628a, BOD_ON
    @ DEVICE pic16F628a, LVP_OFF
    @ DEVICE pic16F628a, CPD_OFF
    @ DEVICE pic16F628a, PROTECT_OFF
    
    DEFINE OSC 4
    DEFINE NO_CLRWDT 1      ' Watchdog timer is disabled, so we don't need to reset it
    DEFINE INTHAND RESET_VT ' Interrrupt on Timer1 overflow to reset outputs in 65.5mS
                                ' if no serial data received in this time period                           
    'SYMBOL  D_IN = porta.0   ' Encoder data input pin
    SYMBOL  serpin = porta.0   ' Encoder data input pin
    SYMBOL  TMR1IF = PIR1.0 ' Timer1 overflow interrupt flag (reset in int handler)
    SYMBOL  TMR1IE = PIE1.0 ' Timer1 interrupt enable bit
    CMCON=%00000111
    vrcon=0
    trisa = %00000001
    trisb = %00000000
    PORTA = 0
    PORTB = 0               
    'serpin VAR porta.0 'serial input pin
    address con %0000000000000000 
    add1 VAR WORD   
    address1 var byte
    address2 var byte
    address3 var byte
    address4 var byte
    addA var   byte '0-7 
    addB var   byte '8-15
    addC var   byte '0-7 
    addD var   byte '8-15
    chkcrc var byte
    crcA var byte
    crcB var byte
    chksum2 var byte bank0 system '
    chksum3 var byte
    flag var byte 'latching feature
    i var byte
    latch var byte
    mydata var byte 
    mydata1 VAR byte
    mydata2 var byte
    mydata3 var byte
    mydata4 var byte
    rf var porta.4
    
        'Variables for saving state in interrupt handler
        wsave	VAR	BYTE $70 system		' Saves W
        ssave	VAR	BYTE bank0 system	' Saves STATUS
        psave	VAR	BYTE bank0 system	' Saves PCLATH
        fsave	VAR	BYTE bank0 system	' Saves FSR
        
        ' Setup Timer1 for resets after ~65.5mS
        T1CON = %00000000   ' Internal clock, 1:1 prescale, Timer1 off for now
        TMR1L = 0 
        TMR1H = 0           ' Timer1 low & high bytes cleared
        TMR1IF = 0          ' Clear Timer1 overflow flag before enabling interrupt
        TMR1IE = 1          ' Enable Timer1 overflow interrupt
        INTCON = %11000000  ' Global & peripheral ints enabled
        chksum2 = 0           ' Clear match count
        GOTO cycle        ' Jump over int handler
        
    ASM
    RESET_VT
        movwf	wsave			; Save W
        swapf	STATUS, W		; Swap STATUS to W (swap avoids changing STATUS)
        clrf	STATUS			; Clear STATUS
        movwf	ssave			; Save swapped STATUS
        movf	PCLATH, W		; Move PCLATH to W
        movwf	psave			; Save PCLATH
        movf	FSR, W			; Move FSR to W
        movwf	fsave			; Save FSR
        
        ; Do interrupt stuff here
        bcf     T1CON,TMR1ON    ; Stop Timer1
        clrf    TMR1L           ; Clear low byte
        clrf    TMR1H           ; Clear high byte
        bcf     PIR1,TMR1IF     ; Clear Timer1 interrupt flag bit
        ;clrf    GPIO            ; Clear outputs on button release (or timeout)    
        clrf    chksum2           ; Clear match variable
        
        ; Restore FSR, PCLATH, STATUS and W registers
        movf    fsave, W		; retrieve FSR value
        movwf	FSR				; Restore it to FSR
        movf	psave, W		; Retrieve PCLATH value
        movwf	PCLATH			; Restore it to PCLATH
        swapf	ssave, W		; Get swapped STATUS value (swap to avoid changing STATUS)
        movwf	STATUS			; Restore it to STATUS
        swapf	wsave, F		; Swap the stored W value
        swapf	wsave, W		; Restore it to W (swap to avoid changing STATUS)
        bsf     T1CON,TMR1ON    ; Re-enable Timer1 before exiting interrupt handler
        retfie					; Return from the interrupt
    ENDASM
    
    PAUSE 20 'SETTLE INPUTS
    
    
    start:
    low rf
    'ZERO VARIABLES
    ADD1=0
    adda = 0
    addb = 0
    addc = 0
    addd = 0
    address1 = 0
    address2 = 0
    address3 = 0
    address4 = 0
    mydata=0
    chkcrc = 0
    i = 0 
    flag = 0
    latch = %01010000
    mydata = 0
    mydata1 = 0
    mydata2 = 0
    mydata3 = 0
    mydata4 = 0
    porta.1 = 0                                    
    porta.2 = 0
    porta.3 = 0
    portb = 0 
    pause 10
    
    cycle:
    low rf
    repeat
    ADD1=0
    adda = 0
    addb = 0
    addc = 0
    addd = 0
    address1 = 0
    address2 = 0
    address3 = 0
    address4 = 0
    chkcrc = 0
    i = 0 
    mydata = 0
    mydata1 = 0
    mydata2 = 0
    mydata3 = 0
    mydata4 = 0
    
    '******************************************************************************
        ' Fire up Timer1 before entry to serial input routine
        T1CON.0 = 1
        
        ' at 4MHz Timer1 overflows in 65536 * 1uS (~65.5mS) if no Synch byte
        ' and serial data arrive on time. SERIN2 timeout & label options
        ' are useless with a noisy RF receiver output - as noise continually
        ' resets the timeout period causing it to hang forever.
        
        ' Wait for Synch byte, then get new inbound data & checksum
    SERIN2 serpin,16468,[wait(254),address1,address2,address3,address4,_
    mydata1,mydata2,crca,crcb]
        
        T1CON.0 = 0    ' Stop Timer1 once we've received data
        TMR1L = 0      ' Clear low byte
        TMR1H = 0      ' Clear high byte
        
        ' / **** Begin data validation **** /
    From here I am off to decode using my own version so I am not using anything in the orignal example except for the timeout, do you have any suggestions on what to keep, delete or change?
    Last edited by mackrackit; - 3rd August 2010 at 15:32. Reason: Added Code Tags

  4. #4


    Did you find this post helpful? Yes | No

    Default

    By the way, don't laugh to hard, I have been working hard at trying to learn and build. If you did not notice, my serin was origninally:
    serpin VAR porta.0 'serial input pin
    but I commented it out because I thought it has to be:
    SYMBOL serpin = porta.0 ' Encoder data input pin.


    Please correct me if I am wrong.

    Thank you
    Last edited by tazntex; - 3rd August 2010 at 14:43.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    No one is laughing. You are trying to learn and that is what we like around here.

    When using SERIN2/SEROUT2
    INCLUDE "MODEDEFS.BAS"
    is not needed. Does not cause any problems if it is there though. It is a hold over from the BS1 days.

    Same goes for "SYMBOL", another BS1 hold over.
    serpin VAR porta.0 'serial input pin
    is fine.

    Unless I am missing something your code looks like it will work for what you want.
    You did what I would do...
    ;clrf GPIO ; Clear outputs on button release (or timeout)
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thank you for checking this for me, I appreciate your help.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts