1 2 Previous Next 18 Replies Latest reply on Aug 30, 2016 5:00 PM by user_222465698

    WaveDAC8 Amplitude Control for PSOC5?

    user_222465698

      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.

        • 1. Re: WaveDAC8 Amplitude Control for PSOC5?
          user_342122993

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

             

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

          • 2. Re: WaveDAC8 Amplitude Control for PSOC5?
            user_222465698

            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.

            • 3. Re: WaveDAC8 Amplitude Control for PSOC5?
              user_342122993

              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.
               

              • 4. Re: WaveDAC8 Amplitude Control for PSOC5?
                user_342122993

                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.

                   

                 

                   

                • 5. Re: WaveDAC8 Amplitude Control for PSOC5?
                  user_222465698

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

                  • 6. Re: WaveDAC8 Amplitude Control for PSOC5?
                    user_342122993
                            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.   
                    • 7. Re: WaveDAC8 Amplitude Control for PSOC5?
                      user_222465698

                      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.

                      • 8. Re: WaveDAC8 Amplitude Control for PSOC5?
                        user_342122993

                        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. 

                        • 9. Re: WaveDAC8 Amplitude Control for PSOC5?
                          user_1377889

                          Hey, Odissey1! Nice tie!!!

                             

                           

                             

                          Bob ;-)

                          • 10. Re: WaveDAC8 Amplitude Control for PSOC5?
                            user_222465698

                            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!

                            • 11. Re: WaveDAC8 Amplitude Control for PSOC5?
                              user_222465698

                              Arrggghhh.. Thought I had it, but apparently I can only change waveform outputs two times and that's it.  I'll keep beating on it to see if I can figure out what I'm doing wrong. It seems like I might be missing something in the DMA. 

                              • 12. Re: WaveDAC8 Amplitude Control for PSOC5?
                                user_222465698

                                Ok,  I gave up on the WaveDAC idea.... It just wasn't coming together.  I was however, able to get the VDAC (actually I'm using an IDAC since I need as fast a waveform as I can get) working pretty well.  Honestly, this is probably a better solution since the way I was trying to do it required having separate waveform data saved in memory.... which for large waveforms or many/multiple waveforms could be a potential memory issue.   Still, I'd like to understand why the WaveDAC didn't work.... The problem seemed to be that the DMA didn't want to update to a new memory pointer.  Not sure if it's an issue with trying to change TD arguments... or something else I've been doing wrong.  The one nice thing about the WaveDAC is that you can make the waveforms completely arbitrary... whereas it's a bit more cumbersome to generate the data points with loops and math.

                                   

                                Anyway, thanks again Odissey1 for the helpful hints!!

                                • 13. Re: WaveDAC8 Amplitude Control for PSOC5?
                                  user_342122993

                                  boz336,

                                     

                                  don't give up! Like there are 200 ways to make a moonshine, there are many ways to generate a ramp using PSoC.

                                     

                                  I updated the project to have 2 (or more) waves, but it still needs testing (will post later). Meanwhile, could you describe all specs requirements for wave generator? (update rate, ramp length, amplitude update frequency; can amplitude be changed during the ramp or it has to wait for ramp to finish? do you need a ramp profile only or some other wave? should ramp wave period be adjustable?, etc). I am a bit concerned you want wave as fast as possible and have many points per ramp; note that maximum WaveDAC can produce is about 17kHz wave repetition frequency at 256 points per wave, as limited by DMA transfer (14-16 CPU clocks).

                                  • 14. Re: WaveDAC8 Amplitude Control for PSOC5?
                                    user_342122993

                                    boz336,

                                       

                                    attached below is hardware ramp generator demo. It uses BasicCounter to make 8-bit digital ramp [0-255], and custom hardware mutiplier component (Mult8x8u) to change the ramp amplitude using API call. Maximum frequency is about 46kHz for 256 point per period. This is not promised WaveDAC though, which is still in the pipeline...

                                       

                                    YouTube video: https://youtu.be/1e-5IT6zt0E

                                       

                                     

                                       

                                       

                                       

                                    1 2 Previous Next