You are here

WaveDAC8 Amplitude Control for PSOC5? | Cypress Semiconductor

WaveDAC8 Amplitude Control for PSOC5?

Summary: 19 Replies, Latest post by boz336 on 30 Aug 2016 05:00 PM PDT
Verified Answers: 0
Last post
Log in to post new comments.
boz336's picture
User
23 posts

I'm in the process of trying to generate a sawtooth waveform with the WaveDac component.  For a static waveform, there are no issues... and it works just fine  However, I'd like to be able to change the amplitude of the waveform through a UART interface. 

So the real question is:  What is the easiest way to be able to change the amplitude of the output waveform?

In the API, there is a WaveDAC8.c file that has an array (const uint8 CYCODE WaveDAC8_wave1) of 8-bit values that presumably get sequentially put into the DAC.  Is there a way to just add several more of these with the correct amplitudes?   If so, how do I go about changing the active waveform from main.c?

Or, is there a better way to do this?

Thanks in advance.

 

user_342122993's picture
User
675 posts

Check a similar project (function generator), which was posted before

http://www.cypress.com/?app=forum&id=2492&rID=76891

boz336's picture
User
23 posts

It looks like that project uses PWM rather than the DAC.  Are there any examples that use the DAC instead?  I've looked, but have not yet found any.

 

user_342122993's picture
User
675 posts

Inddeed, not a WaveDAC. I believe that to update WaveDAC internal array in real time API funcion can be used:
void WaveDAC8_StartEx(uint8 * wavePtr1, uint16 sampleSize1, uint8 * wavePtr2, uint16 sampleSize2)

But I have no ready-to use example at hand.
 

user_342122993's picture
User
675 posts

Attached is a project showing adjustable wave parameters using VDAC8 (not WaveDAC). In essence it does the same as WaveDAC: transferring data from RAM to VDAC8 using DMA.

 

boz336's picture
User
23 posts

Thanks.  That looks pretty close to what I was after.

user_342122993's picture
User
675 posts

I will look into using WaweDAC_StartEx(...), maybe it is possible to update output in real time. Strangely, there are no examples of that reported neither on the forum nor in App notes.

boz336's picture
User
23 posts

To make sure I understand clearly..... In your RAM-DMA-VDAC example, the amplitude would be controlled by loading a different uint8 array with different values (e.g. higher amplitude waveform)?  I'm still trying to figure out how to use   "void WaveDAC8_StartEx"  to change waveform amplitude.  For what it's worth, I don't need super high resolution control over the amplitude.  A set of maybe 6 or 8 amplitudes would probably do it.

user_342122993's picture
User
675 posts

That is correct - to change the waveform amplitude or shape, offset etc., the array values are being updated by CPU. DMA is blindly pushing the content of the array to VDAC. That is the easiest  way to update waveform.

Next step would be to make two arrays and just change the pointer to it. This way the change of waveform can be instantaneous. 

user_1377889's picture
User
10125 posts

Hey, Odissey1! Nice tie!!!

 

Bob ;-)

boz336's picture
User
23 posts

Thanks for the feedback.  It looks like I've got something working now.   A colleague noticed that the WaveDAC8_1_Wave1Setup(WaveDAC8_1_wave1,WaveDAC8_1_WAVE1_LENGTH);   also allowed selection of the desired waveform... and could be called directly from main.c .  There are a couple of things that needed attention in doing things this way: 

1) Making multiple waveforms with distinct names.  This can be done by just using the GUI with the right settings and copying the result into WavDAC8_1.c

2) Making sure to correctly deal with the modInit(); so that the WaveDAC8_1_initVar;   

3) If there are more than 2 desired waveforms, the additional containers need to be defined in WavDAC8_1.h  :

  e.g.

   /***************************************
   *    Variable with external linkage
   ***************************************/

   extern uint8 WaveDAC8_1_initVar;

   extern const uint8 CYCODE WaveDAC8_1_wave1[WaveDAC8_1_WAVE1_LENGTH];
   extern const uint8 CYCODE WaveDAC8_1_wave2[WaveDAC8_1_WAVE1_LENGTH];
   extern const uint8 CYCODE WaveDAC8_1_wave3[WaveDAC8_1_WAVE1_LENGTH];
   extern const uint8 CYCODE WaveDAC8_1_wave4[WaveDAC8_1_WAVE1_LENGTH];

NOTE:  All my waveforms are exactly the same length, so I probably could have just hard coded that instead of using _WAVE1_LENGTH for everything.

It seems like this would be a decent way to have a wide array of different waveforms that can be dynamically selected at runtime.  It might not be the fastest way to switch between the waveforms though.  Depending on how many waveforms are required, you might be able to use multiple WaveDACs with fixed waveforms and use a mux to switch between them. 

At any rate, thanks for the suggestions!

 

Log in to post new comments.