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

    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

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

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

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

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

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

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


    Did you find this post helpful? Yes | No

    Default

    As you're using the Timeout, the serial pin must Idle at the right level. Not a bad idea to leave this resistor.

    http://www.picbasic.co.uk/forum/show...86&postcount=5
    Steve

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

  8. #8
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Well, all in all it works - most of the time.... well half of the time

    The PCCLD pic is a PIC16F628A running at 20 Mhz
    The Master pic is a PIC16F675 running on internal clock at 4Mhz

    I'm pretty sure my programmer has fried the CALIB so DEFINE OSCCAL_1K 1 breaks the serial function.

    The ONLY baud of those I've tried (1200, 2400 and 9600) that works (somewhat randomly) is 9600 - none of the others work.

    Not sure if that's more a function of the PCCLD pic or the Master pic

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 : 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