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.

PICs and DAC/ADC and other basic questions

Status
Not open for further replies.

ChemE

New Member
As you all know I am very new to PICs and programming but I feel that I have learned a lot very quickly.

Jay.Slovak's newbie guide to PICs is excellent and am grateful that he posted this.

Up until today I assumed that digital to analog (DAC) were interchangeable with analog to digital (ADC)... after reading the PICmicro Mid-Range MCU Family Reference Manual I do not believe this to be true. So...

  • Am I right in saying that some PICs have only ADC pins?

  • When the ADC pins are active they are inputs only and can not output an analog signal?

  • So if I would like to have a PIC output 6 different analog signals to 6 potentiometers what will be the best way to accomplish this?

  • Where can I find DACs and what ones would you suggest?

I just ordered a P16pro40 I hope to start building a prototype of my idea soon. Thank you all inadvance for the help!
 
I think some few PIC's have DACs. I could be wrong. Keep in mind, with a low pass filter ANY PWM output can be used as a DAC with an output buffer. Why would you 'output' an analog signal to a potentiometer?
 
Am I right in saying that some PICs have only ADC pins?
Not really, because ADC pins can usually be configured as digital IO pins instead.
When the ADC pins are active they are inputs only and can not output an analog signal?
Correct!
So if I would like to have a PIC output 6 different analog signals to 6 potentiometers what will be the best way to accomplish this?
Usually with PWM and a lowpass filter. Though most PICs don't have that many PWM outputs. You might have more luck using some digital POT ICs attached to the PIC via the SPI or I2C buss.
Where can I find DACs and what ones would you suggest?
I would find an IC that you can get from a supplier that is in (or ships to) your location. We would need to know the number of bits of resolution you need before we could recommend a specific IC. That said, the TDA8444 has X8 6bit DACs in a 16pin DIP.
 
Last edited:
Thank you for the quick response

  • Could someone list which PICs have DACs?

  • Could someone also explain this:
    with a low pass filter ANY PWM output can be used as a DAC with an output buffer

  • What is a PWM?

Ok outputing to a potentiometer is not quite what I would like to do. What I was trying to say is I would like to output analog signal from a PIC inplace of the pots. So instead of the pots sending the analog signal the PIC would send it.

What I am trying to accomplish is to connect a keyboard and mouse through PS/2 ports to input signals into a PIC. Have the PIC output signals to a xbox 360 controller which has 14 buttons and two 4-axis pots (for the thumb analog sticks) and two 1-axis pots (for the left and right trigger).

I have read that PICs have internal pullup resistors which I could use to connect the PS/2 ports for the keyboard and mouse.

  • Could someone explain to me how to connect PS/2 ports by using the internal pullup resistors?

Any information on connecting PS/2 ports to PICs would be great.
 
PWM == Pulse width modulation.
Basically if you turn a digital I/O line on and off at a rate of say 10khz and vary the duty cycle (the percentage of the time the signal is on) if you average that voltage over time you will get an analog signal. In order to turn that into an analog signal you pass it through a resistor and capacitor in a low pass network (look ALL of these terms up in wikipedia) and you'l get an analog voltage out. there are restrictions on the update rate, and the tollerable noise levels. One other very basic yet simple circuit to look up is an R2R DAC. Which is just a set of resistors set up in a certain way which can produce an analog voltage (if it's buffered)
 
Could someone list which PICs have DACs
I don't know of a PIC that has a DAC, let alone 6 of them. Did you try searching https://www.microchip.com ?
I think an external DAC IC like I mentioned will be the best solution. You'll need to do some tests on the POTs on the 360 controller to find out how much resolution you'll need.
Could someone explain to me how to connect PS/2 ports by using the internal pullup resistors?
External vs internal pullup resistors are the least of your worries. Read this about how to interface a microcontroller to a PS/2 keyboard:
**broken link removed**
 
Last edited:
Well I know the voltages of the POTs:

Up = 1.60v
Down = 0v
Center Idle = 0.80

What would I need and how do I calculate the resolution?

If I were to assume that interfacing a PS/2 keyboard was the least of my worries what would be the best way to connect it? With external or internal pullup resistors?

If someone is knowledgable about internal pullup resistors I would appricate it if they could write how they work and how to do them... or someone could point me to a site that discusses them.

Man I am such a newb! I just want to build mouse to PS/2 to PIC to Controller portion of my idea and start playing around with it because I think it will be the best way for me to learn. I have some concerns that there could be some lag from the mouse input to analog output to the 360 controller.

Thank you for all the comments they are really helpful.
 
I'm not aware of a PIC with DAC, but using the built in PWM generators that many PIC's have (The 18F4520 has 5 hardware PWM controllable outputs)

Pulse Wave Modulation is a signal that has both frequency and a duty cycle, for example;

50% duty cycle (freq = 2Khz);
**broken link removed**

25% duty cycle (freq = 2Khz);
**broken link removed**

A simple RC (resistor capacitor) circuit will 'average' this signal out.

Put simply - a 50% duty cycle will appear as 2.5V, a 25% duty cycle would appear as 1.25V.

With that in mind, a 100% duty cycle would appear as 5V, and 0% = 0V.

Now if you didnt already see, you have built a DAC (digital to analogue converter).

**broken link removed**

By using the op-amp, I am buffering the signal, as the opamp has a large input impedance, and a low output impedance (you could use a power opamp like the LM386 for more current).

One other thing to keep in mind - the faster the frequency of the PWM, the better the response rate of the circuit.

With Proton PIC Basic, the PWM of a PIC can be controlled via
Code:
HPWM Channel, Duty_Cycle, Frequency
so
Code:
HPWM 1, 64, 20000

would put a 25% (256 / 64) duty cycle on channel 1 @ 20Khz
 
Last edited:
If I were to assume that interfacing a PS/2 keyboard was the least of my worries what would be the best way to connect it? With external or internal pullup resistors?
External, because the PIC internal inputs only have the option of weak pullups which probably won't source enough current to make it reliable. BTW, I meant that the pullup resistors were the least of your worries. ;)
Well I know the voltages of the POTs:
Up = 1.60v
Down = 0v
Center Idle = 0.80
What would I need and how do I calculate the resolution?
Well, lets say when you are playing a Xbox game and are trying to move around very carefully in it. Lets say that the smallest movement you make with the game pad changes the voltage by 0.02V. Then 1.60/0.02 = 80 or a minimum of 7bits of resolution is required to simulate this minimum step. ( 0.03V would have made it 6bits)
I have some concerns that there could be some lag from the mouse input to analog output to the 360 controller.
Gramo's PWM DAC will work, but will add some lag over a proper DAC IC solution due to the Low Pass Filter network. If you keep the PWM frequency as high as practical, it shouldn't be an issue though.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top