PIC to recognise button press when 2.5V seen at input pin? (ie neither high nor low)


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default PIC to recognise button press when 2.5V seen at input pin? (ie neither high nor low)

    Hi Guys,

    Now I know that for trapping a button being pressed ...the normal condition is to present either a 1 (5V) or a 0 (0V) at an input pin.

    However, is it possible to have a PIC trap a button being pressed with a voltage somewhere in between?

    Is it possible to present say 2.5V at a PIC input pin & have button press code along the lines of "if input pin x isn't high then goto"

    This is just curiosity really - can it be done? (it just so happens I run a lot of virtual ground circuits where there's 2.5V presented all over the place...so it might be useful!

    PS I'm having a torrid time getting PIN 4 on a 12F683 to work as an digital output pin - this just so happens to be the MCLR pin - any top tips what might be my problem? if I use the same code but with a different pin in it's place it all works - so it's somethint unique to that pin 4 - I've tried the MCLRE_OFF in my config - it's driving me potty...

    Code:
    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF  
    @MyConfig = MyConfig & _MCLRE_OFF
    
    DEFINE OSC 4           ' Internal 4MHz
    DEFINE ADC_BITS 10      ' 10-bit resolution
    DEFINE ADC_CLOCK 2     ' Set clock source to Frc/32
    DEFINE ADC_SAMPLEUS 50 ' Sample time in uS before A/D conversion is started
    
    DEFINE DEBUG_REG GPIO     ' Define DEBUG port
    DEFINE DEBUG_BIT 0         ' Set GPIO.0 as DEBUG serial output pin
    DEFINE DEBUG_BAUD 9600   ' DEBUG baud rate = 9600 bps
    DEFINE DEBUG_MODE 0       ' 1 = inverted, 0 = true
    
    CMCON0 = 7   		'Comparators off
    ANSEL = %00001000		'AN3  'Signal In' GPIO.4 (pin 3)
    INTCON = 0		'INTERRUPTS off
    TRISIO = %11110011		'All Inputs except  GPIO.2 (Pin 5) &  GPIO.3 (Pin 4 )
    VRCON = %00000000                 'VREF Off
    What am I missing?

    tks!
    Last edited by HankMcSpank; - 10th May 2010 at 12:59.

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


    Did you find this post helpful? Yes | No

    Default

    Certainly it WILL work if you feed a Comparator...

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


    Did you find this post helpful? Yes | No

    Default

    PS I'm having a torrid time getting PIN 4 on a 12F683 to work as an digital output pin - this just so happens to be the MCLR pin - any top tips what might be my problem? if I use the same code but with a different pin in it's place it all works - so it's somethint unique to that pin 4 - I've tried the MCLRE_OFF in my config - it's driving me potty...
    MCLR pins are INPUTS only when set to off.
    From the data sheet.
    4.2.5.4 GP3/MCLR/VPP
    Figure 4-4 shows the diagram for this pin. The GP3 pin
    is configurable to function as one of the following:
    • a general purpose input
    • as Master Clear Reset with weak pull-up
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    MCLR pins are INPUTS only when set to off.
    From the data sheet.
    Many thanks ...useful things datasheets eh?! (but a bit scarey for n00bs!)

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


    Did you find this post helpful? Yes | No

    Default

    Just keep the data sheets in the bathroom and read them there...
    Somehow they are not so ... intimidating then.Name:  pen_mac.jpeg
Views: 474
Size:  1.9 KB
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default 2V5 input with digital I/O pins

    2V5 is in the analog world so if you have a spare comparator or ADC pin on your PIC then use it.

    If you do not have a spare analog pin, then RCTIME and POT commands can be used.

    Setup your PIC with a fixed resistor and capacitor for RCTIME or POT on an available digital I/O pin. Connect the 2V5 source to the same pin through, say, a 10K resistor. There will be large changes in the value returned by the RCTIME or POT command when the 2V5 source is present/not present.

    HTH
    BrianT

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