Q: How can I generate audio tones using PSoC4?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

This one may be a simple question to answer. I am interested in generating tones, much like notes on a piano, that I can use in a program that I am writing.

   

 

   

I am not asking anyone to write the code for me, just point me in the right direction - using Creator 3.0 - and off I will go, writing code and making beautiful (hopefully) noises from a PSoC4.

   

 

   

If it works with the PSoC4 Pioneer Kit - even better, because that's what I am using for my 'dev kit'.

   

 

   

Thanks.

   

 

   

James

0 Likes
18 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

There is a WaveDAC-component that sends a pre-defined table to a digital-to-analog converter using DMA. Getting harmonic tones is a bit more complicated, but here's the hint: Two half-toned differ by the factor of the 12th root of 2 from each other.

   

There was a project shown recently generating random tones, you may watch it here. http://www.cypress.com/?app=forum&id=2492&rID=86654 

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is an approach that may be of interest, basically an IIR filter

   

with + fdbk. Keep in mind table lookup suffers from limited speed.

   

The approach, however, needs more work to be flexible, but for

   

simple tone generation suitable.

   

 

   

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

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 Bob,

   

 

   

If you are referring to the WaveDAC8... I am not sure that that works. Have you (or anyone else) actually used it with a PSoC4?

   

 

   

I get compile errors.

   

 

   

Plus, looking at the Device Selector - the PSoC3 and the PSoC5LP have 8-Bit DACs in their columns... the PSoC4 does not.

   

 

   

I believe that the WaveDAC8 will not work with the PSoC4, but I may be wrong.

   

 

   

Thanks for the suggestions so far. It looks like it isn't as simple as my last microprocessor I was using... or I may be overcomplicating it.

   

 

   

Regards,

   

 

   

James

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

PSoC4 is a rather small device, use PWM instead under CPU-controll to generate tunes or use a PSoC5 with DMA

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

PSOC 4 is more than adequate to do tone generation. Its has DACs, and you can still do table

   

lookup generated tones with no DMA, just use timed ISR which sets sample rate, hence frequency.

   

And using table lookup you can do tones with complex harmonics. SAW, TRI, RAMP......

   

 

   

Or use its fast single 32 bit multiplier and do a digital approach. Or the IIR approach mentioned

   

earlier. Note multiplier allows modulation, and then there is the approach Kamil is using on forum

   

yielding very complex tones, JLS1 on forum. Karrplus Strong approach.

   

 

   

Regards,. Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is a project Kamil did for PSOC 4 -

   

 

       

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

   

 

   

Regards, Dana.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

The WaveDAC8 component relies on DMA, and the PSoC4 doesn't have any of that. So you need to do this manually.

0 Likes
Anonymous
Not applicable
        Hi Jim-TX, Oh Jim-TX you are   
PSoC4 is insufficient resources to produce audio but   
Pioneer-Kit can do it, it has a Extra great PSoC5LP.   
Did you see this thread?   
http://www.cypress.com/?app=forum&id=2492&rID=86654   
There are many actual samples and YouTube video   
However that sound is so random and fuzzy.   
Last sample is able to control the PSoC5LP from PSoC4 capsense.   
I do not recommand Wave-DAC   
It is too young, it has stall soon when I used it.   
0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is a very simple approach to tone generation, classic table lookup.

   

Could be driven by timer and ISR to control freq. In this example, 48 Mhz clock

   

sine wave = 12.5 Khz

   

 

   

#include <project.h>

 const uint8 sinetable[ 32 ] = {     127, 152, 176, 198, 217, 233, 245, 252,
                                    254, 252, 245, 233, 217, 198, 176, 152,
                                    128, 103,  79,  57,  38,  22,  10,   3,
                                      0,   3,  10,  22,  38,  57,  79, 103 };

uint8 sineptr = 0;

int main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    IDAC8_Start( );
   
   
   
    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
    for(;;) {

        IDAC8_SetValue( (uint32) sinetable[ sineptr++ ] );   
        if ( sineptr == 32 ) sineptr = 0;
    }
}

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

HW looked like this -

   

 

   

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you wrote code in ASM probably much higher freq and/or use a

   

finer (bigger) sine table at same freq.

   

 

   

There are many methods of generating tones, and with the onboard single

   

cycle multiplier filter (IIR) / modulate them.

   

 

   

PSOC 4 has plenty of resources for tone generation and modulation.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

To generate an instrument type tone (a basic type only, you need more for high quality simulation)

   
    You need to know   
   
     1.       The relative amplitudes of the base frequency and the harmonics   
   
     2.       For a string type note, you also need to know the envelope of the tone; normally it is referred to Attack, Decay, Sustain and Release phase of the note.   
   
     3.       When playing the tone, you also need to know the duration as well as the volume of the tone   
0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Attached is an IIR based sinewave generator, ~ 8 Khz.

   

 

   

This could benefit from conversion to a fixed point solution, and/or ASM codeing.

   

Also placing multiplier in loop for modulation.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is a third way to generate sine, via PWM. Note I used

   

a UDB, you could have used timer/PWM block instead.

   

 

   

So in short 3 methods -

   

 

   

1) Table lookup to DAC

   

2) IIR with + fdbk to DAC

   

3) PWM to pin/RC filter

   

 

   

And of course always classical methods using the OpAmps, Wien Bridge,

   

BiQuad.......

   

 

   

Regards, Dana.

   

 

   

0 Likes
Anonymous
Not applicable

Not exactly what you are looking for, but for another idea:

   

 You may be also interested to check out the PSoC 4 1-bit audio example from the 100-projects-in-100-days initiative here:

   

http://www.element14.com/community/message/84171#84171/l/psoc-4-pioneer-kit-community-project057-dig...

   

Cheers,

   

Antonio

0 Likes
Anonymous
Not applicable

 And Jim,

   

I almost forgot - here's another PSoC 4 audio example (a theremin) from the 100-days initiative. 

   

http://www.element14.com/community/message/77464#77464/l/psoc-4-pioneer-kit-community-project16--pro...

   

This one uses a PWM to generate tones/notes. In fact, in 'Discrete' mode, the theremin actually plays the notes of a scale!

   

The firmware should be well commented and pretty instructive.

   

All the best, and let us know how your piano sounds!

   

Antonio

0 Likes
Anonymous
Not applicable

 Dana,

   

 

   

Thanks for working on this. The last example you posted using the PWM component works very well for what I need it to do.

   

 

   

I will probably add a for loop, and use that to play 5 different tones, and I'm done.

   

 

   

Thanks again.

   

 

   

Regards,

   

 

   

James Jackson

   

Oztronics

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

One additional thought on this.

   

 

   

The PWM approach has the biggest drawback of harmonic distortion,

   

and requires more stringent LPF filtering than a table lookup or IIR

   

approach.

   

 

   

Regards, Dana.

0 Likes