Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16F628 - Comparing I/O

Status
Not open for further replies.

burg

New Member
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!
 
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.
 
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.
 
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.

**broken link removed**

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.
 
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!
 
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.
 
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.
 
Pommie said:
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...
 
Will that affect my case? Or is it just a general fact? The pins seem to be identical for my purposes...
 
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...
 
Status
Not open for further replies.

Latest threads

Back
Top