CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

while ( input(PIN_B0) ) is it a good idea ? Also a ADC ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
zonemikel



Joined: 13 Oct 2007
Posts: 53
Location: Texas

View user's profile Send private message Visit poster's website Yahoo Messenger

while ( input(PIN_B0) ) is it a good idea ? Also a ADC ?
PostPosted: Tue Oct 23, 2007 8:17 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 23, 2007 10:35 pm     Reply with quote

See this post for links to schematics which show how to connect a switch
to a PIC.
http://www.ccsinfo.com/forum/viewtopic.php?t=21958&start=1

Here is a routine that waits for you to press the switch. It handles
debouncing the switch.
http://www.ccsinfo.com/forum/viewtopic.php?t=19874&start=1


Quote:
for a pic 877a and #device adc=8

adc_value = read_adc();
volts = (float)(adc_value * 5)/1023.0;

#device adc=8 will produce values from 0 to 255. That won't work
properly with the code given above. It expects you to use
#device adc=10, which will produce values from 0 to 1023.

I think you got that code from here:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
If you look at that program, it does use #device adc=10.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Oct 24, 2007 8:58 am     Reply with quote

Take a look at the debounce code I posted a while back.

http://www.ccsinfo.com/forum/viewtopic.php?t=24103
zonemikel



Joined: 13 Oct 2007
Posts: 53
Location: Texas

View user's profile Send private message Visit poster's website Yahoo Messenger

PostPosted: Fri Oct 26, 2007 9:10 pm     Reply with quote

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 ?
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sat Oct 27, 2007 9:08 am     Reply with quote

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.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Oct 27, 2007 10:27 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group