Using the DAC on PIC18F24K22

Thread Starter

joeyd999

Joined Jun 6, 2011
4,291
I am building an application using the PIC18F24K22 (first time I've encountered this particular species). It's got an on-chip DAC. I am driving the DAC from Vdd to Vss. Not using the onchip FVR.

Assume the DACOUT pin (RA2) is buffered, as indicated as necessary by the datasheet (actually, for debugging, the pin is floating). Comparators are disabled.

Here are my control registers:

TRISA.2 = 0 (or 1, datasheet says don't care)
PORTA.2 = 0
ANSELA.2 = 1

VREFCON0 = b'00010000' -> FVR off
VREFCON1 = b'10100000' -> DAC Enabled/DACOUT OE Enabled/Vdd/Vss
VREFCON2 = 20 -> Vout = 20/32 * Vdd (3.125V @ Vdd=5V)

I get 0V out of the pin, regardless of what I try. I've even tried powering from the FVR with no result. This is puzzling me...usually I have no issues using PIC hardware. Any ideas?

FWIW, I know that I am doing something stupid and obvious, just can figure out what it is.
 

Thread Starter

joeyd999

Joined Jun 6, 2011
4,291
Yes, stupid, but not obvious...

Note 1: Addresses F38h through F5Fh are
also used by SFRs, but are not
part of the Access RAM. Users
must always use the complete
address or load the proper BSR
value to access these registers.
Working now... :)
 

thatoneguy

Joined Feb 19, 2009
6,359
We should start making a list of all the "blocks" in different PICs for peripherals.

Every PIC that has comparators or analog functions has those functions enabled by default on power on (comparators), why?

USB is enabled at power on, which makes sense, but can confuse somebody new to using a PIC with USB.

There's a few others that are specialized, and now we have DAC, how accurate is the DAC now that you have it working?
 

Thread Starter

joeyd999

Joined Jun 6, 2011
4,291
We should start making a list of all the "blocks" in different PICs for peripherals.
Problem is, such a list would never be exhaustive. Too many parts, new parts released often. The hardware changes/additions don't bug me much. I normally read everything for each module I am using and get it right the first time.

This project was a rush: hardware (including schematic & PCB) and firmware done in less than 2 weeks. So I didn't pay much attention.

OTOH, sometimes the errata *kills* me, especially when I forget to look. Once, I couldn't get a simple bin to bcd routine to work. It turned out that the DAW instruction didn't work as advertised!

Every PIC that has comparators or analog functions has those functions enabled by default on power on (comparators), why?
Not *this* part. The comparators are off by default. But the ANSEL bits are on.

USB is enabled at power on, which makes sense, but can confuse somebody new to using a PIC with USB.
My preference would be all peripherals are off, unless you intend to use them.

There's a few others that are specialized, and now we have DAC, how accurate is the DAC now that you have it working?
I assume it meets spec. Don't know, don't care. I only needed it to generate an approximate voltage less than Vdd (power dissipation issue). App works. Done.
 

Thread Starter

joeyd999

Joined Jun 6, 2011
4,291
Further, I really have *no* complaints about Microchip. Been using them from the beginning, and I am absolutely in love with them.

I know others have different preferences, and I respect that. But there ain't a damn thing I can't do with a PIC!
 

ErnieM

Joined Apr 24, 2011
8,011
Every PIC that has comparators or analog functions has those functions enabled by default on power on (comparators), why?
There is a simple reason why at power up pins default to analog inputs, or to digital inputs if they do not have a shared analog function: When you first turn on a device the pins need to default to a state that is the safest one possible.

Consider the digital case: If a pin is truly used as an input it needs to start as an input least two outputs drive against each other. Should the pin truly be used as an output then external components (pull up or down resistors and the like) can manage the short time interval between power on and pin set-up complete (if need be) to provide a certain level.

For the analog case: a digital level is always compatible with an analog input range, but not the reverse in generally untrue. So if a pin may ever be analog it needs to start that way.
 

Thread Starter

joeyd999

Joined Jun 6, 2011
4,291
There is a simple reason why at power up pins default to analog inputs, or to digital inputs if they do not have a shared analog function: When you first turn on a device the pins need to default to a state that is the safest one possible.

Consider the digital case: If a pin is truly used as an input it needs to start as an input least two outputs drive against each other. Should the pin truly be used as an output then external components (pull up or down resistors and the like) can manage the short time interval between power on and pin set-up complete (if need be) to provide a certain level.

For the analog case: a digital level is always compatible with an analog input range, but not the reverse in generally untrue. So if a pin may ever be analog it needs to start that way.
Makes *perfect* sense. Thanks for the explanation!
 

thatoneguy

Joined Feb 19, 2009
6,359
Makes *perfect* sense. Thanks for the explanation!
I agree and finally understand as well, thanks!

I'm a PIC lover myself.

I'm guessing USB enabled if available is for bootloading code or similar function, but it's need to run the program to do that, maybe it doesn't want to be re-recognized/negotiated by some OS's (*cough* M$ *cough*) on a reboot?
 

Thread Starter

joeyd999

Joined Jun 6, 2011
4,291
There's a few others that are specialized, and now we have DAC, how accurate is the DAC now that you have it working?
OK, well I was curious too, so I ran the numbers.

The DACOUT from the PIC, as far as I can tell, comes directly from a 32 step resistor ladder through a MOS transistor. The 32 step divider is composed of 5K resistors, for a total of 160K. I am running the DAC at 20/32 counts, so I expect a 5V*(20/32)=3.125V output, with at least a 37.5K source impedance. I say "at least", because I don't know what the channel resistance is of the output MOS.

Because of the high source impedance, Microchip recommends buffering the output.

My "buffer" is nothing more than a 2N2222 emitter follower driving about a 9.1K load. Remember, accuracy is not important in this application. The input impedance into the 2N2222 is finite and load and beta dependent, so I don't expect "perfect" numbers on the output of the DAC.

Here's the data for 5 boards:



My design target was 2.5V. I used the 0.7V rule of thumb for Vbe. This is no biggie, as I can allow +/- 1V and the app will still work.

PS: Please, someone teach me how to make proper tables on this forum!
 

Attachments

Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
{table=head}header 1 | header 2 | header 3
data1 | data2 | data3
data4 | data5 | data6
{/table}

Swap out { to [ and } to ] and there you have it. Items are separated by the pipe Symbol "|".
 
Top