KL25z sawtooth wave of 1khz

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KL25z sawtooth wave of 1khz

865 Views
Dom051
Contributor I

Hi I have this code showing a sawtooth wave less than 1hz and I am trying to make it 1khz on my Kl25z, what can I change?

void DAC0_init(void);
void delayMs(int n);

int main (void ){
    int i;
    DAC0_init();
    while(1){
         for(i=0;i<0x1000;i+=0x0010){
             DAC0->DAT[0].DATL=i&0xff;
             DAC0->DAT[0].DATH=(i>>8)&0x0f;
             delayMs (1);

        }
     }
}

void DAC0_init(void){
                  SIM->SCGC6 |=0x80000000;
                  DAC0->C1=0;
                  DAC0->C0=0X80|0X20;

}

void delayMs (int n){
       int i;
       int j;
       for(i=0; i<n;i++)
            for(j=0;j<7000;j++){}

}

0 Kudos
Reply
3 Replies

857 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @Dom051 ,

You can use a timer to help you, for example, PIT or LPTMR.

In a 1ms period, you can divide it into 100 part. Then timer will generate interrupt every 0.01ms. In timer interrupt service routing, you put a new DAC value.

 

Regards,

Jing 

845 Views
Dom051
Contributor I

How can I do that?, I'm new to using c++

0 Kudos
Reply

774 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @Dom051 ,

Please refer to the PIT or LPTMR demo in SDK. Both of them will generate interrupt.  You can put your DAC code in interrupt.

 

Regards,

Jing

0 Kudos
Reply