# newbie question...

Status
Not open for further replies.

#### Steve P

Hi guys. Thanks for building such a kick @$$site. I've read the sticky note for beginners, but I still have a couple of questions that I can't seem to find the answer to. First off, I'm working on a project where I'm going to have 3 analog 5v sensors as inputs. My PIC needs to process the info from these sensors and will be controlling 3 outputs (lights, motor, heater). I've read about analog versus digital and I'm a little confused as to how the signals need to be converted and how to program this conversion. Do I need to look for an analog PIC or can a digital PIC work just the same? OR...are all PIC's digital and need a special converter for analog?!?...AHHHHHHHH!!!!!! Second Question, I've been researching PIC's in general and I saw that you guys recommend the PIC 16F628. Before I came across this site, I had been thinking about an 8052 (I found some good tutorials on it). I know that the PIC16 has 16 (18 total) I/O pins and the 8052 has 32 (40 total). How will I know how many I/O pins my project will require? Could I run everything I need for my project with the PIC16's 2 ports or do I need 4 ports with the 8052? I guess I need to know how the ports correlate to the amount of devices the PIC itself can control. Please help! #### checkmate ##### New Member Steve P said: First off, I'm working on a project where I'm going to have 3 analog 5v sensors as inputs. My PIC needs to process the info from these sensors and will be controlling 3 outputs (lights, motor, heater). I've read about analog versus digital and I'm a little confused as to how the signals need to be converted and how to program this conversion. Do I need to look for an analog PIC or can a digital PIC work just the same? OR...are all PIC's digital and need a special converter for analog?!?...AHHHHHHHH!!!!!! Analog means that the signal voltage is any real number. Digital means that the signal voltage is constrained to 2 fixed values, one for 'Logic High' and the other for 'Logic Low'. For PICs, these 2 values are mostly 5v and 0v (ie Gnd). Digital signals can be used to represent binary data, eg a stream of +5 0 +5 0 would correspond to the binary number "1010". All processors (including PIC) work only on binary data, ie digital. To convert analog signals to binary data, we use ADCs (Analog-to-Digital Convertors). Some PICs have built-in ADCs, so you should preferably choose a PIC with those. When working with ADCs, you'll normally see something like 8-bit ADC. That means that the ADC partitions the detection range to 2^8=256 segments. So for a detection range of 0v-5v, the first segment (ie segment 0) will span from 0v to ((5v-0v)/256)v. Similarly, you would expect a value of 128 for 2.5v. Steve P said: Second Question, I've been researching PIC's in general and I saw that you guys recommend the PIC 16F628. Before I came across this site, I had been thinking about an 8052 (I found some good tutorials on it). I know that the PIC16 has 16 (18 total) I/O pins and the 8052 has 32 (40 total). How will I know how many I/O pins my project will require? Could I run everything I need for my project with the PIC16's 2 ports or do I need 4 ports with the 8052? I guess I need to know how the ports correlate to the amount of devices the PIC itself can control. How many pins you'll need will probably depend on what you are controlling. If you just want to switch an LED on/off, you will need only one pin. For motor driver, you generally need 2-3 pins. If you interface an IC, say for ethernet purposes, then you'll gonna need A LOT of pins. So it really depends on your application. #### eblc1388 ##### Active Member Steve P said: Hi guys. Thanks for building such a kick @$$ site. I've read the sticky note for beginners, but I still have a couple of questions that I can't seem to find the answer to.

By reading the sticky, you have a very good chance of getting meanful responses here.

Steve P said:
... Do I need to look for an analog PIC or can a digital PIC work just the same? OR...are all PIC's digital and need a special converter for analog?!

First generation of PICs were all digital. Then they added voltage comparator, then they added Analogue-Digital Converter along with other peripherial.

Smaller PICs like those 18-Pins one have only voltage comparator or one single channel of A/D so if you want A/D converter on several channels, you have to use the 16F87x or higher spec PIC families.

Steve P said:
I've been researching PIC's in general and I saw that you guys recommend the PIC 16F628.

That have changed. Now I would recommend 16F628A as it is cheaper and better. The next in line is 16F88.

Steve P said:
Before I came across this site, I had been thinking about an 8052 (I found some good tutorials on it). I know that the PIC16 has 16 (18 total) I/O pins and the 8052 has 32 (40 total).

No. PIC can have practically as many I/Os as you wanted, in different packaging. Only the 16F628 have 16 I/Os. The 16F877A have upto 35 I/Os, others have more.

Steve P said:
How will I know how many I/O pins my project will require?

You need to ask Mr. Steve P, the chief designer.

Steve P said:
I guess I need to know how the ports correlate to the amount of devices the PIC itself can control.

Most of the pins on a PIC can be configured as either digital input or output and function accordingly. You have full control on every I/O pin.

You can also activate other alternate functions like A/D conversion or USART features on some of them.

#### Steve P

##### New Member
thanks checkmate...i think i FINALLY understand whats going on!

So, let me make sure I understand you correctly... The ADC takes in an analog signal, which is represented as a voltage range. So for example, if I were using an analog thermometer, the temperature range its capable of detecting is directly proportional to its voltage range which is 0v-5v. The 8 bit ADC, in your example, would break that voltage range down into 256 different segments. So mathematically, each segment would be would be worth approximately .01953v. So in other words, each segment would have an incremental increase of .01953v. The ADC would take that voltage and convert it into a binary value that could be processed by the PIC. So in my programming, I would need to know what my desired temperature range would be for the project, calculate the corresponding "segments", or binary values, and program that information accordingly into my program....right?

Now when you say segments... you're talking binary right? Like 8 numbers that could potentially be 1 or 0 which would make 256 different numbers? I'm still trying to completely grasp the binary number system.

#### Steve P

##### New Member
eblc1388, thanks for hitting that pins question for me! You guys are great!

eblc1388 said:
You need to ask Mr. Steve P, the chief designer.
(Put a smile on my face....i know i'm corny...)

I see what you mean about the pins. Is it possible to have one pin connected to more than one thing? Lets say Pin 1 for instance...is it possible to make pin 1 an input pin for a sensor during one instruction and an output pin for something completely different in a different part of the program?

#### checkmate

##### New Member
Yes, yes and yes.

#### Steve P

##### New Member
checkmate said:
Yes, yes and yes.
Thanks for answering all my questions!

I got one more for you...conceptual. Lets say instead of an 8 bit ADC, I had a 16 bit ADC. IF this were the case, wouldn't I have 65,536 "segments" instead of 256? This would allow my DIGITAL temperature readings to be more accurate...right?

I'm sure an 8 bit would do just fine, I just want to see if I completely understand the ADC concept.

PIC18 Devices

#### Steve P

##### New Member
cool.

THANKS A LOT GUYS!

#### Exo

##### Active Member
Steve PI said:
got one more for you...conceptual. Lets say instead of an 8 bit ADC, I had a 16 bit ADC. IF this were the case, wouldn't I have 65,536 "segments" instead of 256? This would allow my DIGITAL temperature readings to be more accurate...right?

Bare in mind that 16-bit resolution is SO accurate that you'll need special high precision external components for it.
I mean, what's the use of a 16bit ADC if you use normal, 10% accuracy resistors and other components...
Even the temperature sensor won't be so accurate. The 10 Bit ADC on most pic's will do fine, no need for a full blown full price 16 Bit.

#### checkmate

##### New Member
Just to add that PICs are 8-bit microcontrollers. That means they handle data 8-bits (or 1 byte) at a time. So working with 16-bits (or even 10-bits) take roughly (VERY rough estimate) double the time. So if you do not need the high resolution, then stick to 8-bits.

#### Steve P

##### New Member
Exo said:
Bare in mind that 16-bit resolution is SO accurate that you'll need special high precision external components for it.
I mean, what's the use of a 16bit ADC if you use normal, 10% accuracy resistors and other components...
Even the temperature sensor won't be so accurate. The 10 Bit ADC on most pic's will do fine, no need for a full blown full price 16 Bit.

#### Jay.slovak

##### Active Member
Steve P said:
I've been researching PIC's in general and I saw that you guys recommend the PIC 16F628. Before I came across this site, I had been thinking about an 8052.
I just want to say, that PICs and 8052s are a totally different families of microcontrollers. PIC was designed to be cheap, fast and requires minimal external components, whereas 8052 (original version) is a very different MCU, which requires much more external components and is more expensive. PICs have also advantage of great support from forums like this, Microchips sample system and their websites resources...

Status
Not open for further replies.

Replies
4
Views
1K
Replies
3
Views
909
Replies
9
Views
3K
Replies
6
Views
865
Replies
1
Views
818