Please help with configs/defines for PIC12F609


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default Please help with configs/defines for PIC12F609

    I'm having trouble with this project. I'm using a PIC12F609 and a pushbutton to turn a dual latching 2formC relay on and off. An LED comes on when the relay is on. This is being used to route an audio signal. The "mute" part of the code uses a MOSFET to short the signal path to ground so that you cannot hear the relay contacts when it switches.

    Everything functions exactly the way I want it to. The problem I'm having is that after 30 minutes or so of sitting idle, the circuit will spontaneously change from the "on" state to the "off" state, or vice versa. And eventually, the program will lock up after sitting idle for about an hour.

    I guess I'm doing something wrong in the configuration/define, but I can't figure out what I'm doing wrong. Any help would be greatly appreciated.



    Code:
    '****************************************************************'*  Name    : relayswitch2.BAS                                                                       *
    '*  Author  : Keith Vonderhulls                                                                       *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS]                     *
    '*          : All Rights Reserved                                                                         *
    '*  Date    : 9/23/2014                                                                                  *
    '*  Version : 1.0                                                                                            *
    '*  Notes   :                                                                                                  *
    '*          :                                                                                                     *
    '****************************************************************
    
    
    #config
        __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _IOSCFS_4MHZ & _CP_OFF
    #endconfig
    
    
    DEFINE OSCCAL_1k 1
    
    
        ANSEL = 0 ' Set all digital
        CMCON0 = 7 ' Analog comparators off
        CMCON1 = 7 ' Analog comparators off
        TRISIO = %10001000
        
    LATCH0 var GPIO.2       'ON latch coil of relay
    LATCH1 var GPIO.1       'OFF latch coil of relay
    LED var GPIO.4
    MUTE var GPIO.0
    PB Var GPIO.3           ' Alias GPIO.3 to push button
    
    
        
        LED = 0
        MUTE = 0
        LATCH1 = 1              'initiate program with LED, MUTE and relay off
        
        pause 10                'allow 10ms pulse to relay coil to turn off 
        LATCH1 = 0              'end pulse to relay coil to conserve power
        
    
    
    
    
    main:
        
        if PB = 0 then
            MUTE = 1                     'mute while switching occurs
            TOGGLE LED                 'change LED status  
            pause 30                    'mute & debounce
                gosub activaterelay
        
            pause 30                        'allow another 30ms to mute
            MUTE = 0
                gosub switchrelease
            pause 50                        'debounce
        endif
        
    goto main
    End
    
    
    activaterelay:                          'change state of relay base upon state of LED
        
        if LED = 1 then
            LATCH0 = 1
        elseif LED = 0 then
            LATCH1 = 1      
        endif
        
        pause 10                 ' send 10ms pulse to relay coil
        
        if LED = 1 then        '  end pulse to relay coil to conserve power
            LATCH0 = 0
        elseif LED = 0 then
            LATCH1 = 0      
        endif
        
    return
    
    
    
    
    switchrelease:                  'wait for footswitch to be released
        do until PB = 1
            pause 10
        loop
    return

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Please help with configs/defines for PIC12F609

    Name:  12f609scheme.jpg
Views: 236
Size:  394.5 KB

    Here's the schematic for the circuit

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Please help with configs/defines for PIC12F609

    http://www.google.com/url?sa=t&rct=j...75775273,d.cGU

    Here's a link to the PIC12F609 datasheet

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Please help with configs/defines for PIC12F609

    Page 98 (sect. 11.3.6) of the PIC12F609 datasheet discusses TIME-OUT SEQUENCE. I think this may be where I'm having problems, but it's going over my head.

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


    Did you find this post helpful? Yes | No

    Default Re: Please help with configs/defines for PIC12F609

    Add a capacitor or two across VDD and VSS near the PIC (1uF or so)
    And maybe tell us about your power supply.
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Please help with configs/defines for PIC12F609

    Name:  12f609scheme.jpg
Views: 262
Size:  432.9 KB

    Here's an updated schematic. It shows the power supply. I also forgot to include a 0.1uF cap off of GPIO.3 to help with debounce.

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Please help with configs/defines for PIC12F609

    Well I for one would NEVER operate a relay directly from the processor. looking at the data sheet for the relay, It draws 22 ma. Its bad enough for a pin that is sinking but it looks as if you are also sourcing the current to the coil. Use a transistor to switch the coil and you also get an extra pin to use. Also, I see NO diode to prevent backemf form the relay.
    Dave Purola,
    N8NTA
    EN82fn

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Please help with configs/defines for PIC12F609

    Quote Originally Posted by Dave View Post
    Well I for one would NEVER operate a relay directly from the processor. looking at the data sheet for the relay, It draws 22 ma. Its bad enough for a pin that is sinking but it looks as if you are also sourcing the current to the coil. Use a transistor to switch the coil and you also get an extra pin to use. Also, I see NO diode to prevent backemf form the relay.
    Thanks, Dave. I actually am using a 2N3904 to supply the power to the coils. the MCU connects to the base of each transistor. The collector of each transistor connects to VDD. And the emitter of each transistor connects to its respective coil. I don't know why I didn't draw them on the schematic. I guess I didn't think that part was relevant to my specific problem.

    Anyhow!

    I resolved the issue. It was a hardware/physical design problem. The .1uF capacitor off of GPIO.3 was causing the problem. I added it to help make the switch less bouncy, but this isn't a good idea when using the MCLR pin when MCLR is turned off. I removed that capacitor and everything works perfectly now.

Similar Threads

  1. Replies: 4
    Last Post: - 7th March 2014, 01:07
  2. 18F6310 configs
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th January 2012, 06:47
  3. 18F4520 Configs
    By ruijc in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th June 2010, 22:18
  4. Internal osc config PIC12F609
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd April 2008, 16:23
  5. Getting Configs straight
    By vacpress in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 24th January 2007, 04:16

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