Hi, I'm trying to add a PIT or LPTMR to make my sawtooth signal 1khz (currently is less than 1hz) im working with a KL25z and dont have much experince
/* p7_4.c: Use DAC to generate sawtooth waveform
* The DAC is initialized with no buffer and use software trigger,
* so every write to the DAC data registers will change the
analog output.
* The loop count i is incremented by 0x0010 every loop. The
12-bit DAC
* has the range of 0-0x0FFF. Divide 0x1000 by 0x0010 yields
0x0100 or 256.
* The sawtooth has 256 steps and each step takes 1 ms. The
period of the
* waveform is 256 ms and the frequency is about 3.9 Hz.
*/
void DAC0_init(void);
void delayMs(int n);
int main (void ){
int i;
DAC0_init(); /*configure DAC0*/
while(1){
for(i=0;i<0x1000;i+=0x0010){
DAC0->DAT[0].DATL=i&0xff; /*write low bye*/
DAC0->DAT[0].DATH=(i>>8)&0x0f; /*write high bye*/
delayMs (1); /*delay 1ms*/
}
}
}
void DAC0_init(void){
SIM->SCGC6 |=0x80000000; /*clock to DAC module*/
DAC0->C1=0; /*disble the user of buffer*/
DAC0->C0=0X80|0X20; /*enable DAC and use software trigger*/
}
/*Delay n miliseconds
*The CPU core clock is set to MCGFLILCLH at 41.94 MHZ in SystemInit().
*/
void delayMs (int n){
int i;
int j;
for(i=0; i<n;i++)
for(j=0;j<7000;j++){}
}
Hi, may be those articles can help you https://os.mbed.com/media/uploads/GregC/an4470-using_low-power_modes_with_kinetis_mcus.pdf
https://spivey.oriel.ox.ac.uk/dswiki/images-digisys/5/56/KL25-refman.pdf, https://comm.eefocus.com/media/download/index/id-1009420
Have a good day