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

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

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

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

  5. #5
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    I'm about ready to give up on serial ports

    It shouldn't work at 9600 yet it does randomly...

    It should work at 2400 but it doesn't at all
    Last edited by Freman; - 28th May 2008 at 11:18.

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


    Did you find this post helpful? Yes | No

    Default

    IF the DEFINE OSCCAL break the serial comm and almost everything, it's a good sign your device programmer screwed the internal calibration, that's for sure. If you have a PICKIT2, you can recover it in few seconds with the OSCCAL Auto regenerate utility.

    Acetronics also posted something here.

    Lost your OSCCAL Value ???
    http://www.picbasic.co.uk/forum/showthread.php?t=7588&

    One thing is sure, you're using a BitBanging Serial communication, you may miss some bytes here and there. Using a Hardware USART provide a 2 bytes buffer and Interrupt capability... which are handy.

    For a simple test, remove the relay check and keep only the serial part, without timeout. See if it works better.
    Last edited by mister_e; - 28th May 2008 at 14:32.
    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

    Given up, moving up to the pic16f628a - Means I can do more as well.
    Another consideration I had was using maxim one wire components to free up 4 of the pins, I could have put a crystal on it then.

    Still can't really use the hardware uart on the pic16f628a because the pic it's talking to is already using it's hardware uart.

    I'll keep a note on that recovery source, that will come in useful

    But here's my new schematic - http://users.on.net/freman/images/el...ceiverplus.png

    I used the interrupt pin for serial communication, so I could interrupt by sending it high, then send bytes
    The other option is to use the hardware uart but it'd be connected to software serial at the other end...

    I'm not set on that yet, this one's still on the breadboard.
    Last edited by Freman; - 28th May 2008 at 15:31. Reason: Linking :)

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