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!

    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

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

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

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

  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!

    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.

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

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

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

  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!

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

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

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