View previous topic :: View next topic |
Author |
Message |
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
while ( input(PIN_B0) ) is it a good idea ? Also a ADC ? |
Posted: Tue Oct 23, 2007 8:17 pm |
|
|
Hello,
In case anyone remembers me thanks for your help. I got rs232 to work.
I was wanting to have a sort of "switch" in my program so if i have high or low to a certain pin it would do something it does not normally do. For instance
Code: |
if ( input(PIN_B0) ) {
// do something extra that you were not doing already
} |
Is this a good way of doing things? If it is a good way of doing things should i make the "switch" go to ground or to hot ? if( !input(PIN_B0) ) or
if( input(PIN_B0) ). Ive been experimenting with it a bit and it seems that if i have if( !input(PIN_B0) ) and its not grounded it sometimes executes.
also for a pic 877a and #device adc=8 is this the correct way to convert from the adc number to a float number that represents the voltage? I always get about +.10 more than i should.
Code: |
//declartations (at the top)
int16 adc_value;
float volts;
// a little further down
adc_value = read_adc();
volts = (float)(adc_value * 5)/1023.0; // convert to volts |
Tia |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
![](templates/subSilver/images/spacer.gif) |
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Fri Oct 26, 2007 9:10 pm |
|
|
Quote: | Look at this schematic. He has 1K pullup resistors on RA0-RA2.
Each pin also goes to a switch, and the other side of the switches
go to ground. You don't need to use 1K. I would have used 4.7K
or 10K resistors.
http://www.vermontficks.org/pellets.gif
|
I went off of this code and suggestion. I used a 10K resistor like this
Code: | gnd
|
|
sw------------------
|
+5V------/\/\/\/\-------PicPin C3 |
so the 10K resistor goes from 5v to the pic pin, at this same point there is a wire that goes to a two pin header and on the other side of the two pin header is gnd.
When i read the pin with a volt meter there is like no Voltage. Is the 10K resistor too much ? Isnt it supposed to be high until you hit the switch it goes to ground ? |
|
![](templates/subSilver/images/spacer.gif) |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sat Oct 27, 2007 9:08 am |
|
|
Yes, that should work.
I'm not sure of your meter's ability (Z) to measure the voltage. I would try some tests with code to see if the PIC is detecting the change in voltage w/ the switch press. If that doesn't check good I'd look for shorts/bad connections. |
|
![](templates/subSilver/images/spacer.gif) |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Oct 27, 2007 10:27 am |
|
|
Quote: |
When i read the pin with a volt meter there is like no Voltage. Is the 10K resistor too much ? Isnt it supposed to be high until you hit the switch it goes to ground ?
|
With a 10K resistor connected as you shown, you should read +5V -even with a chinnesse
$10 multimeter- unless such pin was set as an output LOW.
Humberto |
|
![](templates/subSilver/images/spacer.gif) |
|