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.

Using PWM as DAC

Status
Not open for further replies.

Fred.Amoson

New Member
Hello,

I want to use a PIC as a two output DAC. I was looking at the PIC16F685 to do this. It has 4 PWM channels, and is the cheapest that I could find with 2 or more PWM channels. Does anybody have any cheers or jeers for this PIC?

After I choose my PIC, anything special I should look out for making it PWM? I think I can figure most of it out from the datasheet. I prefer to program in C.

What circuit do I need to use to make the PWM be a DC voltage? Will a simple capacitor work? What kind of response times will I get using said circuit? It is important that this be able to change the DC voltage very quickly.

Thanks!
 
The PIC16F685 has a single PWM source with many H-bridge output options. Choose a 16F876 or 16F877 (886 or 887) if you want two channels.
 
Okay, thanks for the heads up. I will check out those and see what meets my needs the best.

On a side note, what's the difference between Flash, Standard Flash, and Enhanced Flash? Is that anything I need to watch out for when choosing a PIC?
 
Fred.Amoson said:
On a side note, what's the difference between Flash, Standard Flash, and Enhanced Flash? Is that anything I need to watch out for when choosing a PIC?

PIC microcontrollers with Enhanced Flash have self-programming capabilities. You can use a bootloader to program the microcontroller in the target board.
 
eng1 said:
PIC microcontrollers with Enhanced Flash have self-programming capabilities. You can use a bootloader to program the microcontroller in the target board.

Thanks, I always wondered what that meant.

I did a little more searching and decided the 886 would be best for my purposes. What circuit do I need to make the PWM DC? Also, how fast will I be able to change that voltage?
 
You need a low pass filter, I suggest you check the MicroChip application notes, there's at least one that tells you all about using PWM as a DAC and how to calculate the filter values.
 
Perhaps this will help?

The following diagram is with a duty cycle of 25% (63) and a frequency of 32767Hz on channel 1 (CCP1) eg: HPWM 1, 63, 32767 With a duty cycle of 25%, the output will be 25% of 5V, or 1.25V. Note the PSU/OSC are not shown.

**broken link removed**

The command in Proton+ is

Code:
        HPWM Channel , Dutycycle , Frequency

As it so turns out, the channels on the 16F877 are CCP1 and CCP2, but CCP1 is on PORTC.2 and CCP2 is on PORTC.1.. I have no idea why, but you can declare the pins into what would seem the correct format like so,
Code:
        Declare CCP1_PIN = PORTC.1
        Declare CCP2_PIN = PORTC.2

I'm using 1 channel for this example, and a simple RC circuit that will average the PWM signal and turn it into a rather constant analogue output. The op-amp is not required for all applications, but it definitely is good practice to use it as a buffer. The frequency should always be on max, i.e. 32767Hz for DAC, a lower frequency will make the output appear laggy / have a long response time.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top