RB0 + Internal Pullup + Interrupt


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Sorry, it was stupid of me to forget the pic - it's a PIC16F628A

    And no, I really have no room left for much more on that board, I can probably cram one more resistor in as a pulldown but that's about it.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Freman View Post
    Sorry, it was stupid of me to forget the pic - it's a PIC16F628A

    And no, I really have no room left for much more on that board, I can probably cram one more resistor in as a pulldown but that's about it.
    Datasheet PP36 sec. 5.2 . . . "A single control bit can turn on ALL THE PULLUPS. . . . The weak pull up is automatically turned off when the port pin is configured as an output." I think you are stuck using the resistor unless you can flip the port's use in the software I E. instead of, if high then to if low then. I have a blinky running right now which toggles the tris on a port and as soon as it goes back to input the wpu is on.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    I think I've found another side effect of using internal pullups...

    I always figured if I couldn't get any other method working for this, I'd fallback to serial/uart communications...

    I can't get the UART working

    I'm using a usb>serial chip, but it's no real matter because both pins 7(RB1/RX) and 8(RB2/TX) are always high

    Any ideas how I can get this working?
    Last edited by Freman; - 9th August 2009 at 05:52. Reason: Less information

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Freman View Post
    I think I've found another side effect of using internal pullups...

    I always figured if I couldn't get any other method working for this, I'd fallback to serial/uart communications...

    I can't get the UART working

    I'm using a usb>serial chip, but it's no real matter because both pins 7(RB1/RX) and 8(RB2/TX) are always high

    Any ideas how I can get this working?
    Hi Freeman,
    Gotta see some code. USART Idles high, in normal operation.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Here's the code

    Code:
    @     device pic16F628A, hs_osc, wdt_off, pwrt_on, lvp_off, protect_off, bod_on, cpd_off, pwrt_off, mclr_off
    
    DEFINE OSC 20
    DEFINE PULSIN_MAX 3000
    
    CMCON        = 7
    VRCON        = 0
    
    ALL_DIGITAL
    
    ' Alias our pins           
    BEEP           VAR PORTA.0 ' Buzzer
    RFIN           VAR PORTA.1 ' Remote input
    PROXIMITY_DOWN VAR PORTA.2 ' Proximity sensor for DOWN travel
    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
    
    ' Define some aliases for USART
    OERR           VAR RCSTA.1 ' Over-run bit
    CREN           VAR RCSTA.4 ' Continuous receive enable bit
    RCIF           VAR PIR1.5  ' Received character interrupt flag bit
    
    DEFINE HSER_RCSTA 90h      ' Receive register to receiver enabled
    DEFINE HSER_TXSTA 20h      ' Transmit register to transmitter enabled
    DEFINE HSER_BAUD 9600      ' Set baud rate
    
    ' Set the pin directions
    INPUT RFIN
    INPUT BUTTONA
    INPUT BUTTONB
    
    OUTPUT BEEP
    OUTPUT RELAY1
    OUTPUT RELAY2
    OUTPUT PROXIMITY_DOWN
    
    ' Configure the output pins as low
    LOW BEEP
    LOW RELAY1
    LOW RELAY2
    LOW PROXIMITY_DOWN
    
    ' Turn on weak pull-ups
    OPTION_REG.7 = 0
    ' We want to interrupt on the falling edge  
    OPTION_REG.6 = 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
    serialbyte   VAR BYTE
    
    ' Default state
    STATE = STATE_STOPPED
    
    ON INTERRUPT GOTO sighup
    INTCON = %11010000
    PIE1   = %00100000
    
    ' Reset all the primary RF variables
    TOP:
        ADDRESS = 0 : RAW = 0 : DBYTE = 0
    
    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
    
    DISABLE
    
    subUp:
        IF STATE != STATE_GOING_UP THEN
            HIGH BEEP             ' Start making noise
            LOW RELAY1            ' Make sure the down relay is off (Don't know what happens otherwise, don't want to know!)
            LOW PROXIMITY_DOWN    ' Turn off the down proximity sensor
            PAUSE BEEP_WAIT       ' Wait a bit
            LOW BEEP              ' STFU :)
            IF STATE.3 != 1 THEN PAUSE POST_BEEP_WAIT
            HIGH RELAY2           ' Turn the up relay on
            STATE = STATE_GOING_UP
            PAUSE WAIT_WAIT
        ENDIF
        RETURN
        
    subStop:
        IF STATE.3 != 1 THEN
            HIGH BEEP             ' Start making noise
            LOW RELAY1            ' Turn off the down relay
            LOW PROXIMITY_DOWN    ' Turn off the down proximity sensor
            LOW RELAY2            ' Turn off the up relay
            PAUSE BEEP_WAIT       ' Wait a bit
            STATE = STATE_STOPPED
            LOW BEEP              ' STFU :)
            PAUSE WAIT_WAIT
        ENDIF
        RETURN
    
    subDown:
        IF STATE != STATE_GOING_DOWN THEN
            HIGH BEEP             ' Start making noise
            LOW RELAY2            ' Make sure the up relay is off (Don't know what happens otherwise, don't want to know!)
            PAUSE BEEP_WAIT       ' Wait a bit
            LOW BEEP              ' STFU :)
            IF STATE.3 != 1 THEN PAUSE POST_BEEP_WAIT
            HIGH RELAY1           ' Turn the down relay on
            HIGH PROXIMITY_DOWN     ' Turn on the down proximity sensor
            STATE = STATE_GOING_DOWN
            PAUSE WAIT_WAIT
        ENDIF
        RETURN
    
    sighup:
        X = STATE
        IF INTCON.1 == 1 THEN
            GOSUB subStop
            INTCON.1 = 0
        ENDIF
        WHILE RCIF                                 ' While there are bytes to be read
            serialByte = RCREG                    ' Read a byte
            HSEROUT [1, serialByte] ' Tell the sender what byte was received
            IF serialByte = 117 THEN GOSUB subUp
            IF serialByte = 100 THEN GOSUB subDown
        WEND
        IF OERR = 1 THEN
            CREN = 0
            CREN = 1
        ENDIF
        RESUME
        
    ENABLE

    Specifically of interest I guess is this bit - the fiddling with buttons bit
    Code:
        ' 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!

    And here is the basic schematic.




    I'm looking for any solution, hardware or software - I can't change the bit in the unchangeable box, that's the existing pcb that I'm upgrading...
    Last edited by Freman; - 9th August 2009 at 05:59.

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


    Did you find this post helpful? Yes | No

    Default

    I do not see the TX or RX connected to anything??

    But... using http://www.picbasic.co.uk/forum/show...24&postcount=4
    PIC MULTICALC the setting should be
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 129 ' 9600 Baud @ 20MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    No, in that schematic they're not connected to anything - but in reality they're hooked up to tx and rx of a usb-serial adapter. The schematic I posted was more to illustrate the reason behind the pullups being turned on.

    The serial values I'm using are ones I've used in another project that's working... but I'll give yours a try.

    Edit.

    Nope, no change...

    I have noticed tho that when I send data over the usb/serial cable that the voltage does in deed dip (drops from 4.95 to 4.60v) which indicates that the signal is being transmitted (my multimeter isn't fast enough to measure the full weight of the dip)

    I've also done some testing on the usb/serial cable and have found it goes to 3v when high (again probably more, my multimeter can't keep up)
    Last edited by Freman; - 9th August 2009 at 08:01.

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  2. RB0 interrupt problems
    By amindzo in forum General
    Replies: 1
    Last Post: - 26th August 2006, 11:52
  3. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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