PDA

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



HankMcSpank
- 10th May 2010, 11:51
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...



@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!

Melanie
- 10th May 2010, 12:31
Certainly it WILL work if you feed a Comparator...

mackrackit
- 10th May 2010, 13:31
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

HankMcSpank
- 12th May 2010, 20:34
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!)

mackrackit
- 12th May 2010, 20:43
Just keep the data sheets in the bathroom and read them there...
Somehow they are not so ... intimidating then.4387

BrianT
- 14th May 2010, 03:21
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