10 years, 8 months ago.

Is there any way to control the speed of DAC or to modify the speed of the AnalogOut?

Please if anybody can, send mi some code that can increase the speed of the DAC. Thanks in advance

1 Answer

10 years, 8 months ago.

Dear Rolando-san,

I have tried similar thing please check my funcgen

https://developer.mbed.org/users/Rhyme/code/funcgen/

Although I have tested this only with FRDM-KL25Z, as analog out is same PTE30, it may work with FRDM-KL46Z.

Please let me know if it works ok on your board.

IMHO, we can not make DAC faster, but we can make it look slower, in my case with FRDM-KL25Z, I could make the timer interval as fast as 25us and logically there won't be any limit for the slower interval.

Best Regards, 14-Jan-2015 moto

Dear Motoo

Thanks very very much for your answer and for to send me your hard and important

works that I'll see, study and probe with my FRDM-KL-46Z, sending you the results . Please, if it's possible I wish that you send me your e-mail for comunicate us more

directly; this is mine; 'rolandosr013@hotmail.com'.This is my code for a DAC too fast, but

with it I havent'n results(nothing appear in PTE30 and I do'nt know were is

'DACREF_1.!!!), please analyze it you and tell me whats strong.

Regards and thanks in advance dear friend!.

FastAnalogOut

  1. include "mbed.h"
  2. include "clk_freqs.h"
  1. define MAX_FADC 6000000
  2. define CHANNELS_A_SHIFT 5
  3. define SIM_SCGC6_DAC0_MASK 0x80000000u
  4. define DAC_DATH_DATA0_MASK 0xF
  1. ifdef TARGET_K20D50M static const PinMap PinMap_DAC[] = { {PTE30, DAC_0,STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0}),DAC out {NC, NC, 0} };
  2. endif

void inicio(PinName , bool); void enable(bool enabled = true); void disable( void ); void write (uint16_t ); char DACnumber; bool enabled;

uint16_t LH=0;

int main(){

inicio(PTE30, true);

while(1) {

LH = LH++; enable(true); write(LH); wait(0.1); if(LH == 100) { LH = 0; } } }

void inicio(PinName pin, bool enabled){

DACnumber = (DACName)pinmap_peripheral(pin, PinMap_DAC);

if (DACnumber == (DACName)NC) { error("DAC pin mapeado fallido"); }

SIM->SCGC6 |= SIM_SCGC6_DAC0_MASK;

SIM->SCGC5 |= 0x2000;

uint32_t PCLK = bus_frequency(); uint32_t clkdiv; for (clkdiv = 0; clkdiv < 4; clkdiv++) { if ((PCLK >> clkdiv) <= MAX_FADC) break; } if (clkdiv == 4) clkdiv = 0x7;

pinmap_pinout(pin, PinMap_DAC);

enable(enabled);

}

void enable(bool enabled){

if(enabled) { DAC0->C0 |= DAC_C0_DACEN_MASK ; }else disable();

}

void disable( void ) { if (!enabled) { DAC0->C0 &= DAC_C0_DACEN_MASK; } }

void write (uint16_t valor) { DAC0-> DAT[1].DATL &= 0x00; DAC0-> DAT[1].DATH &= 0x00; uint16_t temp= valor;

DAC0-> DAT[1].DATL |= (valor & 0xFF); DAC0-> DAT[1].DATH |= ((temp>>8)& 0xF);

temp=0;

Serial tt(USBTX,USBRX); tt.printf("DATL %d, DATH= %d ", DAC0-> DAT[1].DATL, DAC0-> DAT[1].DATH);

}

posted by Rolando RERIANI 14 Jan 2015

I have just tried my funcgen program with FRDM-KL46Z.

Without any modification, except switching the platform from FRDM-KL25Z to FRDM-KL46Z, it worked fine!

I think this is the virtue of "mbed".

With FRDM-KL46Z, my program could generate up to 13300Hz,
but when freq hit 13350 Hz, output stayed as DC level.

To make it simple, I have just hacked a sample program.
Following program is generating about 40Hz saw wave on my FRDM-KL46Z now.

#include "mbed.h"

DigitalOut led(LED_RED);

int sample_time = 25 ; 
AnalogOut aout(PTE30) ;
Ticker *timer ;

#define DAC_MAX 1.0
#define DAC_MIN 0.0
float dac_value = 0.0 ;
float dac_delta = 0.001 ;

void tick_time(void)
{
    aout = dac_value ;
    dac_value += dac_delta ;
    if (dac_value >= DAC_MAX) {
        dac_value = DAC_MIN ;
    }
}

int main()
{
    timer = new Ticker() ;
    timer->attach_us(&tick_time, sample_time) ;
    
    while (true) {
        led = !led; // toggle led
        wait(0.2f);
    }
}
posted by Motoo Tanaka 14 Jan 2015