12f675_fuse_about_to_blow! - Page 24


Closed Thread
Page 24 of 24 FirstFirst ... 142021222324
Results 921 to 929 of 929
  1. #921
    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!

  2. #922
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    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.

  3. #923
    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 19:19.

  4. #924
    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.

  5. #925
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    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)

  6. #926
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    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?

  7. #927
    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

  8. #928
    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!

    Hi mackrackit.

    Here's the Tx and Rx code as is stands. The Tx program now transmits a data WORD on button press, not just the button press itself.

    Tx:

    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
     
        DEFINE OSC 4
        DEFINE OSCCAL_1K 1
        DEFINE NO_CLRWDT 1    
     
        SYMBOL D_OUT = GPIO.2 ' RF serial data output
        SYMBOL E_OUT = GPIO.5 ' RF transmitter enable output
     
        VISITS   VAR word   ' Holds total daily bird visits
        DAT_OUT  VAR BYTE   ' Holds 8-bit data byte
        DAT_OUT2 VAR BYTE   ' Holds 8-bit test byte 
        LOOPS    VAR BYTE   ' Loop var
        CHK_SUM  VAR BYTE   ' Holds calculated checksum of outbound data
        I        VAR word   ' Delay loop count
        BAUD     VAR WORD   ' Holds baud rate
     
        ' Constants
        PreAmble CON $A5    ' 10100101 preamble
        Synch    CON "~"    ' 01111110 synch byte
        N4800    CON 188    ' 4800 bps 
        N2400    CON 16780  ' 2400 bps
        GUARD    CON 5      ' 5mS guard time pause
        PACE     CON 5      ' Set CHAR transmission speed
     
        ' hardware init 
        GPIO = 0            ' Everything off on boot
        ' GPIO.2=data out, GPIO.5=RF enable, GPIO.3,4 = Bird_visit_count / It's dark..maybe
        TRISIO = %00011011  '
        ANSEL = 0           ' Disable A/D
        INTCON = %00001000   ' Enable port change wakeup from sleep
        WPU = %00010000     ' pull-up on for GPIO.4 (external pull-up already on GPIO.3)
        IOC = %00011000     ' Wakeup on change enabled for GPIO.3,4
        VRCON = 0           ' Disable internal Vref
        CMCON = 7           ' Disable comparators
        OPTION_REG = 0      ' Pull-ups on 
     
        D_OUT = 0           ' Idles low for inverted serial output
        E_OUT = 0           ' Enable for RF transmitter=0 (transmiter off)
        BAUD = N2400        ' Set baud rate here
     
    Main:
        ' Read port to clear missmatch, if with no buttons pressed, then
        ' clear int-on-change flag & snooze until wake up on change. This
        ' conserves battery power on the demo board with 3V coin cell.
     
      IF GPIO.3= 1 AND GPIO.4= 1 THEN ' Nothing has happened so SLEEP
           E_OUT=0       ' Disable transmitter
           INTCON.0 = 0  ' No Inputs detected or it's still light so clear int on change flag
           @ SLEEP       ' and start snoozin..zzzzzzzzzzz indefinatly
           @ NOP
           ENDIF
        ' E_OUT=1        ' Mackrackit, I moved this to (after delay loop)this to save power as I need a long
        'PAUSEUS 25      ' Delay loop 30mins so saves Transmitter power
     
    Delay:    
         FOR I = 1 TO 2  ' Delay loop 2sec test
         PAUSe 1000
         NEXT I 
     
         IF GPIO.3=1 and GPIO.4=1 THEN 'Button pressed then released..carry on     
     
    Encode:
        E_OUT=1        ' Enable transmitter (+ lights RFEN LED on demo board)
        PAUSEUS 25     ' Allow RF stage to stabilize
     
        DAT_OUT = %10101001 
        INTCON.0 = 0  ' Clear int on change flag  
     
        'Build checksum of 2 data bytes
        CHK_SUM = (DAT_OUT * 2) 
     
    Transmit:
        'LET VISITS = VISITS / 2  'Just VISITS too not from the box 
        LET VISITS = 300 'Test data number (Bird visits)
        SEROUT2 D_OUT,BAUD,PACE,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM,VISITS.highbyte,VISITS.lowbyte]
        PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
        endif
        GOTO Main
     
     
        END
    When the 'Test Data' number arrives at the Rx the code flashes an led three times if DATA is TRUE.

    Rx:

    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  ' 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 300
        X         VAR BYTE  ' Loop counter value 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 = 0
        MATCH  = 0           ' Clear match count
     
    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 = 1 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:
        PORTA = DAT_IN1 & DAT_IN2
        DAT_IN1 = !DAT_IN2  ' Destroy the match
        MATCH = 0 
     
        IF VISITS = 300 THEN  LED    
        GOTO MAIN 
     
    lED:
     
        for X = 1 to 3  'Blink led 3 times to show data has arrived (correctly)
        HIGH PORTA.1  
        PAUSE 500
        LOW PORTA.1
        pause 500
        next X
        GOTO MAIN
     
     
        END
    Still much to do / change but a good day today. I've sent the Tx / Rx into a continual 'Test' loop
    hasn't missed a beat so far, really pleased.

    As always thanks for everyone's help, input.

    Dave
    Last edited by LEDave; - 17th May 2011 at 23:45.

  9. #929
    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!

    Really pleased to say the project took a giant leap forward tonight. Have re-written some of the code to work with pull-down resistor now 0v = off, 5v = on.

    Tap a wire +5v to GPIO.0 ten times, then touch GPIO.1 once and the Tx Tx's and the Rx board flashes 5 times (simulates five visits to bird box).

    Still plenty to do I'm sure but feeling a little like Marconi this evening.

    Dave
    Last edited by LEDave; - 22nd May 2011 at 00:22.

Members who have read this thread : 1

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