I have come across a piece of code on NXP website (ZIP file attched) which has been written for an LPC1700 micro controllers.
the software is very simple and aims to generate Audible medical alarms.
These micros family have a 10 bit DAC which means data buffer is 10 bit wide and can't take any value greater than 0x400.
looking at the code, file multi_tone_gen.c --> GenerateMultiTone (struct wave *t) ;
DAC->DACR = ((output >> 10) & 0xFFC0) + 0x8000; // make unsigned and output to DAC
When I run the code the input to DAC buffer is always greater than 0x400.
what am I missing here, am I just supposed to scale it down?
Note that I have ported this code into a PIC32 micro with 10 bit DAC module. it sounds the right melodies but it is not smooth. there is a roughness in the sound. when I scale down the input to the DAC buffer and lower it down to less than 0x400, the sounds get improved but still has that roughness in it.
Any idea what I am doing wrong?
regards,