Replacing existing pic


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    May 2008
    Posts
    46

    Default Replacing existing pic

    G'day there.

    I'm sure what I have is a very simple problem, but I'm having a bit of trouble working out the back side to it.

    Back story - I'm upgrading my home theater (if it can be called that) to be operated from a single remote through my media PC. I've already gotten most of the other stuff working (with help from here with the comparator stuff I was having problems with before)

    I've pulled apart the receiver/controller for my motorized projection screen. Imagin my delight to see it's driven by a PIC chip - unfortunatly the chip that's existing has code protect so I can't just reverse engineer the chip and add my new feature (a 1 wire serial port). I'm forced to try and replicate the code.

    I've got a fair understanding of most of it, but the input buttons have me lost.

    Attached is a very very basic overview of the circuit that my new pic has to slot into.

    How on earth can I tell what button is pushed?

    Things I know.

    Pin 6 to Pin 7 is 4.7v (it varies a little), pin 6 to gnd is 0.2v (it also varies a little) Pin 7 to gnd is 5v

    Can you think of any way they might have been reading the 3 buttons in the original circuit?

    Ideally I'd love keep the original RF remote working as well, but as I have no idea what signals it's using (And don't have a scope) I don't know how I can do that
    Attached Images Attached Images  

  2. #2


    Did you find this post helpful? Yes | No

    Default

    If a pin varies a little, it may be changing state faster than the device you are trying to measure it with. I would think the code is doing something with the weak pull-ups on the pins. Fiddling with the weak pull-ups would allow the chip to scan the buttons, and the code may even use the ADC to read pin levels.
    Tim Barr

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


    Did you find this post helpful? Yes | No

    Default

    Sure enough they use internal pull-ups. Make sure you disable the ADCs and comparators before.

    Now how to know which push button.. Are you sure of the current schematic? Any way it miss some resistors and/or diode in that?
    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

    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

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

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

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