Replacing existing pic


Closed Thread
Results 1 to 30 of 30

Hybrid View

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

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

  3. #3
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Gone completely back to the idea of replacing the pic.

    I think I'll be best served by hooking up my soundcard scope and seeing if it is indeed scanning the input buttons.

  4. #4
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Thumbs up

    Ok guys, I've replicated the functionality of the original 8 pin chip, here's the code - any thoughts?

    This is why there's pin fiddling on BUTTONA and BUTTONB
    Attachment 2617

    Thanks some more

    Code:
    ' Configure the FUSE options for the compiler
    @     device pic16F628A, hs_osc, wdt_off, pwrt_on, lvp_off, protect_off, bod_on, cpd_off, pwrt_off, mclr_off
    
    ' Running a 20Mhz clock
    DEFINE OSC 20
    DEFINE PULSIN_MAX 3000
    
    CMCON        = 7
    VRCON        = 0
    
    ALL_DIGITAL
    
    ' Setup the USART
    DEFINE HSER_RCSTA 90h      ' Receive register to receiver enabled
    DEFINE HSER_TXSTA 20h      ' Transmit register to transmitter enabled
    DEFINE HSER_BAUD 19200     ' Set baud rate
    
    ' Alias our pins           
    BEEP VAR PORTA.0           ' Buzzer
    RFIN VAR PORTA.1           ' Remote input
    RELAY1 VAR PORTB.4         ' Relay 1 output
    RELAY2 VAR PORTB.5         ' Relay 2 output
    BUTTONA VAR PORTB.6        ' Primary panel button input
    BUTTONB VAR PORTB.7        ' Secondary panel button input
    
    ' Set the pin directions
    INPUT RFIN
    INPUT BUTTONA
    INPUT BUTTONB
    
    OUTPUT BEEP
    OUTPUT RELAY1
    OUTPUT RELAY2
    
    ' Configure the output pins as low
    LOW BEEP
    LOW RELAY1
    LOW RELAY2
    
    ' Turn on weak pull-ups - IMPORTANT: After making relays and beepers low...
    OPTION_REG.7 = 0 
    
    ' Set us up some variables
    PBITS       VAR BYTE[24]   ' The bits we've read
    RAW         VAR WORD       ' The raw pulsin value
    ADDRESS     VAR WORD       ' Storage for the address
    DBYTE       VAR BYTE       ' Storage for the data
    LOOPADDRESS VAR WORD       ' Second loop storage of first loop addres
    LOOPDBYTE   VAR BYTE       ' Second loop storage of first loop data byte
    X           VAR BYTE       ' Loop/TMP var
    Y           VAR BYTE       ' Loop/TMP var
    STATE       VAR BYTE       ' Current state of the device
    
    ' Constants
    STATE_STOPPED    CON 0     ' Screen is stopped
    STATE_GOING_UP   CON 1     ' Screen is going up
    STATE_GOING_DOWN CON 2     ' Screen is going down
    
    ' Default state
    STATE = STATE_STOPPED
    
    ' Reset all the primary RF variables
    TOP:
        ADDRESS = 0 : RAW = 0 : DBYTE = 0
        
    ' This is the real main - almost all the looping comes back here
    MAIN:
        ' Set both buttons for input
        INPUT BUTTONA
        INPUT BUTTONB
        ' Check to see if the individual buttons are toggled
        IF NOT BUTTONA THEN GOSUB subDown
        IF NOT BUTTONB Then GOSUB subUp
        ' Fiddle with the inputs to see if the middle button is pushed
        LOW BUTTONB
        X = BUTTONA ' If it's LOW then there's a good chance the middle button is down
        HIGH BUTTONB
        INPUT BUTTONB
        LOW BUTTONA  
        Y = BUTTONB ' If it's LOW then there's a good chance the middle button is down
        HIGH BUTTONA
        INPUT BUTTONB
        INPUT BUTTONA
        IF NOT Y AND NOT X THEN GOSUB subStop ' Both register as LOW then the middle button is down!
        
        ' Look for one huge low pulse
        PULSIN RFIN, 0, RAW
        ' 2350 is about mean average
        IF RAW < 2340 OR RAW > 2360 THEN MAIN
    
        ' Read 16 address bits and 8 data bits    
        FOR X = 0 TO 23
            PULSIN RFIN, 0, RAW
            ' Check the pulse parameters
            IF RAW < 30 OR RAW > 240 THEN MAIN
            PBITS[x] = NCD RAW
        NEXT X
        
        ' Gather the address
        ADDRESS = 65535 ' Maxmimum known ID
        FOR X = 0 to 15
            IF PBITS[x] > 7 THEN ADDRESS.0[X] = 0
        NEXT X
        
        ' Gather the data
        DBYTE = 255 ' Maximum known data value
        Y=0
        FOR X = 16 TO 23
            IF PBITS[X] > 7 THEN DBYTE.0[Y] = 0
            Y = Y + 1
        NEXT X
    
        ' If we've done a loop...
        IF ADDRESS == LOOPADDRESS AND DBYTE == LOOPDBYTE THEN
            SELECT CASE DBYTE
                CASE 3
                    GOSUB subUp
                CASE 12
                    GOSUB subStop
                CASE 192
                    GOSUB subDown
            END SELECT
            LOOPDBYTE = 0
            LOOPADDRESS = 0
        ELSE
            ' Start a loop
            LOOPDBYTE = DBYTE
            LOOPADDRESS = ADDRESS
        ENDIF
    
        GOTO TOP
    END
    
    subUp:
        IF STATE != STATE_GOING_UP THEN
            HIGH BEEP             ' Start making noise
            HSEROUT ["UP",10,13]  ' DEBUG
            LOW RELAY1            ' Make sure the down relay is off (Don't know what happens otherwise, don't want to know!)
            PAUSEUS 65355         ' Wait a bit
            HIGH RELAY2           ' Turn the up relay on
            LOW BEEP              ' STFU :)
            STATE = STATE_GOING_UP
        ENDIF
        RETURN
        
    subStop:
        IF STATE != STATE_STOPPED THEN
            HIGH BEEP             ' Start making noise
            HSEROUT ["STOP", 10, 13] ' DEBUG
            LOW RELAY1            ' Turn off the down relay
            LOW RELAY2            ' Turn off the up relay
            PAUSEUS 65355         ' Wait a bit
            LOW BEEP              ' STFU :)
            STATE = STATE_STOPPED
        ENDIF
        RETURN
    
    subDown:
        IF STATE != STATE_GOING_DOWN THEN
            HIGH BEEP             ' Start making noise
            HSEROUT ["DOWN",10,13] ' DEBUG
            LOW RELAY2            ' Make sure the up relay is off (Don't know what happens otherwise, don't want to know!)
            PAUSEUS 65355         ' Wait a bit
            HIGH RELAY1           ' Turn the down relay on
            LOW BEEP              ' STFU :)
            STATE = STATE_GOING_DOWN
        ENDIF
        RETURN

  5. #5
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    He guys.

    Is there any way (other then DarrelTaylor's elapsed timer) to work out how many seconds have passed?

    Darrel's method K/O's my pulsin code.

    I was looking to time the descent of the screen and stop it at 44 seconds - which is the right height for viewing.

    My fall back method is a reed switch - but that'll mean that there's an ugly reed switch visible to the naked eye when the screen is up.

    For the record the screen takes 49 seconds to fully descend but that leaves it about a foot too long.

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


    Did you find this post helpful? Yes | No

    Default

    Search the forum for Mel's Olympic Timer and RTC. The might do the trick.

    Paul has one also.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

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