LABX-USB using port B problems


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Default LABX-USB using port B problems

    Hi,

    I am having trouble using port B on the ME Labs LABX USB proto board.

    I have connected a rotary encoder to port B3, 4, & 5. 4 is the common, set high to give me a supply, 3, & 5 the signals.
    I want to detect the signals on 3, & 5. I have also set B0 to an input so that when I push on the encoder SW1 is pressed. I am getting very strange results.
    Code:
    Define OSC 48               'PIC18F4550
    adcon1 = %00001111      'All digital
    INTCON2.7 = 1        ' disable PORTB pull-ups
    trisb = 0                ' portb all outputs
    portb = 0               'all low
    @ clrf UTRDIS
    @ clrf UPUEN
    led1        var portd.0
    sw1         var portb.0
    encsupply   var portb.4
    encup       var portb.3
    encdn       var portb.5
    
    high encsupply 
    input encup
    input encdn
    input led1
    
    start: 
    if sw1 = 0 then low led1
    if sw1 = 1 then high led1
    goto start
    End
    When I push the switch the led will light, but it will not go off unless I press button 2, 3, or 4. Also if I turn the encoder the led lights a little each detent, and even stranger if I have my fingers near to the switches or LED 1 I can vary the brightness of the LED, until it seems to go hard on, and once again can only be extinguished by pressing one of the 3 switches.

    Can anyone help?

    Regards
    Bob...

  2. #2
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: LABX-USB using port B problems

    The line input led1 is actually input sw1

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: LABX-USB using port B problems

    Is SW1 the SW1 on the LAB-XUSB board? (the matrix keypad)

    If so, then you need to turn ON the internal pull-ups on PORTB.
    And PORTB.4 is the input. Set PORTB.0 LOW.

    See the keypad pinouts in the LAB-XUSB schematic ... http://melabs.com/downloads/LABXUSCH_06.PDF
    DT

  4. #4
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: LABX-USB using port B problems

    Hi Darrel,

    Yes it is that switch. The idea was to have pull-ups off, use portb.4 as the supply, b3, & b5 as the encoder inputs, with the 100k weak pull-down resistors, and sw1 as the input when I push on the encoder shaft. I can't see why this does not work with the pull ups off.

    Oh well, back to the drawing board. Thanks.

    Bob.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: LABX-USB using port B problems

    RB0 doesn't have a 100k pull-down resistor, only RB3 and RB5 do.
    DT

  6. #6
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: LABX-USB using port B problems

    Maybe I need to add a pull down to B0 too, though I still cant explain the strange results I was getting.
    Anyway thank you for your help, I'll have another go at the weekend.
    Hope I can get it to work, I love how fitting an encoder to the board made it an encoder with push button switch underneath, so just pushing the knob gives me an encoder with a switch, totally by accident, not design.

    Amazing, & puzzling how I can write a USB interface, write the visual basic program to connect the hardware to flight simulator, and then I cant even get a switch to work.

    By the way much kudos, & many thanks for your interrupt routines, they made a project at work really easy for me.

    Kind regards
    Bob...

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