Replacing existing pic


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    I'm positive there's no missed resistors or diodes in relation to the push buttons - as much as it's a very abbreviated schematic, the circuit really doesn't have much more - I can upload some scans of the board if you like, but I've actually decided to approach this a different way.

    Originally I was going to sacrafice the remote control function to gain a serial interface, but what I've since decided to do is take the two outputs from the original pic and feed it into another pic - this will give me my serial interface and keep the remote control - without having to deal

    Now I have a problem with frightfully slow interrupts - I've tested this in PIC Simulator and it works reasonably quickly there. In real life tho, this code interrupts 'eventually' usually 5-20 seconds later. I can't see why, I'm only tying it up for 10 ms then I've inserted an extra pauseus so it's got something to interrupt before/after before returning to serin.

    Anyway I can speed up the interrupt to... between 11 and 100 ms?

    Code:
    ' Configure the pic
    @     device pic12F675, INTRC_OSC_NOCLKOUT, WDT_ON, PWRT_ON, MCLR_OFF, BOD_ON, CPD_OFF, PROTECT_OFF
    
    N9600   CON     6
    
    CMCON        = 7
    ANSEL        = 0
    
    Relay1       VAR GPIO.5
    Relay2       VAR GPIO.4
    
    SlavePower   VAR GPIO.2
    SlaveRelay1  VAR GPIO.0
    SlaveRelay2  VAR GPIO.1
    
    Serial       VAR GPIO.3
    
    B0           var BYTE
    
    INPUT SlaveRelay1
    INPUT SlaveRelay2
    INPUT Serial
    
    OUTPUT Relay1
    OUTPUT Relay2
    OUTPUT SlavePower
    
    ON INTERRUPT GOTO slaveSpeaks
    IOC            = %00000011
    INTCON       = %10001000
    
    ' Turn on the original PIC
    HIGH SlavePower
    
    main:
        B0 = 0
        PAUSEUS 1
    
        SERIN Serial, N9600, 10, main, [1], B0
    
        ' The original PIC latches it's output, we want to reboot the original pic if we get something from the serial port to force it's outputs low
        IF B0 > 1 THEN LOW SlavePower
        if B0 = 2 THEN GOSUB subUp
        IF B0 = 3 THEN GOSUB subDown
        IF B0 = 4 THEN GOSUB subStop
        IF B0 > 1 THEN
            PAUSEUS 1000
            HIGH SlavePower
        ENDIF
    GOTO main
    
    DISABLE
    subUp:
        LOW Relay2
        HIGH Relay1
        RETURN
    subDown:
        LOW RELAY1
        HIGH Relay2
        RETURN
    subStop:
        LOW Relay1
        LOW Relay2
        RETURN
    
    slaveSpeaks:
        if SlaveRelay1 THEN
            GOSUB subUp
        ELSE
            IF SlaveRelay2 THEN
                GOSUB subDown
            ELSE
                GOSUB subStop
            ENDIF
        ENDIF
        INTCON = %10001000
        RESUME
    ENABLE

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I would probably skip the interrupt and perform everything in a tight loop instead. As the Relay check is done pretty quick. Not a fan of using GOSUBs in a ISR.

    From what i feel, S2 should have dual contacts attach to GPIO<1:0>

    To know which relay is activated, i would bet that...
    Code:
    WhichRelay VAR BYTE
    '
    '
    '
    '
    WhichRelay=GPIO & 3
    Select case WhichRelay
        CASE 0 ' Relay 2
          ' do stuff for relay 2
    
        CASE 1 ' Relay 1
          ' do stuff for relay 1
     
        CASE 2 ' Relay 3
          ' do stuff for relay 3
         END SELECT
    If you still want to use Ints, don't re-enable the GIE bit, the PIC will do it for you. Just clear the offending INT flag and get out of there.

    If you play with GIE bit, you will run into problems, that's for sure.
    Last edited by mister_e; - 27th May 2008 at 16:34.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Heh, never even thought about SELECT CASE

    So something more like this then.

    Code:
    ' Configure the pic
    @     device pic12F675, INTRC_OSC_NOCLKOUT, WDT_ON, PWRT_ON, MCLR_OFF, BOD_ON, CPD_OFF, PROTECT_OFF
    
    N9600   con     6
    
    CMCON        = 7
    ANSEL        = 0
    
    Relay1       VAR GPIO.5
    Relay2       VAR GPIO.4
    
    SlavePower   VAR GPIO.2
    SlaveRelay1  VAR GPIO.0
    SlaveRelay2  VAR GPIO.1
    
    Serial       VAR GPIO.3
    
    B0           var BYTE
    SlaveState   VAR BYTE
    WhichRelay   VAR BYTE
    
    INPUT SlaveRelay1
    INPUT SlaveRelay2
    INPUT Serial
    
    OUTPUT Relay1
    OUTPUT Relay2
    OUTPUT SlavePower
    
    restart:
    SlaveState = 0
    PAUSEUS 1000
    HIGH SlavePower
    
    main:
        B0 = 0
        pauseus 1
        SERIN Serial, N9600, 10, main, [1], B0
        IF B0 > 1 THEN LOW SlavePower
        if B0 == 2 THEN GOSUB subUp
        IF B0 == 3 THEN GOSUB subDown
        IF B0 == 4 THEN GOSUB subStop
        IF B0 > 1 THEN GOTO restart
        
        WhichRelay = GPIO & 3
        IF SlaveState <> WhichRelay THEN
            SlaveState = WhichRelay
            SELECT CASE WhichRelay
                CASE 0
                    GOSUB subStop
                CASE 1
                    GOSUB SubUp
                Case 2
                    GOSUB subDown
            END SELECT
        ENDIF   
    goto main
    
    subUp:
        LOW Relay2
        HIGH Relay1
        RETURN 
    subDown:
        LOW RELAY1
        HIGH Relay2
        RETURN
    subStop:
        LOW Relay1
        LOW Relay2
        RETURN

  4. #4
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Oh I feel like such an idiot - Note to self, double check the label in 'serin' if you change your code substantially...

    Code:
    ' Configure the pic
    @     device pic12F675, INTRC_OSC_NOCLKOUT, WDT_ON, PWRT_ON, MCLR_OFF, BOD_ON, CPD_OFF, PROTECT_OFF
    
    N9600   con     6
    
    CMCON        = 7
    ANSEL        = 0
    
    Relay1       VAR GPIO.5
    Relay2       VAR GPIO.4
    
    SlavePower   VAR GPIO.2
    SlaveRelay1  VAR GPIO.0
    SlaveRelay2  VAR GPIO.1
    
    Serial       VAR GPIO.3
    
    B0           var BYTE
    SlaveState   VAR BYTE
    WhichRelay   VAR BYTE
    
    INPUT SlaveRelay1
    INPUT SlaveRelay2
    INPUT Serial
    
    OUTPUT Relay1
    OUTPUT Relay2
    OUTPUT SlavePower
    
    restart:
    SlaveState = 0
    PAUSEUS 1000
    HIGH SlavePower
    
    main:
        B0 = 0
        SERIN Serial, N9600, 15, testSlave, [1], B0
        LOW SlavePower
        SELECT CASE B0
            CASE 2
                GOSUB subUp
            CASE 3
                GOSUB subDown
            CASE 4
                GOSUB subStop
        END SELECT
        GOTO restart
    
    testSlave:    
        WhichRelay = GPIO & 3
        IF SlaveState <> WhichRelay THEN
            SlaveState = WhichRelay
            SELECT CASE WhichRelay
                CASE 0
                    GOSUB subStop
                CASE 1
                    GOSUB SubUp
                Case 2
                    GOSUB subDown
            END SELECT
        ENDIF   
    goto main
    
    subUp:
        LOW Relay2
        HIGH Relay1
        RETURN 
    subDown:
        LOW RELAY1
        HIGH Relay2
        RETURN
    subStop:
        LOW Relay1
        LOW Relay2
        RETURN

  5. #5
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Nope, that isn't working either.

    It's working in the simulator but not in the real life.

    Should I set up pulldown resistors on the inputs of the new pic from the outputs of the old pic?

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    This should work. The only thing i would suggest you, is to use a slower baudrate, check the manual for that. They suggest higher speed OSC for 9600 bauds.

    Maybe not a bad idea to call the OSCCAL value to make sure you use the factory calibration for the internal OSC.
    Code:
    DEFINE OSCCAL_1K 1
    Your code don't enable the internal pull-up
    Code:
    OPTION_REG.7=0
    Last edited by mister_e; - 27th May 2008 at 17:04.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    I'm not actually using the serial at the moment, I'm just trying to get to the "other" part of the code, but I'll try 2400 bps, I'll also try the osccal

    So you're telling me I should set that bit to 0 in my code?


    Nope still no go This is the code and attached is the schematic

    I know the slave is bringing the pins high (multi-meter and beep confirms it)

    Edit: One clue I have is.... if I comment out the serial routine and tell it to goto the 'testSlave' label, it works fine

    Code:
    ' Configure the pic
    @     device pic12F675, INTRC_OSC_NOCLKOUT, WDT_ON, PWRT_ON, MCLR_OFF, BOD_ON, CPD_OFF, PROTECT_OFF
    
    DEFINE OSCCAL_1K 1
    N2400   con      4
    
    CMCON        = 7
    ANSEL        = 0
    OPTION_REG.7 = 0
    
    Relay1       VAR GPIO.5
    Relay2       VAR GPIO.4
    
    SlavePower   VAR GPIO.2
    SlaveRelay1  VAR GPIO.0
    SlaveRelay2  VAR GPIO.1
    
    Serial       VAR GPIO.3
    
    B0           var BYTE
    SlaveState   VAR BYTE
    WhichRelay   VAR BYTE
    
    INPUT SlaveRelay1
    INPUT SlaveRelay2
    INPUT Serial
    
    OUTPUT Relay1
    OUTPUT Relay2
    OUTPUT SlavePower
    
    LOW Relay1
    LOW Relay2
    
    restart:
    SlaveState = 0
    PAUSEUS 1000
    HIGH SlavePower
    
    main:
        B0 = 0
        SERIN Serial, N2400, 20, testSlave, [1], B0
        LOW SlavePower
        SELECT CASE B0
            CASE 2
                GOSUB subUp
            CASE 3
                GOSUB subDown
            CASE 4
                GOSUB subStop
        END SELECT
        GOTO restart
    
    testSlave:    
        WhichRelay = GPIO & 3
        IF SlaveState <> WhichRelay THEN
            SlaveState = WhichRelay
            SELECT CASE WhichRelay
                CASE 0
                    GOSUB subStop
                CASE 1
                    GOSUB SubUp
                Case 2
                    GOSUB subDown
            END SELECT
        ENDIF   
    goto main
    
    subUp:
        LOW Relay2
        HIGH Relay1
        RETURN 
    subDown:
        LOW RELAY1
        HIGH Relay2
        RETURN
    subStop:
        LOW Relay1
        LOW Relay2
        RETURN
    Attached Images Attached Images  
    Last edited by Freman; - 27th May 2008 at 17:30. Reason: Code and picture

  8. #8
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    SOLVED

    I think

    Throw a 10k resistor from the serial pin to ground. The question now is, should that resistor remain even after I actually hook up the serial signal from the other device?

    [PC - USB > serial] ---> [Main Board (PCCLD)] ---> {1 way serial} ---> [New/Master PIC]

    Should that resistor remain, or can I turf it once I hook up the serial?

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. Replacing Hall Effect throttle with PIC
    By idtat in forum General
    Replies: 4
    Last Post: - 22nd October 2009, 21:55
  3. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  4. Replacing shift register with PIC
    By TonyA in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th April 2008, 18:31
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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