After working on an ADC example, a DAC one was missing. Julio E. Fajardo is a reader of this blog, and he was so kind to send me an example project for the FRDM-KL25Z. The example is able to produce produce different waveforms with the DAC. The project has two examples which they are enabled/disabled in
main(). One example waveform the sawtooth:
And the other example waveform is a sinus:
The project sources are available on GitHub. It is using tables with the values so they are not computed at runtime. I tweaked the code a bit, and have defined the table as
const array so it ends up in FLASH.
Many thanks again to Julio for that great example and screenshots!
Happy ADCing 🙂
Do the Kinetis MCUs like the KL05 have the ability to gate the PWM signal with the DAC output in hardware? I would like to have the ability to have a PWM signal from my DAC while also setting the output voltage on the ON Duty times without the use of software interrupts or the need to put an external transistor on the DAC output with the PWM on the gate. Following me?
I know what you mean, but I have not used the DAC in such a way, so I cannot tell you if this is supported or not.
Thanks to Erich for a GREAT blog (it’s my go-to resource for learning the KL25Z) and to Julio for the DAC example.
My long-term goal is to create a simple triggerable music player using the KL25Z (mostly as a learning exercise). The idea is to read in from an SD card or SPI flash and then output via the DAC to a small amp.
Whilst playing about with the DAC component I noticed that there is a D/A buffer option (along with DMA access). Does anyone know if the KL25Z supports this and could push me in the right direction as to implementing it? The datasheet I have doesn’t really cover this in any detail – is there a better datasheet anyone could point me to?
All help gratefully received – if I get the buffer going I am happy to share an example project with you all.
many thanks for that positive feedback! 🙂
I had this idea of such a music player in my mind for a long time too, but never had the time. I have not used that buffer option, but if I remember right, it allows to store conversion values in a fifo, so it can be retrieved later on. Maybe somebody else has more knowledge in this area?
Thanks for your reply Erich. I’m developing this VERY slowly as (a) I’m a hardware engineer really and (b) CodeWarrior has a steep learning curve for me.
2 quick questions:
1. Is there a good resource for learning CodeWarrior (except for this site). Like a reference book I can read? The built-in help is actually very good but it would be good to have a continuous reference I can access.
2. Is there a “proper” datasheet for the MKL25Z128VLK4 that I can access? I can’t find one that details each hardware element individually and gives a register-by-register breakdown of what’s going on…
Sorry if either of these have obvious answers – I’m drowning in new information at the minute!
for 1: Nothing special I’m aware of. I rarely read reference manuals :-).
here are a few pointers (inside the installation):
for 2: You can find reference manuals here:
But if you are looking for information on the ARM core itself: then you need to go to the ARM.com web site.
So this easily ends up in ten thousands of pages 😦
I hope this helps.
Thanks for your advice Erich – the reference manuals are about right – not sure I’m ready for a full-on ARM assault yet! In the end I managed to get DAC output driven by a Timer Interrupt which was OK-ish. I am happy to make that example available to people if you like – it’s a very straightforward derivative of Julio’s however.
Now I’m having trouble getting everything together with SD reads, but that’s another story…
I had this idea too, but I have not time to work on this now. I greatly appreciate the example you will realize.
I tried you code but something seems off at the output:
Sinewave has overshooting periodically, not smooth like yours;
Sawtooth wave wasn’t generated at all, some gibberish was generated instead.
Is my DAC configuration wrong? Can you go into more details on how to configure the DAC please?
I have not used that example for a long time, but I thought it was working as expected at the time of the post. Are you using the FRDM-KL25Z board?
Yes I’m sure. I have posted the issue at the freescale community as well to try to get this issue sorted out. Its here in case you want to get updated:
how can i get the labview virtual cro shown in the images above
That signal was obtained with the NI ELVIS Oscilloscope, NI provides a virtual instrument package.
NI provides a virtual instrument package with the NI ELVIS II.
Hi Erich! Is there any way to reach a higher frequency than 1Khz? I did everything this tutorial say, and i can’t get any freq higher than 1Khz.
Maybe changing the setting on CPU clocks? If it’s possible, could you help me on that?
Thank you in advice!
the maximum frequency depends on your sample frequency and how many samples (oversampling) you take. The higher the bus clock, the less time you need. So increase the bus clock to the maximum value on your board. Beyond that, you would need to use DMA. With DMA, you free up the processor moving the data.
Do you have a clear example of using DMA with DAC? I’ve tried to do that, even having read the help on component but no results 😦 I’ve not found the correct configuration to make it work.
I have not done that (yet), but maybe this one can help you?
freescale community docs/DOC-96507
I had some troubles to get it work with the FRDM-K64F. However, there is an example from freescale for the K64F: freescale community thread/325233 (at the bottom of the page). Petr_H an employee of Freescale wrote: “We have reproduced the problem with DAC component and it is a defect related to the internal value computation which we will fix for next release. We are sorry for the inconvenience.”
The example he posted on the webpage worked fine with the K64F.
I downloaded the project today, In the current build of Code Warrior (10.6), the DA1:DAC_LDD component DMA is enabled in the Component Inspector. Project is not working with this setting. When the DMA is disabled project is working fine.
And thanks for the project
thanks for that information, I have not tried that project for a while.
The link to downlad the DAC project on GitHub doesn’t look to work anymore.
Soonst, thanks for all your great examples and tutorials on this website!! Very usefull 😉
I’m sorry, the location on GitHub has moved to here: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/CodeWarrior/FRDM-KL25Z/Freedom_DAC
How can I change the amplitude, frequency and offset base on a table of the wave?. I need to make a wave generator. For the amplitude I think that I can use conventional electronic for that but the rest of option I don’t know how.
Please help me
I would create the table on demand with the desired wave and frequency.