new user with problem using PGP Pro, Lab-X3 with 16F628A


Closed Thread
Results 1 to 4 of 4
  1. #1
    equipoise's Avatar
    equipoise Guest

    Question new user with problem using PGP Pro, Lab-X3 with 16F628A

    Hi,

    My first time here, new PIC user, and with a few questions. I've begun using PGP PRo with a Lab-X3 board that includes the 16F628A. This board has several buttons (SW1 uses RB7 and SW2 uses !MCLR through a 100 ohm resistor), 2 onboard LEDs (LED1 uses RB4 and LED2 uses RB5), and 1 pot (on RB0).

    Here's what I'm trying to do: I've attached 2 external LEDs (call them LEDX1 and LEDX2) using the bases of 2 NPN transistors attached to RB1 and RB2, respectively. A simple program to flash LEDX1 and LEDX2 works fine, and I've been able to calibrate and use the pot in a simple pgm. I've also used example pgms to use SW1 and SW2 to control the onboard LEDs.

    I've been trying to write and run a pgm that monitors the pot and SW1. The main loop alternately flashes LEDX1 and LEDX2, while monitoring SW1 to see if it has been pressed. If it has, the program should then look at the pot, and use the value of the pot to change the fraction of time that LEDX1 and LEDX2 will be on. Then the program goes back to the main loop and flashes LEDX1 and LEDX2 using this updated value. I'd like to do it this way, rather than just including the pot reading in the loop, because the pot reading seems to slow the flash rate.

    This hasn't yet worked. I seem to be having problems understanding the interactions of OPTION_REG.7 (RBPU bit) and the reading of SW1. From looking at some example source, I have seen that I need to use OPTION_REG.7=1 to query the pot, and OPTION_REG.7=0 to query SW1. I've tried a bunch of different ways to do this, but the result has generally been that I end up going through the pot reading routine each time I go through the main loop. Also, I've tried modifying the status of TRISB at various points in the pgm in the hope that this would override the effect of the pullup resistors on PORTB. No success here.

    So, it seems, I'm foggy on the basic picture here. Can anyone give me a clue? I'd be happy to furnish source code or schematics, but am unsure of forum etiquette on this.

    One other thing: Bruce Reynolds at Reynolds Electronics explained how to set up the compiler to enable/disable the reset capability of !MCLR, using an "@ DEVICE MCLR_OFF" statement in my pgm, for which I am grateful. I hadn't seen any mention of this kind of thing in the PBP Pro manual, nor in Chuck Heelybuyck's "Programming PIC Microcontrollers with PicBasic", and wonder if there is any good literature alerting to me to these kinds of considerations. WHile I have the 16F628A data sheet, I'm not sure I would (or could) discern all of the options it may discuss by reading it more carefully than I have. Any pointers for the naive new user?

    Thanks.

    Bill Christens-Barry

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Barry,

    Barry>>So, it seems, I'm foggy on the basic picture here. Can anyone give me a clue? I'd be happy to furnish source code or schematics, but am unsure of forum etiquette on this.<<

    I do not know what your source code is like, but if you furnish it, folks can look at it.

    Can you scope anything?

    Can you be *sure* the switch is being recognized as being pressed?

    Is the value of your Pot a big enough difference for you to *SEE* the time difference in the blinking lights?

    Try turning on BOTH LED's for 2 seconds in the area that the switch is pressed. That way you can see both LED's stay on, and verify your program actually went into the "Switch" routine.

    Try leaving one LED on and just blinking the other, to determine that the "POT" routine was entered.

    These are ways to verify your program is acting like it is supposed to. If they don't... you have to find the problem *why* it is not entering the "Switch Routine" and/or Why it is not entering the "POT read" routine.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    >> I seem to be having problems understanding the interactions >> of OPTION_REG.7 (RBPU bit) and the reading of SW1.

    OPTION_REG.7 turns ON or OFF the PortB internal pull-ups.

    On the Lab-X3 board, when SW1 is pressed, it will ground RB7. If you don't have the internal pull-ups turned ON, then you have what's called a floating input on RB7 (or any other portb pin set to an input).

    With the internal pull-ups ON (OPTION_REG.7=0), you have internal pull-up resistors from Vcc to all portb pins (that are set to inputs).

    RB7 sees Vcc through the internal pull-up resistor when SW1 is not being pressed, and ground when SW1 is pressed. This is why you want OPTION_REG.7=0 if you're using RB7 on the LAB-X3 as an input. So RB7 does not "float" when SW1 is not being pressed.

    If you had an external pull-up from Vcc to RB7, then of course you wouldn't need to turn on internal pull-ups.

    Portb pins that are set to outputs are not affected by OPTION_REG.7=0. Only portb pins that are set as inputs will see the internal pull-ups.

    Example;

    TRISB = %00110011
    OPTION_REG.7=0

    Only RB0, RB1, RB4 and RB5 will see Vcc through the internal pull-ups since these are the only pins on portb set to inputs by the TRISB direction control register.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    There are a few FAQ's here that you could also see...

    Presetting Configuration Fuses (PIC Defines) into your Program

    this covers the use of "@ DEVICE MCLR_OFF" statement and similar. The various device options are found in the "Special Features of the CPU" section of the device Datasheet and not in the PBP manual as such, since these are device specific functions and not Basic compiler commands.

    The other FAQ is...

    I'm getting strange Results using POT or RCTIME on PortB (or GPIO Port)

    The weak pull-up's are again a function of the device. Take a look at the OPTION REGISTER in the device Datasheet (somewhere in section 4 from memory - not having the device Datasheet with me). You need pull-up's enabled to drive a PIC's pin high (by default). This then can be taken low if you press a switch which is connected between that pin and ground (Vss 0v). It saves on additional Resistors. The Pull-Up's are only on PortB, but if you have a POT connected to a pin on that Port, depending on how it is connected, can throw the results dramatically - so it is usual to switch the Pull-Up's OFF (OPTION_REG.7=1) to play with the POT, and back ON again (OPTION_REG.7=0) when playing with the Switches.

    As for your code not working, if you post it here, folks can take a look at it and comment accordingly.

    Melanie

Similar Threads

  1. 16F628A fuse problem
    By AndrewC in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th July 2008, 07:51
  2. Problem on writing EEPROM in Winpic800 with picbasic pro
    By selimkara in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th May 2007, 16:33
  3. PicBasic Pro Math Problem??
    By Glen65 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th March 2006, 04:36
  4. Math problem...with picbasic pro
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2005, 19:28
  5. New user with PAUSE command problem
    By Howy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th August 2004, 01:54

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