Timing of DAC

17 Jan 2012

I want to write 8 bits raw to the dac no convert

17 Jan 2012

http://images4.wikia.nocookie.net/__cb20090208013646/stargate/images/2/22/MilkyWay.jpg

http://gifsoup.com/view7/2921216/milky-way-o.gif

20 Jan 2012

Gert van der Knokke wrote:

It is right when it sounds right, try taking one step at a time. So first get normal play working then concentrate on the reversal part. It works was talking about 8bits and changing Samux code

8 bit unsigned (0-255, level zero=128) can be written as 16 bit ((don't want to do will increase values)) to the dac after it has been shifted 8 positions to the left (or multiplied by 256)

8 bit signed (-127 to 127, level zero=0) must be converted first Why convert???? (add 128) and then shift 8 positions to the left again.???????????????????

Gert why are you talking to me in assemble language and not C or mbed language, I want write 8 bits only to the DAC...

at the moment I am using 8000khz 16bits problems better... but I want to write 8 bits at 8000khz...

at moment math is 125us 16bit 65535

I want lower 8000khz 125us 8bit -127 to 127 or 0 t0 255

21 Jan 2012

I am not talking assembler :-)

Shift/multiply is not assembly language as you can shift as easily in C as in assembler: 0xFF<<8 is a 255 shifted 8 places to left and then ends up being 0xFF00 or multiplied by 256...

Since the DAC has more bits than 8 you need to convert. NXP used a 10 bits DAC but reserved the lower 6 bits for future updates. With more bits you get more (finer) steps and adding bits is adding smaller steps (at the bottom end, not at the top).

To send 8 bits to the DAC you need to multiply to get a 16 bit result of which the top 10 bits are used. If you do not shift/multiply your 8 bits are reduced to only 2 bits if you write them to the DAC. I do not know if it is possible to write just the top byte of the DAC

21 Jan 2012

Gert van der Knokke wrote:

I am not talking assembler :-)

Shift/multiply is not assembly language as you can shift as easily in C as in assembler: 0xFF<<8 is a 255 shifted 8 places to left and then ends up being 0xFF00 or multiplied by 256...

Quote:

Since the DAC has more bits than 8 you need to convert. NXP used a 10 bits DAC but reserved the lower 6 bits for future updates. With more bits you get more (finer) steps and adding bits is adding smaller steps (at the bottom end, not at the top).

Quote:

To send 8 bits to the DAC you need to multiply to get a 16 bit result of which the top 10 bits are used. If you do not shift/multiply your 8 bits are reduced to only 2 bits if you write them to the DAC. I do not know if it is possible to write just the top byte of the DAC

So if I shift 5 bits 0xFF<<5 I would get a 10 bit result, I now want to write 10 bit results only. 10bit 0xFF<<2 is 8bits?????

22 Jan 2012

Gert van der Knokke wrote:

I am not talking assembler :-)

Shift/multiply is not assembly language as you can shift as easily in C as in assembler: 0xFF<<8 is a 255 shifted 8 places to left and then ends up being 0xFF00 or multiplied by 256...

Since the DAC has more bits than 8 you need to convert. NXP used a 10 bits DAC but reserved the lower 6 bits for future updates. With more bits you get more (finer) steps and adding bits is adding smaller steps (at the bottom end, not at the top).

To send 8 bits to the DAC you need to multiply to get a 16 bit result of which the top 10 bits are used. If you do not shift/multiply your 8 bits are reduced to only 2 bits if you write them to the DAC. I do not know if it is possible to write just the top byte of the DAC

So this is what is being done in the code already http://mbed.org/handbook/USBAudio

but I don't want to multiply, I just want to send 8bits or just 10 bits so is it 0xFF<<4 but I can't work out where samux is multiplying in his code which makes no sense to me the way he has chosen to code it anyway, does not make good mathematical sense to me, in fact it seems like confusing coding to me, but not that I know much about coding yet.

I want to receive a 8 bit resolution from the pc, the way you describe things in maths to make sense to me would be if I want to send bits to the computer, I don't understand if I am receiving 16 bits from a computer why would I need to multiply, I would need to divide right??

we are talking about the usb protical here, do you know the usb protocol, it just we have been talking for ages about this and it makes me think that you don't know that much about usb and you are talking of your experience with other protocols???

24 Jan 2012

With 16 bits unsigned audio data you do not need to multiply or divide anything, maybe only mask off the bottom(!) 6 bits. The DAC register is 16 bits where the top(!) 10 bits are valid and the lower 6 bits are for future expansion.

I have used the DAC of the mbed in my SP0256 speech synthesizer emulator and it works fine for me (in 8, 10 or 16 bit mode).

25 Jan 2012

Well I want to shrink the code, by using 8 bits and 8000khz in hope to solve the clicks at 125us ... this is why I don't want to multiply??

// USBAudio speaker example

#include "mbed.h"
#include "USBAudio.h"

// frequency: 48 kHz
#define FREQ 48000

// 1 channel: mono
#define NB_CHA 1

// length of an audio packet: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there is one channel, the length will be 48 * 2 * 1
#define AUDIO_LENGTH_PACKET 48 * 1 * 1

#define USR_POWERDOWN    (0x104)

int semihost_powerdown() {
    uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg);
}
 

// USBAudio
USBAudio audio(FREQ, NB_CHA, 0x7175, 0x7535);

// speaker connected to the AnalogOut output. The audio stream received over USb will be sent to the speaker
AnalogOut speaker(p18);

// ticker to send data to the speaker at the good frequency
Ticker tic;

// buffer where will be store one audio packet (LENGTH_AUDIO_PACKET/2 because we are storing int16 and not uint8)
uint8_t buf[AUDIO_LENGTH_PACKET];

// show if an audio packet is available
volatile bool available = false;

// index of the value which will be send to the speaker
int index_buf = 0;

// previous value sent to the speaker
uint8_t p_val = 0;

// function executed each 1/FREQ s
void tic_handler() {
    float speaker_value;
    unsigned short PlaySample;


    if (available) {
        //convert 2 bytes in float
        speaker_value = (float)(buf[index_buf]);
        
        // speaker_value between 0 and 65535
        speaker_value += 32768.0;

        // adjust according to current volume
        speaker_value *= audio.getVolume();
        
        // as two bytes has been read, we move the index of two bytes
        index_buf++;
        
        // if we have read all the buffer, no more data available
        if (index_buf == AUDIO_LENGTH_PACKET) {
            index_buf = 0;
            available = false;
        }
    } else {
        speaker_value = p_val;
    }
    
    p_val = speaker_value;
    
  // send value to the speaker
speaker.write(speaker_value);
}

int main() {

semihost_powerdown();

    // attach a function executed each 1/FREQ s
    tic.attach_us(tic_handler, 1000000.0/(float)FREQ);

    while (1) {
        // read an audio packet
        audio.read((uint8_t *)buf);
        available = true;
    }
}

you see trying to write as float

// Audio Type I Format
        FORMAT_TYPE_I_DESCRIPTOR_LENGTH,        // bLength
        INTERFACE_DESCRIPTOR_TYPE,              // bDescriptorType
        STREAMING_FORMAT_TYPE,                  // bDescriptorSubtype
        FORMAT_TYPE_I,                          // bFormatType
        channel_nb,                             // bNrChannels
        0x01,                                   // bSubFrameSize
        8,                                     // bBitResolution
        0x01,                                   // bSamFreqType
        LSB(FREQ >> 3) & 0xff,                              // tSamFreq
        (FREQ >> 8) & 0xff,                     // tSamFreq
        (FREQ >> 16) & 0xff,                    // tSamFreq

It no work yet, I know is lots of things that need to and can be done I just want to do this first.

Why don't you just do it for me Gert

this is the code

http://mbed.org/users/samux/programs/USBAUDIO_speaker/m1h5sc

load it in the complier I don't want unwanted values or code in my code tho:) If I could I would do this all in assembly code