HI,
I tried to send signal with DAC in fixed times using PIT timer interrupt (the value of the signal is changing as the PIT interrupt occur). I configured the PIT timer to interrupt in each 1ms and what I get in oscilloscope which test the signal is
that the signal is changed in any 5ms and not 1ms as i thought.
here is the setting of the the clocks, DAC and the PIT Interrupt.
please tell me if something with my setting is wrong
void InitPIT(){
SIM_SCGC6 |= SIM_SCGC6_PIT_MASK; //Enable the Clock to the PIT Modules
// Timer 0
PIT_LDVAL0 = 0x0000BB80; // setup timer 0 for 1msec counting period
PIT_TCTRL0 = PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK; //enable PIT0 and its interrupt
PIT_MCR |= PIT_MCR_FRZ_MASK; // stop the pit when in debug mode
enable_irq(INT_PIT-16); // //Enable PIT IRQ on the NVIC
set_irq_priority(INT_PIT-16,0); // Interrupt priority = 0 = max
}
void InitDAC(){
//When the DAC is enabled and the buffer is not enabled,
//the DAC module always converts the data in DAT0 to analog output voltage.
// pin PTE30 is by default (ALT0) configured as DAC0_OUT
//VDDA reference voltage (Use this option for the best ADC operation).
SIM_SCGC6 |= SIM_SCGC6_DAC0_MASK; //DAC0 Clock Gate Control
DAC0_C0 |= DAC_C0_DACEN_MASK + DAC_C0_DACRFS_MASK + DAC_C0_DACTRGSEL_MASK + DAC_C0_LPEN_MASK;
}
void PIT_IRQHandler(){
if (state==2){ //if state=2 deliver signal out will enter each 1ms (I don't know why the scope show 5ms)
sampleNumOut=sampleNumOut%41;
DAC0_DAT0H = ((int)samplesArray[sampleNumOut] & 0xF00)>> 8; //deliver the signal of the DAC out (DAT0H=DAC DATA High Register)
DAC0_DAT0L = (int)samplesArray[sampleNumOut] & 0x0FF; //deliver the signal of the DAC out (DAT0L=DAC DATA LOW Register)
sampleNumOut++;
}
// When software trigger is selected, a conversion is initiated following a write to SC1A
ADC0_SC1A = POT_ADC_CHANNEL | ADC_SC1_AIEN_MASK; //here for other purpose.
PIT_TFLG0 = PIT_TFLG_TIF_MASK; //clear the Pit 0 Irq flag
}
thank you
Hi Ofir
PIT module take bus speed as the reference clock, How do you have setup the bus speed? depending on this speed, you will have to load a value to PIT_LDVAL0. Also, I didn't see where you are clearing the MDIS bit of the PIT_MCR register, this field must be enabled before any other setup is done.
Best regards
Jorge Alcala