Time Out ?


Closed Thread
Results 1 to 13 of 13

Thread: Time Out ?

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default One more question,...

    I've compiled and ran this but it still hangs meaning the output is still on then a few seconds later goes off. As I noted PORTA needs to be cleared but with the exception of PORTA.0 ( my serin pin). By adding clrf PORTB for a split second they come on and go off immediately while still transmitting. I wonder if if by timing out after receiving is causing PORTB to now act that way. Is this to fast "at 4MHz Timer1 overflows in 65536 * 1uS (~65.5mS)" ? and how could I adjust this?


    @ 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

    TMR1IF var PIR1.0 ' Timer1 overflow interrupt flag (reset in int handler)
    TMR1IE var 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 %0010000000000001
    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
    i 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 PORTA ; Clear outputs on button release (or timeout)

    From what I understand from the datasheet I can clear selected outputs by:
    bcf PORTA, 2
    bcf PORTA, 3
    bcf PORTB, 0
    bcf PORTB, 1
    bcf PORTB, 2
    bcf PORTB, 3
    bcf PORTB, 4
    bcf PORTB, 5
    bcf PORTB, 6
    bcf PORTB, 7

    ;I REALLY NEED TO CLEAR PORTA WITH THE EXCEPTION OF PORTA.O (SERIN PORT)

    clrf PORTB ; 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 1000 'SETTLE INPUTS


    start:
    high 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
    mydata = 0
    mydata1 = 0
    mydata2 = 0
    mydata3 = 0
    mydata4 = 0
    porta.1 = 0
    porta.2 = 0
    porta.3 = 0
    portb = 0
    pause 50

    cycle:
    high 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 **** /

    As I mentioned earlier after making changes the output will quickly come on and go off.
    Thanks
    Last edited by tazntex; - 3rd August 2010 at 21:12.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Looking at the datasheet I just changed the timer from Internal to External :
    from this:
    ' Setup Timer1 for resets after ~65.5mS
    T1CON = %00000000'%00000000Internal clock, 1:1 prescale, Timer1 off for now

    to this:
    ' Setup Timer1 for resets after ~65.5mS
    T1CON = %00000010'%00000000Internal clock, 1:1 prescale, Timer1 off for now

    Now it works and holds the output on while transmitting but when I release the button most of the time there is a delay of several seconds before the output goes off.

    Am I on the right track?

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


    Did you find this post helpful? Yes | No

    Default

    I did not think about the external OSC change, good catch.

    For some reason I was thinking that you did not want to clear anything in the ASM routine...
    I do not see what it would hurt to clear all of PORTA in the ASM, "clrf PORTA". When the code gets to SERIN2 it will still input.

    Now it works and holds the output on while transmitting but when I release the button most of the time there is a delay of several seconds before the output goes off.
    That I am not sure about. Maybe there is something in the TX code causing things to drag?

    Maybe post both the TX and RX and someone will be able to spot the problem.
    Dave
    Always wear safety glasses while programming.

  4. #4


    Did you find this post helpful? Yes | No

    Default Timer???

    Am Using the correct timer, I am using an external 4mHz oscilliator on RA6 and RA7, I've just noticed that on the original code Bruce has the PIC is a 12F635. T1CON: TIMER1 CONTROL REGISTER bit 7 is set to 0 and that Timer counts when the gate is low, I don't have a gate, so how am I counting?


    By the way I am using a 16F628A.
    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Neither on is counting.
    On the 635, T1CON bit 6 is 0 in Bruce's code. Bit 6 being 0 just turns on the timer, no gate.
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply, So as it is in the previous post it seems to work, but I just was looking over the datasheets of both the PIC's this past weekend. I was just curious how it works, I am still struggling to understand the timers. I shall keep reading because it is not clear to me what makes it "tick" to jump out and continue.


    Thanks again for the many replies.
    '73

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


    Did you find this post helpful? Yes | No

    Default

    I shall keep reading because it is not clear to me what makes it "tick" to jump out and continue.
    Yup, they can be confusing at times. You may have this part figured out but we will start someplace.

    Once the timer is setup it will run in the background as if there is a second chip. This second process can be looked at as an alarm clock. When the alarm goes off, timer overflows, it will interrupt the main process.

    At this time we turn the alarm off, disable the timer, and do whatever... get up go about our day....

    Then the alarm is set again...
    Dave
    Always wear safety glasses while programming.

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