10 years, 4 months ago.

DAC MCP4821 and NXP 11U24 : How to increase frequency of output

I have been using MCP4821 for a while now , I have managed to get it to correctly output a signal , but after rigorous tweaking and analysis I ve only managed to take it from 15 hz to 1 khz of frequency . Is this the limit ? Does anybody know a way to increase my output to say 20 mhz ?

test.cpp

#include "mbed.h"
#include "BurstSPI.h"




int main()
{
    Serial pc(USBTX, USBRX);
    AnalogIn Vin(p18);
    DigitalOut CS(p35);
    DigitalOut LDR(p30);
    int output=0x0000 ;
    int next=1;
    int i=0;
    BurstSPI device(p5, p6, p7); // mosi, miso, sclk
    device.format(16,0);
    device.frequency(48000000);
    device.setFormat();
    int data=0x0000;
    LDR=1;
  
    while(1) {
        CS=0;
   
        data=output|0x3000;
        device.fastWrite(data);
        device.clearRX();
        
        CS=1;
        if (next==1){
           output=output+0x000F;
        }
        else if (next==2){
           output=output-0x000F;
        }
        if (output>=0x0fff) {
            //output=0x0000;
            next=2;
        }
        else if (output<=0x0000){
            next=1;
        }
        i++;
        LDR=0;
        LDR=1;
       
    }
}
posted by Antreas Antoniou 20 Dec 2013

The LPC11u24 can't get higher than 24MHz (your DAC also not, so that's not an issue. Also while I like people using my libraries, in this case BurstSPI doesn't make it go faster: BurstSPI is intended for situations where ALOT is written without toggling CS. For example a regular LCD writes 153kB without raising/lowering its CS pin. Writing one word and then waiting until it is done with that won't be faster than using regular SPI.

There are some options to make it go faster. But most important two questions:

When you say 15Hz-1kHz, do you mean the speed it outputs values, or the time it takes to finish a complete period of your triangle wave. Question 2: What are your requirements. So we can judge if they are realistic on the LPC11u24.

posted by Erik - 21 Dec 2013

Firstly when I say 15hz-1khz I mean the actual output of the signal when measured with an osciloscope . And second my requirements are to take it to at least 10 khz as I will be also reading and analysing some signals at the same time having this one at a greater frequency can ensure that it won't become extremely slow when I add the extra functionality . Also I would like to ask , is there any chance 11u24 can support multi-threading ? or not . If not how about its big bro NXP 1768??

posted by Antreas Antoniou 21 Dec 2013

Well the easiest option to increase your speed is to make your ramps using larger steps, now you add 0x0F for each step, increasing that makes it go faster.

With multi-threading, you can look at the RTOS (search for it here), it allows you to have several threads which all do their own thing. However there is still only one physical core, so it will not be able to actually do several things in parallel. Same for the LPC1768. There are some multi-core microcontrollers, for example from NXP one with an M0 core in parallel to an M4 core, but generally that isn't really required, or you simply put two microcontrollers in parallel.

posted by Erik - 21 Dec 2013

Yes , thats exactly why I have 0x000f so that I increase the speed from the original 0x0001 stepping . Thanks for your input . Already found multi threading technique . Also if there is any other option to increase speed other than stepping please don't hesitate to share. Thanks once more

posted by Antreas Antoniou 21 Dec 2013

The SPI module can also toggle a pin as CS pin automatically. I am not sure that pin is available on the LPC11u24, but for sure it would mean you need to do some manual writing to registers. If you are comfortable with that you can look in the user manual which registers you need for that.

posted by Erik - 21 Dec 2013

2 Answers

10 years, 4 months ago.

The SPI lib should be able to go to pretty high frequencies for SCK, but toggling the CS line using the DigitalOut method may be a limiting factor on the relatively slow 11U24. DMA could improve the update speed. Could you publish your code to see what else may be done.

Accepted Answer

Thanks for your prompt response , my code is now published on top.

posted by Antreas Antoniou 20 Dec 2013
10 years, 4 months ago.

You will got nowhere near 20MHz. That simply is way outside the abilities of the LPC11u24 to send (or hell any device to send using SPI), and outside the capabilities of the MCP4821.

That said, it should be do-able to get alot faster than 1kHz, so like Wim said, could you show your code.

Thanks for your prompt response , my code is now published on top.

posted by Antreas Antoniou 20 Dec 2013