You are here

mutiple channel sine wave generator based on DAC_SineWaveGenerator | Cypress Semiconductor

mutiple channel sine wave generator based on DAC_SineWaveGenerator

Summary: 5 Replies, Latest post by Gautam Das on 27 Jan 2011 07:19 AM PST
Verified Answers: 0
Last post
Log in to post new comments.
Johnspark's picture
User
9 posts

Dear community, I want to make a multiple channel sinewave generator which can have configurable amplitude and phase. Frequency only has to be 50 / 60 hertz. Ideally I would like 8 channels but can settle for 4.

From the example called :DAC_SineWaveGenerator, I understand for 1 channel, I need 1 timer, 1 DMA and 1 VDAC.

For 4 channels I would need 4 DMAs, 4 VDACs but what do I do with the timing, do i use 4 timers, or 1 timer plus 3 shift registers? What is the best way to go?

many thanks

For the time being I am happy to have a register or simple way to store the phase and amplitude data.

kind regards,

John

Johnspark's picture
User
9 posts

 

 

Many Thanks in Advance!

Dear community, I have made some snail progress and have produced the following code as well as added a second DMA and VDAC_8 onto the *.cysch  page, as part of my developing the final solution:

 

#include

<device.h>

#define

 

TABLE_LENGTH 32

void

{

 

176,152,127,103,79,57,38,22,10,3,0,3,10,22,38,57,79,103};

 

 

 

 

 

main()uint8 sineTable[32] = {127,152,176,198,217,233,245,252,254,252,245,233,217,198,uint8 channel, channel_2; uint8 td,td_2; /* Start the DAC,PWM and enable the clock */

 

VDAC8_Start();

VDAC8_1_Start();

Timer_Start();

 

 

 

* Request per burst - 1 (every burst needs a new request

* High byte of source address = 0 (as SRAM is within 16 bit address space)

* High byte of Destination address = 0 (as it resides within 16 bit address space) */

#if (defined(__C51__))/* Initailize the DMA Channel will Burst count of 1 (to send 1 byte at a time)

 

channel = DMA_DmaInitialize(1, 1, 0, 0);

channel_2 = DMA_2_DmaInitialize(1,1,0,0);

 

 

#else

 

 

* Request per burst - 1 (every burst needs a new request

* High byte of source address = The upper 16 bits of source address is initialized with

* only one variable because the base address will be same for all the variables in the

* pattern and only the offset changes

* High byte of destination address = 0 (the UDB control register resides in 16 bit address space */

/* Initailize the DMA Channel will Burst count of 1 (to send 1 byte at a time)

 

channel = DMA_DmaInitialize(1, 1, HI16(sineTable), HI16(VDAC8_viDAC8__D) );

channel_2 = DMA_2_DmaInitialize(1, 1, HI16(sineTable), HI16(VDAC8_2_viDAC8__D) );

 

 

 

#endif /* Allocate the td with the channel that was allocated */

td = CyDmaTdAllocate();

td_2 = CyDmaTdAllocate();

 

 

/* Configure the td to transfer 32 bytes of data with auto increment of source address and no following TD */

CyDmaTdSetConfiguration(td, TABLE_LENGTH, td, TD_INC_SRC_ADR);

CyDmaTdSetConfiguration(td_2, TABLE_LENGTH, td_2, TD_INC_SRC_ADR);

 

 

/* Set the lower 16 bits of source address and the destination adddress */

CyDmaTdSetAddress(td, LO16((

CyDmaTdSetAddress(td_2, LO16((

 

 

uint32)sineTable), LO16((uint32)VDAC8_viDAC8__D) );uint32)sineTable), LO16((uint32)VDAC8_2_viDAC8__D) );/* Set tds to be the initial td associated with channel */

CyDmaChSetInitialTd(channel, td);

CyDmaChSetInitialTd(channel_2, td_2);

 

 

/* Enable the DMA channel */

CyDmaChEnable(channel, 1);

CyDmaChEnable(channel_2, 1);

 

 

 

(;;)

{

 

}

for

Would someone please help me get this second DMA channel (DMA_2) to read exactly the same look up table value as DMA channel one (DMA), and send to my second VDAC_8 called (VDAC_8_1) , the first VDAC_8 is still called (VDAC_8).  I am a novice at the moment, but will learn as time permits..

./main.c: In function 'main':

./main.c:93: error: 'VDAC8_2_viDAC8__D' undeclared (first use in this function)

The command 'arm-none-eabi-gcc.exe' failed with exit code '1'.

--------------- Build Failed: 10/25/2010 08:08:23 ---------------

 

dasg's picture
Cypress Employee
730 posts

Hi Johnspark,

 

Can you please post the error messages/ warnings you are getting while building this project?

 

Regards,

dasg

Johnspark's picture
User
9 posts

Hi Dasg,

I am now using 8 PWMs instead of 4 DACs but continue making snail progress. Have now read many PSoC articles as well as looked at lots of c forums, still making slow progress.

Currently, I have the following code with 2 errors and would greatly appreciate help to progress:

 

 I have a sine look up table with this in the header:

#define

 

 

 

 

 

 

 

 

SINE_TABLE_SIZE 65536

const  unsigned short  Sine_Table_unsigned_short[SINE_TABLE_SIZE];

 

I have this in the sine look up table c file:

 

#include "SineLut.h"

const

{

32768

unsigned short Sine_Table_unsigned_short[SINE_TABLE_SIZE] =

...

32761 ,

32764

};

/* [] END OF FILE */

I have this in the main.c file:

 DMA_1_TD[0] = CyDmaTdAllocate();

 

 

 

CyDmaTdSetConfiguration(DMA_1_TD[0],

 

sizeof(Sine_Table_unsigned_short), DMA_1_TD[0], TD_INC_SRC_ADR);// Set the source to be the waveform and the destination to be the PWM

CyDmaTdSetAddress(DMA_1_TD[0], (

 

unsigned short)Sine_Table_unsigned_short,(uint16)((uint16) PWM_1_COMPARE1_LSB_PTR));

 

 

and these are the 2 warning errors:

large implicitly truncated to unsigned type (for CyDmaTdSetConfiguration line)

cast from pointer to integer of different size (for CyDmaTdSetAddress line)

 

 

any help would be greatly appreciated Dasg,

cheers Johnspark

 

 

 

 

Johnspark's picture
User
9 posts

Dear All, I have managed to clear up the errors so thanks anyway on this post,

 

 

cheers JohnSpark

dasg's picture
Cypress Employee
730 posts

Hi Johnspark,

 

Can you please share with us the error which you were facing?

It will be helpful to all members.

 

Thanks in advance,

dasg

Log in to post new comments.