12f675_fuse_about_to_blow! - Page 23


Closed Thread
Page 23 of 24 FirstFirst ... 13192021222324 LastLast
Results 881 to 920 of 929
  1. #881
    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!

    I'm having major problems trying to get the TX program to do what I want it to, namely TX after a timing loop executes. Just for information, if I comment out the timing loop the program TX's no problem and sends and receives a test WORD.

    Here's the setup:

    Code:
    INTCON = %00001000  ' Enable port change wakeup from sleep
    Code:
    WPU = %00010000     ' pull-up on for GPIO.4 (external pull-up already on GPIO.3)
    It's GPIO.4 we're looking at here. That's the pin that will receive the input from a 555 timer / potential divider using an ldr to detect that it's dark and therefore TX the days count over.

    Code:
    OPTION_REG = %00001111 'Watch_Dog_Timer ON with a 128 prescaler
    Here's the main body of the program. it's a little bit of a mess because I've commented out the GPIO.3 COUNTS part of the program and also added then commented out INTCON.0 = 0 in various places to try and get it to do the timer loop / COUNT then TX.

    Code:
    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         ' Do nothing for 1st instruction on wake-up
      ELSE  
       'IF  GPIO.3=0 THEN GOSUB COUNTS 'Bird detected at box - GOTO LABEL COUNTS   
       IF  GPIO.4=0 THEN DARK   'It's got dark? or just cloudy - GOTO LABEL DARK
      ENDIF     
      GOTO MAIN          'Back to sleep / continue counting
        
        
     'COUNTS:
        '  VISITS = VISITS +1 'Bird at box so increment counter
        '  INTCON.0 = 0       ' Clear int on change flag
      'RETURN                 ' Then back to sleep....
         
          DARK:
          
          'INTCON.0 = 0     ' Clear int on change flag
                           ' It could be night time...It might only be a cloud though...   
                           ' so back to sleep / wake / sleep for half an hour..zwzwzw
    
          COUNTER=0        ' clear before entry
    WHILE COUNTER < 2      ' 4.608sec Loop time (Loop for 30 mins = 781)
         @ SLEEP
         COUNTER=COUNTER+1
         'IF  GPIO.3= 0  THEN COUNTS 'Bird at box (it's not dark) so continue counting
    WEND     
                  
        if  GPIO.4= 0  then ENCODE  ' It really ia dark so carry on and transmit VISITS
        
        'IF  GPIO.4= 1  THEN Main  '(changed from return) It's not dark after all so carry_on_sleeping_counting 
        
    Encode:  
        E_OUT=1     ' Turn transmitter on 
        pauseus 25  ' Let transmitter settle
        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
        SEROUT2 D_OUT,BAUD,[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.
        INTCON.0 = 0  ' Clear int on change flag - moved here from above
        GOTO Main
            
        END
    I think the problem maybe that the COUNTER loop never gets completed because the IOC which comes from GPIO.4 isn't reset and the counter loop is using @SLEEP but never gets that far.

    Any ideas greatfully received.

    Dave
    Last edited by LEDave; - 4th April 2011 at 17:42.

  2. #882
    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!

    What happens if the @SLEEP below is commented?
    Code:
    WHILE COUNTER < 2      ' 4.608sec Loop time (Loop for 30 mins = 781)
         @ SLEEP
         COUNTER=COUNTER+1
         'IF  GPIO.3= 0  THEN COUNTS 'Bird at box (it's not dark) so continue counting
    WEND
    Dave
    Always wear safety glasses while programming.

  3. #883
    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!

    What happens if the @SLEEP below is commented?
    It TX's straight away and the led on the Pickit1 (receiver) flashes three times (as intended). There is no 5 sec delay from the timing loop though.

    It's as if the timing loop COUNT is just being bypassed, have I set it up right?

    Dave
    Last edited by LEDave; - 4th April 2011 at 23:11.

  4. #884
    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!

    If I press and hold down push button GP4 on the transmitter, the receiver flashes the led continually. I would have thought / was expecting that when the push button on GPIO.4 was pressed and held down you would get a four / five second delay before the receiver received anything and started to flash.

    Tonights silly question:

    How does setting the OPTION reg and WDT then become associated with the loop COUNTER? The WDT has a period of 18ms so setting the bits 111 gives 128*18ms =2.304secs the COUNTER loop should run twice giving a delay of 4.608secs right? But if the program doesn't read COUNTER as being associated with the WDT it's going to count to two in a flash and it will appear that the TX sends the data instantly(which is what is happening). Should the WDT and COUNTER be 'joined' via a 'SYMBOL statement in the program under SYMBOL? or something like this?

    Dave
    Last edited by LEDave; - 5th April 2011 at 00:30.

  5. #885
    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!

    Just guessing as I have not done this before...
    Code:
    WHILE COUNTER <= 2      ' 4.608sec Loop time (Loop for 30 mins = 781)
          INTCON.0 = 0
         @ SLEEP
         COUNTER=COUNTER+1
         'IF  GPIO.3= 0  THEN COUNTS 'Bird at box (it's not dark) so continue counting
    WEND
    I hope someone else will jump in on this...
    Dave
    Always wear safety glasses while programming.

  6. #886
    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,

    I've made the changes and the Transmitter lights the it's reference led about once every nine seconds but doesn't transmit at all (doesn't seem to get that far).

    I still can't get my head around how the WDT associates with the loop COUNTER, plus the more I read on this it seems that if the WDT isn't reset back to zero before it reaches FF+1 (I think) it then reboots the program which makes sense....Mmm, more reading and thinking to do, interesting though.

    Dave

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


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    First let me say, this is an awesome thread. I have been meaning to read it from the beginning, but I am a slow reader.

    LEDave, WDT in the snippet you just posted works like this:
    Assuming PBP knows you are using the WDT, clear WD is sprinkled around the program for you to keep from resetting the chip. But to get to these, the program must run.

    @sleep basically stops the program and the chip just, well sleeps. Because of this, the WDT never gets cleared. The WD can wake up the PIC, so when WDT overflows, the PIC wakes up and resumes where it left off. So this is how the WDT is associated with the counter.

    Hope this helps
    -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!

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

    Bert,
    will this make it work as expected?
    Code:
    WHILE COUNTER <= 2      ' 4.608sec Loop time (Loop for 30 mins = 781)
          INTCON.0 = 0
         @ SLEEP
        CLEARWDT
         COUNTER=COUNTER+1
         'IF  GPIO.3= 0  THEN COUNTS 'Bird at box (it's not dark) so continue counting
    WEND
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Dave, sorry for being only clear as mud with my explaination. I ment to say : because of this, the WD never gets cleared WHILE SLEEPING. When the pic is asleep, WDT overflows thus waking up the PIC.

    I tried to quickly look over the program a few posts up, but I don't have a good feel for it yet. I don't think adding the CLRWDT will help only because when the pic wakes, it should be a long time (~2sec) before the next overflow.

    I did notice when @SLEEP is used elsewhere in the program, the line following is @NOP. Maybe this is needed to give the pic a chance to get the sleep from its eyes? I would try using @NOP right after the @SLEEP and see if this works.

    I have never used any of the power saving modes before, but if the pic needs a nop upon waking up, it may be ignoring the counter=counter+1. Therefore the while is never satisified.

    In any event,if the NOP is needed, adding CLRWDT may solve the problem, we just won't know why it did.
    -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!

  10. #890
    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 Bert

    Thanks for your input and welcome to the thread. I was heading towards the CLRWDT after reading this (quite an interesting website):

    http://www.hobbyprojects.com/pic_tut...utorial13.html

    Well here's the section of code as it stands:

    Code:
    DARK:   
          'INTCON.0 = 0    ' Clear int on change flag
                           ' It could be night time...It might only be a cloud though...   
                           ' so back to sleep / wake / sleep for half an hour..zwzwzw
          
          COUNTER=0        ' clear before entry
    WHILE COUNTER <= 2     ' 4.608sec Loop time (Loop for 30 mins = 781)
         INTCON.0 = 0      ' Clear int on change flag
         @ SLEEP
         @ NOP 
         CLEARWDT
         COUNTER=COUNTER+1
         'IF  GPIO.3= 0  THEN COUNTS 'Bird at box (it's not dark) so continue counting
    WEND     
                       
        if  GPIO.4= 0  then ENCODE  ' It really ia dark so carry on and transmit VISITS
        
        'IF  GPIO.4= 1  THEN Main  '(changed from return) It's not dark after all so carry_on_sleeping_counting 
        
    Encode:  
        E_OUT=1     ' Turn transmitter on
    What happens now is when the push button on GPIO.4 is pressed (and held down) After a count of 9 seconds approx (I was expecting a count of two to give half that time) the TX board led lights but still nothing is transmitted.

    The program still doesn't seem to get to encode and transmit, frustrating, any other thoughts?

    Dave

  11. #891
    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!

    Bert

    As an aside to the problem, earlier on in the program we have:

    Code:
    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         ' Do nothing for 1st instruction on wake-up
      ELSE  
       'IF  GPIO.3=0 THEN GOSUB COUNTS 'Bird detected at box - GOTO LABEL COUNTS   
       IF  GPIO.4=0 THEN DARK   'It's got dark? or just cloudy - GOTO LABEL DARK
      ENDIF     
      GOTO MAIN          'Back to sleep / continue counting
    Does this mean that using a WDT and a SLEEP command to save power are kind of mutually exclusive? The SLEEP command turns the PIC off (saving power) then the WDT turns the PIC back on again 4.6seconds later in our case? The above code would keep looping on and off until a button is pressed or the 3v cell goes flat?

    Dave
    Last edited by LEDave; - 5th April 2011 at 23:24.

  12. #892
    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!

    Have spent several interesting but largely fruitless hours trying to make some progress with the program.

    However if I jump passed the COUNTER / WDT routine the TX & RX work fine which is good to know.

    Here's the code for it:

    Code:
          COUNTER=0        ' clear before entry
    WHILE COUNTER <= 2     ' 4.608sec Loop time (Loop for 30 mins = 781)
         INTCON.0 = 0      ' Clear int on change flag
         @ SLEEP
         @ NOP 
         CLEARWDT
         COUNTER=COUNTER+1
    One thought does occur to me though, at the start of the program the PIC is placed into SLEEP mode, only to be woken on INTERRUPT.

    Code below.

    Code:
    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         ' Do nothing for 1st instruction on wake-up
           CLEARWDT
      ELSE  
       'IF  GPIO.3=0 THEN GOSUB COUNTS 'Bird detected at box - GOTO LABEL COUNTS   
       IF  GPIO.4=0 THEN   encode 'DARK 'Encode 'DARK   'It's got dark? or just cloudy - GOTO LABEL DARK
    However, GPIO.4 must be pressed and held down (simulating night time) which causes the wake up from SLEEP interrupt, the program then moves down to the COUNTER / WDT loop. I think I might have found a problem here though. For the COUNTER / WDT loop to work and give a 4.6sec test delay the PIC must go into SLEEP mode, if GPIO.4 is continually held down simulating night time and hence causing an INTERRUPT from SLEEP (continually, even resetting the interrupt won't help as button continually pressed) then my thinking says the COUNTER /WDT loop will never work because the PIC is always being woken up.

    A bit garbled I know, sorry, but am I onto something.

    Dave

  13. #893
    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!

    I'm having a problem getting the rfpic transmitter to Tx when I want it to. I've set up an ON INTERRUPT with DISABLE - RESUME - ENABLE and have the INTCON & IOC set at:

    Code:
    INTCON = %00001000 & IOC = %00011000
    What happens is, when buttons GPIO3/4 are pressed (and released)the RFEN led after a 5sec delay briefly flashes but no data is sent. If GPIO.3/4 are pressed and held down after 10 secs the RFEN led lights up the five seconds later (button still held down) data is Tx'd, the button is then released and five seconds later the RFEN led goes out.

    What I'd like is for the buttons GPIO.3/4 to be pressed, ON INTERRUPT runs then five seconds later after the delay loop the data is Tx'd. Does anyone have any idea on what's going wrong?

    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
     
        ON INTERRUPT GOTO  Delay
     
        DAT_OUT  VAR BYTE   ' Holds 8-bit data byte
        CHK_SUM  VAR BYTE   ' Holds calculated checksum of outbound data
        VISITS   VAR WORD   ' Loop variable (300 for test)
        I        VAR word   ' Delay Loop Count value  
        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
     
     
        ' 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 / Waiting for IOC
        @ NOP
        'ON INTERRUPT starts / returns here with Button_press: goes to LABEL - "DELAY":
     
    ENDIF
    Encode: 
     E_OUT=1     ' Turn transmitter on 
        pauseus 25  ' Let transmitter settle
        DAT_OUT = %10101001
     
        '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
         SEROUT2 D_OUT,BAUD,[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.
         GOTO Main 
     
    disable 
     
    Delay:
    FOR I = 1 TO 5
        PAUSe 1000
    nEXT I 
    INTCON.0 = 0 
    resume : enable 
    goto Main
    Dave

  14. #894
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    I think change this to the number that represents
    the mode referenced by this. I "think" baud is
    1 byte trying to hold 5 byte ASCII word.

    Code:
    BAUD = N2400        ' Set baud rate here
    I am not home right now, so I cannot check, does
    this PIC have interrupts? On the pins you want them?
    Finally "On Interrupt" is like asking you teen to
    clean his room, he will, someday.
    Use DT_INTS for fast reliable interrupts, maybe will not fit a 675.
    Last edited by Archangel; - 12th May 2011 at 05:54. Reason: add
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  15. #895
    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!

    Name:  RFRXD0420.pdf - Adobe Reader_2011-05-12_09-34-44.png
Views: 1475
Size:  51.8 KB

    does
    this PIC have interrupts? On the pins you want them?
    Hi Joe, from the data sheet (pasted above) so yes IOC on pins I need.

    I've changed BAUD to:

    Code:
    BAUD = 16780        ' Set baud rate here
    Program does same as before though - Also if @SLEEP is commented out as
    mackrackit suggested earlier, the rfpic transmits pretty much transmits on button press.

    Use DT_INTS for fast reliable interrupts, maybe will not fit a 675.
    I'll have a look into DT_INTS later today, thanks for the pointer.

    PS: Sorry for pasting Data sheet info into the thread instead of as an attachment, not sure what I did wrong there.

    Dave

  16. #896
    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!

    Yes, I told you to use DISABLE-ENABLE-RESUME... I thought you were playing with ONINTERUPPT.

    Looks like you are still using Bruce's code as a base, so lets go back to it and modify it some.

    But first you may want to try Bruce's code as he wrote it to make sure your hardware is working correctly.

    Code:
    '****************************************************************
    '*  Name    : rfPIC_TX.BAS                                      *
    '*  Author  : B. Reynolds                                       *
    '*  Notice  : Copyright (c) 2007 Reynolds Electronics           *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/09/2007                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : 2-BIT Encoder for remote control with the         *
    '*          : rfPIC12F675 on Microchip rfPIC demo board         *
    '****************************************************************
    @ DEVICE PIC12F675,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
    @ DEVICE PWRT_ON,PROTECT_OFF
        
        ' With rfRXD0420 module installed in PICkit 1 board;
        ' SW1 toggles LED D6 on PICkit 1 board
        ' SW2 toggles LED D7 on PICkit 1 board
        DEFINE OSC 4
        DEFINE NO_CLRWDT 1
        DEFINE OSCCAL_1K 1
        
        SYMBOL D_OUT = GPIO.2 ' RF serial data output
        SYMBOL E_OUT = GPIO.5 ' RF transmitter enable output
        
        DAT_OUT VAR BYTE    ' Holds 8-bit data byte
        LOOPS   VAR BYTE    ' Loop var
        CHK_SUM VAR BYTE    ' Holds calculated checksum of outbound data
        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
        
        ' hardware init 
        GPIO = 0            ' Everything off on boot
        ' GPIO.2=data out, GPIO.5=RF enable, GPIO.3,4=SW1/SW2 switch inputs (rfPIC board)
        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 ' pins will be 0 only when buttons are pressed
         E_OUT=0         ' Disable transmitter
         INTCON.0 = 0    ' No buttons down, so clear int on change flag
         @ SLEEP         ' and start snoozin..zzzzzzzzzzz
         @ NOP           ' Do nothing for 1st instruction on wake-up
        ENDIF
        E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
        PAUSEUS 25       ' Allow RF stage to stabilize
        
        ' Button pressed (or being held down), so keep going   
    ' Here is where you want to put the 5 second loop
    Delay:
    FOR I = 1 TO 5
        PAUSe 1000
    NEXT I 
    'Then check the buttons again
     IF (GPIO.3=1) AND (GPIO.4=1) THEN
    
    'Look for ENDIF near the end.  
    'If button are still pressed then it goes to ENCODE
    'If not, go back to MAIN and the INTERRUPT ON CHANGE will be reset
    Encode:  
        ' Only DAT_OUT bits 1 and 2 are used. We add a few 1's in bit
        ' positions 0,3,5,7 to balance out the data packet being sent.
        DAT_OUT = %10101001
        ' Get data on button inputs & invert 0's to 1's
        DAT_OUT.0[1]=~GPIO.3
        DAT_OUT.0[2]=~GPIO.4
        INTCON.0 = 0  ' Clear int on change flag
          
        ' Build checksum of 2 data bytes
        CHK_SUM = (DAT_OUT * 2)
        
    Transmit:
        SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM]
        PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
    
        ENDIF
        GOTO Main
            
        END
    Dave
    Always wear safety glasses while programming.

  17. #897
    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

    Yes, I told you to use DISABLE-ENABLE-RESUME... I thought you were playing with ONINTERUPPT.
    I did and I am still hoping to get it working: Post #893 above has ON INTERRUPT -DISABLE-ENABLE-RESUME in the code.

    Thanks for the TX program, I had to change:

    Code:
    @DEVICEPIC12F675,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
    @ DEVICE PWRT_ON,PROTECT_OFF
    To:

    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _PWRTE_ON
    To make the program compile, are the above changes ok?

    So what happened when I ran it? Well the RFEN led lit for five seconds immediately either button was pressed but nothing was transmitted. I then commented out the delay loop, the RFEN led lit when buttons pressed then went off when button released - still no data sent.

    I see where you're coming from with the IF - THEN with the program then going onto the ENDIF statement.

    I made a small change adding:

    Code:
    IF (GPIO.3=1) AND (GPIO.4=1) THEN goto   Main
     if (GPIO.3=0) OR (GPIO.4=0) THEN 'Look for ENDIF
    The result was the RFEN led lit for five seconds immediately either button was pressed but nothing was transmitted (as before) however, when the delay loop was commented out data was trnsmitted.

    It seems to me that the delay loop is killing the data transfer. What do you think?

    But first you may want to try Bruce's code as he wrote it to make sure your hardware is working correctly.
    I've saved Bruce's original code as Tx - Rx Master, works a treat.

    Dave
    Last edited by LEDave; - 12th May 2011 at 21:38.

  18. #898
    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!

    A breakthrough, I think....

    I moved the delay loop to run right after the IOC from @SLEEP. So what happens now is if GPIO.3/4 are held down, after 5sec delay data is Tx'd. If GPIO.3/4 are pressed and released within 5secs PIC goes back to @SLEEP.

    mackrackit, idea why moving the delay loop 'made a difference' to my mind it should have worked where you put it too.

    Code:
    IF (GPIO.3=1) AND (GPIO.4=1) THEN ' pins will be 0 only when buttons are pressed
         E_OUT=0         ' Disable transmitter
         INTCON.0 = 0    ' No buttons down, so clear int on change flag
         @ SLEEP         ' and start snoozin..zzzzzzzzzzz
         @ NOP           ' Do nothing for 1st instruction on wake-up
        FOR I = 1 TO 5
          PAUSe 1000
          NEXT I 
        ENDIF
        E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
        PAUSEUS 25       ' Allow RF stage to stabilize
     
    'Then check the buttons again
     IF (GPIO.3=1) AND (GPIO.4=1) THEN  Main 'Button not pressed or pressed then released
     if (GPIO.3=0) OR  (GPIO.4=0) THEN       'Carry on to ENDIF & Tx DATA
    Dave
    Last edited by LEDave; - 13th May 2011 at 01:45.

  19. #899
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Quote Originally Posted by LEDave View Post
    Attachment 5485



    Hi Joe, from the data sheet (pasted above) so yes IOC on pins I need.

    I've changed BAUD to:

    Code:
    BAUD = 16780        ' Set baud rate here
    Program does same as before though - Also if @SLEEP is commented out as
    mackrackit suggested earlier, the rfpic transmits pretty much transmits on button press.



    I'll have a look into DT_INTS later today, thanks for the pointer.

    PS: Sorry for pasting Data sheet info into the thread instead of as an attachment, not sure what I did wrong there.

    Dave
    OK, now at home I see why it would work Baud = n2400, because n2400 is set as a symbol in modedefs.bas as 4 (mode 4 ) so its a variable aliasing a constant. Explains Why it Should work. 16780 is a serout2 mode . . . does it work with serout ?
    Edit:
    Oh My Bad, you are using serout2.
    Last edited by Archangel; - 13th May 2011 at 02:25.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  20. #900
    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!

    mackrackit, idea why moving the delay loop 'made a difference' to my mind it should have worked where you put it too.
    I am really missing something or there is something else in your code...
    I do not see why you had to move the delay. Your way the delay should be jumped over when a button is pressed...
    Dave
    Always wear safety glasses while programming.

  21. #901
    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!

    Made a mistake, please ignore this post,Dave.
    Last edited by LEDave; - 14th May 2011 at 21:01.

  22. #902
    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!

    I am really missing something or there is something else in your code...
    Hi mackrackit

    I reloaded your code and the rfpic worked exactly as before, namely:

    The RFEN led lit for five seconds immediately either button was pressed but nothing was transmitted.

    I do not see why you had to move the delay. Your way the delay should be jumped over when a button is pressed...
    Mm, I thought (hoped) the PIC would go to SLEEP then IOC would wake it and the program would run from where it went to SLEEP, so the next thing it would do was run the delay loop...? ON INTERRUPT is on hold right now until we get the delay loop to work with the rfpic tx-ing after the delay. I'm not using ON INTERRUPT RIGHT now.

    Code:
    IF (GPIO.3=1) AND (GPIO.4=1) THEN ' pins will be 0 only when buttons are pressed
         E_OUT=0         ' Disable transmitter
         INTCON.0 = 0    ' No buttons down, so clear int on change flag
         @ SLEEP         ' and start snoozin..zzzzzzzzzzz
         @ NOP           ' Do nothing for 1st instruction on wake-up
        FOR I = 1 TO 5
          PAUSe 1000
          NEXT I 
        ENDIF
        E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
        PAUSEUS 25       ' Allow RF stage to stabilize
     
    'Then check the buttons again
     IF (GPIO.3=1) AND (GPIO.4=1) THEN  Main 'Button not pressed or pressed then released
     if (GPIO.3=0) OR  (GPIO.4=0) THEN       'Carry on to ENDIF & Tx DATA
    Dave
    Last edited by LEDave; - 14th May 2011 at 22:11.

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


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Jumping in again, possibly completely off base here. But, is there any kind of max time between when you enable the tx, and when you send it data? Because all I see different about moving the delay loop is then enable is moved after it.

    As a side note, why not change the for loop to something much bigger like 1 to 250, then make the pause time of 20. This won't help the current problem, but when you are back to on interrupt you will not be trapped in the pause for near as long.
    -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!

  24. #904
    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!

    Jumping in again, possibly completely off base here. But, is there any kind of max time between when you enable the tx, and when you send it data? Because all I see different about moving the delay loop is then enable is moved after it.
    Hi cncmachineguy, I suspect timing has a lot to do with it (although I don't kow enough to say or point to why).

    Plenty of head scratching going on here.

    As a side note, why not change the for loop to something much bigger like 1 to 250, then make the pause time of 20. This won't help the current problem, but when you are back to on interrupt you will not be trapped in the pause for near as long..
    Yes, pauses for too long are bad news for what I'm aiming at with this project.

    Dave
    Last edited by LEDave; - 15th May 2011 at 00:36.

  25. #905
    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!

    In my code try moving
    Code:
     E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
        PAUSEUS 25       ' Allow RF stage to stabilize
    to the beginning of the
    Encode:
    block...

    Search this document for "RFEN"..
    http://ww1.microchip.com/downloads/e...doc/70091a.pdf
    Last edited by mackrackit; - 15th May 2011 at 01:49.
    Dave
    Always wear safety glasses while programming.

  26. #906
    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!

    I moved the code.

    What happens is:

    1/ If a button is pressed and released RFEN briefly flashes after the 5sec delay (no data is Tx'd).

    2/ If a button is continually pressed, nothing happens at all (RFEN doesn't light / no data is Tx'd.

    Dave
    Last edited by LEDave; - 15th May 2011 at 03:24.

  27. #907
    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!

    How is the voltage on the power supply/battery?

    I hope Bruce stops in and sees this as I am lost...
    Dave
    Always wear safety glasses while programming.

  28. #908
    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!

    How is the voltage on the power supply/battery?
    I'm using a power supply set at 4.66v.

    For some reason my attachments are appearing here 'inline' rather than at the page bottom, sorry.

    The comment about dataask going high caught my eye. Maybe our timing is off a touch (not sure if or why) with the RFEN coming on and us missing data-ask going high (there is no technical reason why anything I've just typed is remotely true) Just my gut....aka....Agent Gibbs style...!

    Name:  RFRXD0420.pdf - Adobe Reader_2011-05-15_02-38-20.png
Views: 882
Size:  42.5 KB

    Dave
    Last edited by LEDave; - 15th May 2011 at 04:05.

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


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Sorry guys, I will have to just keep following. I'm stumpted.
    -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!

  30. #910
    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!

    Can you post your entire program as it stands now?

    (There's no way my feeble mind can remember all changes through a 23 page thread.)
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  31. #911
    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!

    Two versions to look at really Demon. I've posted two, it might help you see 'something' because although very similar, what they both do is subtley different things.

    The first one does this on button presses:

    1/ If a button is pressed and released RFEN briefly flashes after the 5sec delay (no data is Tx'd).

    2/ If a button is continually pressed, nothing happens at all (RFEN doesn't light / no data is Tx'd.


    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _PWRTE_ON
     
        ' With rfRXD0420 module installed in PICkit 1 board;
        ' SW1 toggles LED D6 on PICkit 1 board
        ' SW2 toggles LED D7 on PICkit 1 board
        DEFINE OSC 4
        DEFINE NO_CLRWDT 1
        DEFINE OSCCAL_1K 1
     
        SYMBOL D_OUT = GPIO.2 ' RF serial data output
        SYMBOL E_OUT = GPIO.5 ' RF transmitter enable output
     
        DAT_OUT VAR BYTE    ' Holds 8-bit data byte
        LOOPS   VAR BYTE    ' Loop var
        CHK_SUM VAR BYTE    ' Holds calculated checksum of outbound data
        BAUD    VAR WORD    ' Holds baud rate
        I       VAR BYTE
     
        ' 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
     
        ' hardware init 
        GPIO = 0            ' Everything off on boot
        ' GPIO.2=data out, GPIO.5=RF enable, GPIO.3,4=SW1/SW2 switch inputs (rfPIC board)
        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 ' pins will be 0 only when buttons are pressed
         E_OUT=0         ' Disable transmitter
         INTCON.0 = 0    ' No buttons down, so clear int on change flag
         @ SLEEP         ' and start snoozin..zzzzzzzzzzz
         @ NOP           ' Do nothing for 1st instruction on wake-up
        ENDIF
       ' E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
       ' PAUSEUS 25       ' Allow RF stage to stabilize
     
    ' Button pressed (or being held down), so keep going   
    ' Here is where you want to put the 5 second loop
    Delay:
    FOR I = 1 TO 5
        PAUSe 1000
    NEXT I 
    'Then check the buttons again
     IF (GPIO.3=1) AND (GPIO.4=1) THEN
    'Look for ENDIF near the end.  
    'If button are still pressed then it goes to ENCODE
    'If not, go back to MAIN and the INTERRUPT ON CHANGE will be reset
    Encode: 
    E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
    PAUSEUS 25       ' Allow RF stage to stabilize 
        ' Only DAT_OUT bits 1 and 2 are used. We add a few 1's in bit
        ' positions 0,3,5,7 to balance out the data packet being sent.
        DAT_OUT = %10101001
        ' Get data on button inputs & invert 0's to 1's
        DAT_OUT.0[1]=~GPIO.3
        DAT_OUT.0[2]=~GPIO.4
        INTCON.0 = 0  ' Clear int on change flag
     
        ' Build checksum of 2 data bytes
        CHK_SUM = (DAT_OUT * 2)
     
    Transmit:
        SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM]
        PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
        ENDIF
        GOTO Main
     
        END
    This one does this:

    1/ Tx's the data after the button is continually held down for 5secs.

    2/ The RFEN led briefly flashes (after 5secs) if either button is pressed and released.

    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _PWRTE_ON
     
        ' With rfRXD0420 module installed in PICkit 1 board;
        ' SW1 toggles LED D6 on PICkit 1 board
        ' SW2 toggles LED D7 on PICkit 1 board
        DEFINE OSC 4
        DEFINE NO_CLRWDT 1
        DEFINE OSCCAL_1K 1
     
       ' ON INTERRUPT goto  Delay
     
        SYMBOL D_OUT = GPIO.2 ' RF serial data output
        SYMBOL E_OUT = GPIO.5 ' RF transmitter enable output
     
        DAT_OUT VAR BYTE    ' Holds 8-bit data byte
        LOOPS   VAR BYTE    ' Loop var
        CHK_SUM VAR BYTE    ' Holds calculated checksum of outbound data
        BAUD    VAR WORD    ' Holds baud rate
            I   VAR BYTE
     
             ' 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
     
        ' hardware init 
        GPIO = 0            ' Everything off on boot
        ' GPIO.2=data out, GPIO.5=RF enable, GPIO.3,4=SW1/SW2 switch inputs (rfPIC board)
        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 ' pins will be 0 only when buttons are pressed
         E_OUT=0         ' Disable transmitter
         INTCON.0 = 0    ' No buttons down, so clear int on change flag
         @ SLEEP         ' and start snoozin..zzzzzzzzzzz
         @ NOP           ' Do nothing for 1st instruction on wake-up
        FOR I = 1 TO 5
         PAUSe 1000
         NEXT I 
        ENDIF
     
    'Then check the buttons again
     
     IF (GPIO.3=1) AND (GPIO.4=1) THEN Encode 'Button pressed & released But carry on)
     if (GPIO.3=0) OR  (GPIO.4=0) THEN        'Carry on to ENDIF & Tx DATA
     
    'Look for ENDIF near the end.  
    'If button are still pressed then it goes to ENCODE
    'If not, go back to MAIN and the INTERRUPT ON CHANGE will be reset
    Encode:
     E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
        PAUSEUS 25       ' Allow RF stage to stabilize   
        ' Only DAT_OUT bits 1 and 2 are used. We add a few 1's in bit
        ' positions 0,3,5,7 to balance out the data packet being sent.
        DAT_OUT = %10101001
        ' Get data on button inputs & invert 0's to 1's
        DAT_OUT.0[1]=~GPIO.3
        DAT_OUT.0[2]=~GPIO.4
        INTCON.0 = 0  ' Clear int on change flag
     
        ' Build checksum of 2 data bytes
        CHK_SUM = (DAT_OUT * 2)
     
    Transmit:
        SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM]   
        PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
     
        ENDIF
        GOTO Main
     
        END
    Dave
    Last edited by LEDave; - 15th May 2011 at 10:46.

  32. #912
    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!

    I started by looking at your first code:

    Code:
    'Then check the buttons again
     IF (GPIO.3=1) AND (GPIO.4=1) THEN
    'Look for ENDIF near the end.  
    'If button are still pressed then it goes to ENCODE
    'If not, go back to MAIN and the INTERRUPT ON CHANGE will be reset
    Encode: 
    E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
    PAUSEUS 25       ' Allow RF stage to stabilize 
        ' Only DAT_OUT bits 1 and 2 are used. We add a few 1's in bit
        ' positions 0,3,5,7 to balance out the data packet being sent.
        DAT_OUT = %10101001
        ' Get data on button inputs & invert 0's to 1's
        DAT_OUT.0[1]=~GPIO.3
        DAT_OUT.0[2]=~GPIO.4
        INTCON.0 = 0  ' Clear int on change flag
     
        ' Build checksum of 2 data bytes
        CHK_SUM = (DAT_OUT * 2)
     
    Transmit:
        SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM]
        PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
        ENDIF
        GOTO Main
    If GPIO.3 and GPIO.4 are both 1, then neither are being pressed when pull-up resistors are used.


    Code:
    'If button are still pressed then it goes to ENCODE
    'If not, go back to MAIN and the INTERRUPT ON CHANGE will be reset
    I read these comments backwards to what the code does.


    Personally, the technique of using 1 for OFF and 0 for ON is extremely confusing; it makes trying to follow your code extremely difficult. I always use pull-down resistors and 0=OFF / 1=ON 'cause that's how binary works as well as power switches.

    EDIT: Unless it's a requirement for Sleep mode to have current ON, and the interruption signals Wake.

    Otherwise, if power consumption is an issue, I'd keep the line OFF, saving power, and only applying a bit of current to Wake.
    Last edited by Demon; - 15th May 2011 at 22:08.

  33. #913
    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 / All

    In Bruce's oringinal code, the rfpic (if no buttons are pressed) goes to SLEEP until a button is pressed then Encodes & Tx's straight away.

    It seemed to me the data Tx is dependant on a button press occuring and staying pressed until the data is Tx'd. If a button is pressed then released the RFEN led flashes but no data is ever sent, hence our delay loop problem, the button is pressed then released by the time the loop has run the button press is history. The the only time data has ever Tx'd is when the button is actually pressed when the code gets to 'Transmit'.

    I added LOW GPIO.4 to simulate a button press (staying pressed) result: The rfpic Tx'd no problem after the delay loop had run.

    We now have a IOC that wakes up from sleep, then runs a delay loop, then Tx's the data. We've cracked it you cry.....hoorah! Well almost, problem is the rfpic locks into Tx mode (GPIO.4 is always low - Button is never released if you like).

    Figure a way of GPIO.4 back to 'normal' and we're there, any thoughts. Bear in mind though that GPIO.4 must be 'low' to make the rfpic Tx.

    Any ideas....?

    Code:
    Transmit:
    LOW GPIO.4
        SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM]
        PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
    Dave

  34. #914
    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 Demon

    I hear what you're saying. By the time this project is finished a lot of changes will have been made to the set-up.

    This is my first excursion into RF, with Tx - Rx programs that Bruce kindly posted up. Right now it's a learning curve for me.

    Dave

  35. #915
    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!

    I think I've sent everyone on a wild Goose chase (sorry).

    Mackrackit's Tx code was working fine all along.

    I now think It's the Rx program that holds the key. The reason I think this is becasue Bruce's Rx program (as I understand it) looks to reset if no data recieved within 65ms of button press ( that's why the data only ever Tx'd with a button actually pressed). Any timing loop throws out the 65ms data arrival, hence no flahing led.

    I commented out a section of the Rx program and although not working perfectly, the Rx led now flashes after the time delay and data is sent.

    What do we think? Am I on to something here?

    Again apologies for the curved ball.

    Dave

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


    Did you find this post helpful? Yes | No

    Default Re: 12f675_fuse_about_to_blow!

    Well thats good to know, Thanks Dave!! So does that me the Tx side is done? Do we get to see the Rx side to chew on for a bit?
    -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!

  37. #917
    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!

    Well thats good to know, Thanks Dave!! So does that me the Tx side is done?
    Hi Bert

    Well no the Tx side still has work to be done. The delay loop problem has / had to be overcome to get the project code to do what I want it to. The GPIO.3 / 4 pins will need to be set as as Demon posted earlier, namely:

    I always use pull-down resistors and 0=OFF / 1=ON 'cause that's how binary works as well as power switches.
    Do we get to see the Rx side to chew on for a bit?
    I'll tidy it up and post it tomorrow. The big thing for me is that Mackrackit agree's I'm on the right track with my thinking regards Rx being the problem not the Tx side.

    Dave
    Last edited by LEDave; - 17th May 2011 at 01:59.

  38. #918
    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!

    Mackrackit's Tx code was working fine all along.
    But the other code (Bruce's) worked when my mod did not appear to ???

    Yup, we need to see both ends.


    But it does sound like you are on to something....
    Dave
    Always wear safety glasses while programming.

  39. #919
    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 15:04.

  40. #920
    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!

    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)

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