Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 29th March 2007, 02:37 AM   (permalink)
Default 16F628 - Comparing I/O

Hey,

I'm stuck at the moment with how to check the I/O of the 16F628 PIC. I'll start from the beginning.

I have 3 inputs, all of which I want to check the voltages and whether they are between a certain voltage or not. First I need to know how to accept the input (I've seen the use of ADRESH but not sure if it applies to this PIC because it has no A/D, so I doubt it) and then how to go about comparing it to a decimal number.

I understand the use of add/sub's to compare, but I don't understand how to compare with a decimal number. I don't quite understand how to declare a decimal number either. How would one, say, declare a constant of 1.3V?

Thanks for any help!
burg is offline   Reply With Quote
Old 29th March 2007, 02:54 AM   (permalink)
Default

On the 628 you don't have an ADC. You do however have comparators. You could use a comparator to compare a pin to 1.3V. Place a variable resistor (and adjust for 1.3V) on 1 comparator input and the voltage to be tested on the other and the output will go high/low dependent on the input voltage.

Have a read of the data sheet and you should be able to work out how to set it up.

Just reread your question and you can't use this method for 3 inputs as the 628 only has 2 comparators. Have you considered a 16F88?

Mike.
Pommie is online now   Reply With Quote
Old 29th March 2007, 02:59 AM   (permalink)
Default

I just took a quick look at the comparator module and by setting CMCON to 1, you can test 3 inputs against a fixed value.

Mike.
Pommie is online now   Reply With Quote
Old 29th March 2007, 03:49 AM   (permalink)
Default

Ha,

I did the opposite. I looked over the chart at Microchips and saw only 2 comparators and went to look at the 16F88. I think it would actually be able to just slide right into my circuit in replace of the 628.



I've seen more code examples using the A/D method vs. the comparators, but I've had no experience with either. What do you think would be better, given that the 16F88 seems to fit right into the circuit?

*Note* That IC converts a frequency to voltage, which that voltage is needed by other components as well. So I'd rather avoid the PIC for that.

Thanks alot, you've been a great help.
burg is offline   Reply With Quote
Old 29th March 2007, 04:00 AM   (permalink)
Default

The 88 is probably the simplest solution. I posted some example code in the third post of this thread which shows how to read the ADC.

HTH

Mike.
Pommie is online now   Reply With Quote
Old 29th March 2007, 04:06 AM   (permalink)
Default

Yeah, from reading more into it, there seems to be a lotmore documentation on the A/D method. You're code gave me a few tips as well. I just hope it works in that circuit, but I doubt there is much of a difference between them. The ports line up all the same, and from the looks of it the 16F88 doesn't need any external additions, correct?

Thanks again!
burg is offline   Reply With Quote
Old 29th March 2007, 04:25 AM   (permalink)
Default

The 16F88 is a direct replacement for the 628 and has the added advantage that the internal clock is twice as fast at 8MHz but is software settable to 4MHz should you have time critical code. It also has twice the memory.

Mike.
Pommie is online now   Reply With Quote
Old 29th March 2007, 11:03 AM   (permalink)
Default

Honestly I would use the A/D converters of the PIC16F88 because I'm familiar with them, but the comparators of the PIC16F628A can do the job. I like the internal voltage reference of the comparators, that is software selectable. You need to set CMCON2:0 to b'010' and configure the VRCON register.
eng1 is offline   Reply With Quote
Old 30th March 2007, 03:52 AM   (permalink)
Default

Quote:
Originally Posted by Pommie
The 16F88 is a direct replacement for the 628 and has the added advantage that the internal clock is twice as fast at 8MHz but is software settable to 4MHz should you have time critical code. It also has twice the memory.

Mike.
Too bad they moved some of the I/O around (The USART uses different pins)

It's an awesome chip. Now if only people would stop using the 16F84

PS looking at the 16F887 is a different beast than the 16F877, lots more little bits...
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 30th March 2007, 03:54 AM   (permalink)
Default

Will that affect my case? Or is it just a general fact? The pins seem to be identical for my purposes...
burg is offline   Reply With Quote
Old 30th March 2007, 05:30 AM   (permalink)
Default

You should be fine as you aren't using the USART.

Mike.
Pommie is online now   Reply With Quote
Old 30th March 2007, 01:40 PM   (permalink)
Default

The A/D on the 16F88 are all on PORTA, you should be fine. Nice feature about the 16F88 you can split up the A/D. On the larger chips they have to be enabled in order. RA0 then RA1 etc...
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 30th March 2007, 02:28 PM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
The A/D on the 16F88 are all on PORTA
Except for the two that are on PORTB!

Mike.
Pommie is online now   Reply With Quote
Old 30th March 2007, 04:12 PM   (permalink)
Default

I hate it when those picky details get in the way (grin)...
Mike, K8LH is offline   Reply With Quote
Old 30th March 2007, 04:17 PM   (permalink)
Default

Quote:
Originally Posted by Pommie
Except for the two that are on PORTB!

Mike.
I forgot about those two, can't use em with the ICD2 connected.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
code convertion 16F628 -> 16F84 patroclus Micro Controllers 6 6th April 2006 08:34 PM
is the number if I/O pins on a 16f628 enough for my project? ryan_ryan Micro Controllers 8 13th March 2005 01:22 PM
16f628a programming only got 16f628 support will it work? lompa Micro Controllers 6 18th December 2004 05:51 PM
JDM and 16F628 patroclus Micro Controllers 13 15th December 2004 10:20 AM
Can JDM program 16F628 ??? dy001 Micro Controllers 3 25th September 2003 03:06 PM



All times are GMT. The time now is 11:40 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.