I'm trying to get a basic DAC example working on the FRDM-K22F board using Processor Expert.
I've configured a DAC (Legacy High-Level component) using an underlying DAC (Logical Device Driver). The issue I'm having is that the DAC output seems to jump around/toggle but doesn't exactly reflect the value I'm trying to assign.
I have a loop incrementing a variable and assigning to the DAC, so I was expecting a sawtooth waveform:
for(;;){
DAC_Update(dacValue);
sprintf(dacString, "DAC: %d", dacValue);
WriteLine(dacString);
WAIT1_Waitms(1000);
dacValue += 10;
if(dacValue > 4000)
dacValue = 0;
}
However, what I actually see is a toggling signal between 0V and .16V before eventually jumping directly to 3.3V. So here's the dacValue vs the output voltage:
dacValue: 0 voltage: 0 V
dacValue: 10 voltage: 0.16 V
dacValue: 20 voltage: 0 V
dacValue: 30 voltage: 0.16 V
dacValue: 40 voltage: 0 V
dacValue: 50 voltage: 0.16 V
dacValue: 60 voltage: 0 V
dacValue: 70 voltage: 0.16 V
...
dacValue: 400 voltage: 3.3 V
Eventually, the dacValue drops again/jumps around in the range 0-3.3V.
Any idea what is causing this? Here is my DAC configuration from PE:
DAC0
12 bits
Left justified/unsigned
Init value: 0
D/A resolution: 12 bits
Low power mode: unchecked
Voltage reference source: external
Not sure what's going on with the Legacy High-Level DAC but when I use the Logical Device Driver interface directly, I get the expected results (output ramps up smoothly).
Hi
Do you apply an external reference? Normally the output should follow the variable 0..4095 range.
If you have problem with P+E just use the Open Source uTasker K22 project:
It does DAC or PWM from USB, etc.
http://www.utasker.com/kinetis/FRDM-K22F.html
http://www.utasker.com/kinetis/TWR-K22F120M.html
http://www.utasker.com/kinetis/BLAZE_K22.html
http://www.utasker.com/docs/uTasker/uTaskerADC.pdf (ADC/DAC documentation)
https://www.youtube.com/watch?v=n-GABeILGV8&feature=youtu.be (Video of K22 USB->DAC and FFT analysis)
Open Source project code: http://www.utasker.com/forum/index.php?topic=1721.msg7086#msg7086
Regards
Mark
Professional support for Kinetis: http://www.utasker.com/index.html
Remote desktop one-on-one coaching: http://www.utasker.com/services.html
Getting started to expert videos: https://www.youtube.com/results?search_query=utasker+shorts