12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    But the other code (Bruce's) worked when my mod did not appear to ???
    It did / does. Bruce's code for the Tx - Rx on button press works a treat, it never misses a beat. The problem appears when we try and add in a time delay loop.

    Here's Bruce's original Rx code (a button press on the transmitter = immediate led flash on Rx board).

    Code:
    '****************************************************************
    '*  Name    : rfPIC_RX.BAS                                      *
    '*  Author  : B. Reynolds                                       *
    '*  Notice  : Copyright (c) 2007 Reynolds Electronics           *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/09/2007                                        *
    '*  Version : 1.0 (Momentary decoder version)                   *
    '*  Notes   : 2-Bit decoder for Microchip RF dev system         *
    '*          : with rfRXD0420 module installed in PICkit 1 board *
    '*  PIC     :  PIC16F684 Originally PIC16F676!!!                                       *
    '****************************************************************
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _PWRTE_ON 
        DEFINE OSC 4
        DEFINE NO_CLRWDT 1      ' Watchdog timer is disabled, so we don't need to reset it
        DEFINE INTHAND RESET_VT ' Interrupt on Timer1 overflow to reset outputs in 65.5mS
                                ' if no serial data received in this time period
        SYMBOL  D_IN = PORTC.1  ' data input pin
        SYMBOL  TMR1IF = PIR1.0 ' Timer1 overflow interrupt flag (reset in int handler)
        SYMBOL  TMR1IE = PIE1.0 ' Timer1 interrupt enable bit
     
        'Variables for saving state in interrupt handler
        wsave   VAR BYTE $5F system    ' Saves W
        ssave   VAR BYTE bank0 system  ' Saves STATUS
        psave   VAR BYTE bank0 system  ' Saves PCLATH
        fsave   VAR BYTE bank0 system  ' Saves FSR
     
        ' Working variables
        MATCH     VAR BYTE bank0 system ' Match variable
        DAT_OUTB  VAR BYTE  ' Holds decoded data for output
        DAT_IN1   VAR BYTE  ' 1st Data byte
        DAT_IN2   VAR BYTE  ' 2nd Data byte for verify
        CHK_SUM   VAR BYTE  ' Holds checksum received
        CheckSum  VAR BYTE  ' Computed checksum of all bytes received
        LOOPS     VAR BYTE  ' Loop var
     
        ' Constants
        Synch    CON "~"    ' 01111110 synch byte
        N2400    CON 16780  ' 2400 bps inverted
        N4800    CON 188    ' 4800 bps inverted
     
         ' hardware init
        PORTA = 0
        TRISA = %00111001   ' RA1 and RA2 are LED outputs
        PORTC = 0           ' Clear outputs on power-up
        TRISC = %00111110   ' RC1 = RF input
        IOC = 0             ' Interrupt on change disabled
        VRCON = 0           ' Comparator Vref disabled
        CMCON0 = 7           ' Disable comparators
        ANSEL = 0           ' disable A/D
        OPTION_REG = 128    ' Pull-ups off
     
        ' 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
        MATCH = 0           ' Clear match count
        GOTO    MAIN        ' Jump over int handler
     
    ASM  ; Timer1 overflow interrupt resets outputs when no valid key press
         ; is detected within ~65mS
    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   PORTA         ; Clear outputs on button release
        clrf   MATCH         ; 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
     
    MAIN: 
     
        ' 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 D_IN,N2400,[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
     
        ' / **** Begin data validation **** /
     
        ' Calculate checksum by adding 2 data bytes together
        CheckSum = DAT_IN1 + DAT_IN2
     
        ' Test new checksum against one received in CHK_SUM
        IF CheckSum != CHK_SUM THEN MAIN ' Failed checksum, return
     
        ' Test data bytes for match
        IF (DAT_IN1) != (DAT_IN2) THEN MAIN ' Failed data comparison, return
     
        MATCH = MATCH + 1        ' We have a match so increment match count
        IF MATCH = 2 THEN DECODE ' Everything matched twice, we're good
        GOTO Main                ' Else do it all over
     
        ' Everything looking good - so place new data on outputs
    DECODE:
        ' Place decoded values on port pins..
        PORTA = DAT_IN1 & %00000110
        DAT_IN1 = !DAT_IN2  ' Destroy the match
        MATCH = 0 
        GOTO MAIN
     
        END
    And here's the 'chopped down' version which doesn't Rx on every Tx but DOES Rx after the timing loop on the Tx has run.

    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _PWRTE_ON 
        DEFINE OSC 4
        DEFINE NO_CLRWDT 1      ' Watchdog timer is disabled, so we don't need to reset it
     
        SYMBOL  D_IN = PORTC.1  ' data input pin
     
        ' Working variables
        MATCH     VAR BYTE bank0 system ' Match variable
        DAT_OUTB  VAR BYTE  ' Holds decoded data for output
        DAT_IN1   VAR BYTE  ' 1st Data byte
        DAT_IN2   VAR BYTE  ' 2nd Data byte for verify
        CHK_SUM   VAR BYTE  ' Holds checksum received
        CheckSum  VAR BYTE  ' Computed checksum of all bytes received
        LOOPS     VAR BYTE  ' Loop var
        VISITS    var word  ' Test BYTE with a value of 3 - DT
        X         VAR BYTE  ' Loop counter value Byte - DT
        Total     var byte
     
        ' Constants
        Synch    CON "~"    ' 01111110 synch byte
        N2400    CON 16780  ' 2400 bps inverted
        N4800    CON 188    ' 4800 bps inverted
     
         ' hardware init
        PORTA = 0
        TRISA = %00111001   ' RA1 and RA2 are LED outputs
        PORTC = 0           ' Clear outputs on power-up
        TRISC = %00101110   ' RC1 = RF input
        IOC = 0             ' Interrupt on change disabled
        VRCON = 0           ' Comparator Vref disabled
        CMCON0 = 7           ' Disable comparators
        ANSEL = 0           ' disable A/D
        OPTION_REG = 128    ' Pull-ups off
     
     
        INTCON =  %11000000 ' Global & peripheral ints enabled
        MATCH = 0           ' Clear match count
        GOTO    MAIN        ' Jump over int handler
     
    MAIN:         
     
        ' Wait for Synch byte, then get new inbound data & checksum
        SERIN2 D_IN,N2400,[WAIT(Synch),DAT_IN1,DAT_IN2,CHK_SUM,VISITS.HIGHBYTE,VISITS.LOWBYTE]
     
        ' / **** Begin data validation **** /
     
        ' Calculate checksum by adding 2 data bytes together
        CheckSum = DAT_IN1 + DAT_IN2
     
        ' Test new checksum against one received in CHK_SUM
        IF CheckSum != CHK_SUM THEN MAIN ' Failed checksum, return
     
        ' Test data bytes for match
        IF (DAT_IN1) != (DAT_IN2) THEN MAIN ' Failed data comparison, return
     
      '  MATCH = MATCH + 1        ' We have a match so increment match count
       ' IF MATCH = 2 THEN DECODE ' Everything matched twice, we're good
       ' GOTO Main                ' Else do it all over
     
        ' Everything looking good - so place new data on outputs
    DECODE:
     
        'DAT_IN1 = !DAT_IN2  ' Destroy the match
       ' MATCH = 0 
     
        IF VISITS = 300 THEN  LED    
        GOTO MAIN 
     
    lED:
     
        for X = 1 to 3  'Test=7  or 600
        HIGH PORTA.1  
        PAUSE 500
        LOW PORTA.1
        pause 500
        next X
        GOTO MAIN
     
     
        END
    Dave
    Last edited by LEDave; - 17th May 2011 at 14:04.

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    I use config fuse WTD_OFF and never had to use this:

    DEFINE NO_CLRWDT 1 ' Watchdog timer is disabled, so we don't need to reset it
    (still looking over rest of code)

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Without the define, PBP will sprinkle CLTWDT through out your code. The Config tells uP not to use it, the DEFINE tells PBP not to.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Quote Originally Posted by cncmachineguy View Post
    Without the define, PBP will sprinkle CLTWDT through out your code. ...
    I cannot Find CLTWDT in the ASM file of my latest project?

    So I went through older larger programs in code size was an issue. None of the ASM has CLTWDT either.

  5. #5
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Just had a breakthrough with the project

    Having modified Bruce's code to make the timing loop run & transmit. Tx 'consistancy' was a problem. The data was only recieved about 3 in 5 times. So reading the Manual, I added PACE to the program with a 5ms delay, result the data now gets Tx'd & Rx'd everytime with the delay loop.....Whoopee....!

    Code:
    SEROUT2 D_OUT,BAUD,PACE,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM,VISITS.highbyte,VISITS.lowbyte]
    Mega_Chuffed tonight.

    Dave
    Last edited by LEDave; - 17th May 2011 at 18:19.

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


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    COOL

    Can you post the complete code as is? Just to keep everything/everyone UpToDate...
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Quote Originally Posted by LEDave View Post
    Just had a breakthrough with the project
    ...
    Good news!


    About the checksum:

    Code:
    SEROUT2 D_OUT,BAUD,PACE,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM,VISITS.highbyte,VISITS.lowbyte]
    I always thought the idea behind checksum was to confirm that a data transfer had completed successfully. As it stands, you are checking data from the front of the stream only. I would put the CHKSUM at the end of your data stream, that way you are certain you have received everything.

    It might not be necessary with the way PBP processes Serout commands, but this is from old programming habits in a business environment (you want to be sure everything made it through).

    Code:
    SEROUT2 D_OUT,BAUD,PACE,[PreAmble,Synch,DAT_OUT,DAT_OUT,VISITS.highbyte,VISITS.lowbyte,CHK_SUM]
    (unless the location of CHKSUM in SEROUT is pre-determined by hardware/software)

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Quote Originally Posted by LEDave View Post
    ...
    I added PACE to the program with a 5ms delay, result the data now gets Tx'd & Rx'd everytime with the delay loop.....Whoopee....!
    ...

    How did you control the Pace delay?

    I'm looking at Serout2 in PBP manual v2.60 (p.155) and only see reference of adding Pace, possibility of 1 to 65,535 ms delay, but no way of controlling delay.

    I assume Pace is a word variable that you assigned a value of 5?

  9. #9
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Can you post the complete code as is? Just to keep everything/everyone UpToDate...
    Will do mackrackit.

    It might not be necessary with the way PBP processes Serout commands, but this is from old programming habits in a business environment (you want to be sure everything made it through).
    Hi Demon. I hear what you're saying, makes good sense. I remember Henrik telling me that it didn't matter whether you sent Highbyte or Lowbyte first, your way kind of gives a check / checksum

    How did you control the Pace delay?
    I used:

    Code:
    PACE     CON 5
    Dave

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