Arduino Controlled Ampli Waveform Generator

Hi all,

Just wanted a little bit of feedback about a project idea I have that I am thinking about doing.

Basically I want to make a test box that puts out a few custom (not normal sine or square wave) amplified waveforms that are programmed in to the Arduino.

Would the best way to do this be to use an Arduino Duo/Zero with the build in DAC, program in the custom waveform then take the output on the DAC pins and amplify it.

Can you think of any issues I might come across when doing this/general advice.

Thanks,
vedya

The Due should work. Since non-sine waves contain higher frequency harmonics, you'll need a sample-rate greater than the [u]Nyquist Limit[/u].

Thanks Doug. I think I maybe be using a Zero as they are available here but it also has a DAC so I think I'll be okay.

I have another question. How would one write a non standard waveform into the arduino programming software. I saw some code for a sine wave before and it looked like just graph like plots. How would I go from knowing what I want it to look like to writing it in...

Thanks for any help you can provide all

Put your strange waveform into an array eg waveform[] and clock it out in the loop()..

regards

Allan

Like this "Simple Waveform Genetator" :slight_smile:

Leo..

allanhurst:
Put your strange waveform into an array eg waveform[] and clock it out in the loop()..

regards

Allan

Hi Allan,

How do I get started on turning a rough idea of how the waveform should look into an array?

Many thanks

For example - I needed sines and cosines for a recent project, so I put the values for each degree scaled 0..255 into arrays...

  unsigned char sinA [] = 
{0, 4, 8, 13, 17, 22, 26, 31, 35, 39, 44, 48, 53, 57, 61, 65, 
70, 74, 78, 83, 87, 91, 95, 99, 103, 107, 111, 115, 119, 123, 
127, 131, 135, 138, 142, 146, 149, 153, 156, 160, 163, 167, 
170, 173, 177, 180, 183, 186, 189, 192, 195, 198, 200, 203, 
206, 208, 211, 213, 216, 218, 220, 223, 225, 227, 229, 231, 
232, 234, 236, 238, 239, 241, 242, 243, 245, 246, 247, 248, 
249, 250, 251, 251, 252, 253, 253, 254, 254, 254, 254, 254, 255};

  unsigned char cosA [] = 
{255, 254, 254, 254, 254, 254, 253, 253, 252, 251, 251, 250, 
249, 248, 247, 246, 245, 243, 242, 241, 239, 238, 236, 234, 
232, 231, 229, 227, 225, 223, 220, 218, 216, 213, 211, 208, 
206, 203, 200, 198, 195, 192, 189, 186, 183, 180, 177, 173, 
170, 167, 163, 160, 156, 153, 149, 146, 142, 138, 135, 131, 
127, 123, 119, 115, 111, 107, 103, 99, 95, 91, 87, 83, 78, 
74, 70, 65, 61, 57, 53, 48, 44, 39, 35, 31, 26, 22, 17, 13,
8, 4, 0};

eg The sines and cosines are for 0..90 degrees - if I were to send each successive value to an 8-bit DAC at equal intervals I'd get the 1st 90 degrees of a sin/cos waveform in 90 steps.

I didn't need -ve values - but that's detail...

regards

Allan

allanhurst:
For example - I needed sines and cosines for a recent project, so I put the values for each degree scaled 0..255 into arrays...

  unsigned char sinA [] = 

{0, 4, 8, 13, 17, 22, 26, 31, 35, 39, 44, 48, 53, 57, 61, 65,
70, 74, 78, 83, 87, 91, 95, 99, 103, 107, 111, 115, 119, 123,
127, 131, 135, 138, 142, 146, 149, 153, 156, 160, 163, 167,
170, 173, 177, 180, 183, 186, 189, 192, 195, 198, 200, 203,
206, 208, 211, 213, 216, 218, 220, 223, 225, 227, 229, 231,
232, 234, 236, 238, 239, 241, 242, 243, 245, 246, 247, 248,
249, 250, 251, 251, 252, 253, 253, 254, 254, 254, 254, 254, 255};

unsigned char cosA [] =
{255, 254, 254, 254, 254, 254, 253, 253, 252, 251, 251, 250,
249, 248, 247, 246, 245, 243, 242, 241, 239, 238, 236, 234,
232, 231, 229, 227, 225, 223, 220, 218, 216, 213, 211, 208,
206, 203, 200, 198, 195, 192, 189, 186, 183, 180, 177, 173,
170, 167, 163, 160, 156, 153, 149, 146, 142, 138, 135, 131,
127, 123, 119, 115, 111, 107, 103, 99, 95, 91, 87, 83, 78,
74, 70, 65, 61, 57, 53, 48, 44, 39, 35, 31, 26, 22, 17, 13,
8, 4, 0};




eg The sines and cosines are for 0..90 degrees - if I were to send each successive value to an 8-bit DAC at equal intervals I'd get the 1st 90 degrees of a sin/cos waveform in 90 steps.

I didn't need -ve values - but that's detail...

regards

Allan

I see, thanks for the information.

I have converted some waves to 0-255 values.

How does this translate over to programming it into an arduino. Like for example, this is one for an arduino due signal generator...

'// Triangular wave
{
0x44, 0x88, 0xcc, 0x110, 0x154, 0x198, 0x1dc, 0x220, 0x264, 0x2a8,
0x2ec, 0x330, 0x374, 0x3b8, 0x3fc, 0x440, 0x484, 0x4c8, 0x50c, 0x550,
0x594, 0x5d8, 0x61c, 0x660, 0x6a4, 0x6e8, 0x72c, 0x770, 0x7b4, 0x7f8,
0x83c, 0x880, 0x8c4, 0x908, 0x94c, 0x990, 0x9d4, 0xa18, 0xa5c, 0xaa0,
0xae4, 0xb28, 0xb6c, 0xbb0, 0xbf4, 0xc38, 0xc7c, 0xcc0, 0xd04, 0xd48,
0xd8c, 0xdd0, 0xe14, 0xe58, 0xe9c, 0xee0, 0xf24, 0xf68, 0xfac, 0xff0,
0xfac, 0xf68, 0xf24, 0xee0, 0xe9c, 0xe58, 0xe14, 0xdd0, 0xd8c, 0xd48,
0xd04, 0xcc0, 0xc7c, 0xc38, 0xbf4, 0xbb0, 0xb6c, 0xb28, 0xae4, 0xaa0,
0xa5c, 0xa18, 0x9d4, 0x990, 0x94c, 0x908, 0x8c4, 0x880, 0x83c, 0x7f8,
0x7b4, 0x770, 0x72c, 0x6e8, 0x6a4, 0x660, 0x61c, 0x5d8, 0x594, 0x550,
0x50c, 0x4c8, 0x484, 0x440, 0x3fc, 0x3b8, 0x374, 0x330, 0x2ec, 0x2a8,
0x264, 0x220, 0x1dc, 0x198, 0x154, 0x110, 0xcc, 0x88, 0x44, 0x0
}'

How do I go from like 6, 12, 24 to like 0x44, 0xcc etc?

The compiler understands both decimal and hexadecimal (0x...) representation of numbers, no need to change anything.

You can use e.g. the Windows Calculator in Programmer view, to convert between decimal and hex numbers. Then you'll find out that e.g. 0xff0=4080, what does not fit into a byte. If the DAC has 12 bits, adjust your amplitude values to the 0-4095 range.