Hi all,
I am trying read a PWM signal's DC and period using the TCC modules as I have never used them and want to give them a go. Using MPLAX and Harmony to generate the code and from my understanding I can use TCC0_WO0 (PA4) and TCC0_WO1(PA5) as inputs and then just read the CC0 and CC1 values which should give me the DC and T. Datasheet is confusing me between input, channels, events, capture all meaning different things but not really sure how they are different. Anyhow the code below is the barebones of what I wanted to do but interestingly enough I am getting a PWM signal OUT of these pins
. I have checked that all the registers are configured correctly and cannot find anything wrong with them besides TCC0_REGS->TCC_EVCTRL = TCC_EVCTRL_TCEI1_Msk.. which is not shown in the TCC part of the datasheet but it is under the TC part. I have tried removing this part with no change on the behavior. Reaching out to you experts out there to see what I am doing wrong
Thanks anyway!
int main ( void )
{
/* Initialize all modules */
SYS_Initialize ( NULL );
// Register callback function for CH0 period interrupt
TC4_TimerCallbackRegister(TC4_CH4_TimerInterruptHandler, (uintptr_t)NULL);
// Start the timer channel 0
TC4_TimerStart();
uint32_t capture_status,cc0,cc1,count;
//TCC0_CaptureCallbackRegister(TCC0_CH1_InterruptHandler,(uintptr_t)NULL);
//TCC0_CaptureStart();
//TCC DISABLE
TCC0_REGS->TCC_CTRLA = 0;
while((TCC0_REGS->TCC_SYNCBUSY & TCC_CTRLA_ENABLE_Msk) != 0U)
{
/* Wait for Write Synchronization */
}
TCC0_REGS->TCC_CTRLA = TCC_CTRLA_SWRST_Msk; //TCC_CTRLA=0x00000001 Reset all TCC registers
//CLK_TCC0_APB was configured in CLOCK_Initialize();
while((TCC0_REGS->TCC_SYNCBUSY & TCC_SYNCBUSY_SWRST_Msk) == TCC_SYNCBUSY_SWRST_Msk)
{
/* Wait for Write Synchronization */
}
/* Configure prescaler, standby & capture mode */
TCC0_REGS->TCC_CTRLA = TCC_CTRLA_PRESCALER_DIV1 | TCC_CTRLA_PRESCSYNC_PRESC
| TCC_CTRLA_CPTEN0_Msk | TCC_CTRLA_CPTEN1_Msk
;
TCC0_REGS->TCC_EVCTRL = TCC_EVCTRL_TCEI1_Msk | TCC_EVCTRL_EVACT1_PWP | TCC_EVCTRL_MCEI0_Msk | TCC_EVCTRL_MCEI1_Msk;
/* Clear all interrupt flags */
TCC0_REGS->TCC_INTFLAG = TCC_INTFLAG_Msk;
while((TCC0_REGS->TCC_SYNCBUSY) != 0U)
{
/* Wait for Write Synchronization */
}
//enable
TCC0_REGS->TCC_CTRLA |= TCC_CTRLA_ENABLE_Msk;
while((TCC0_REGS->TCC_SYNCBUSY & TCC_SYNCBUSY_ENABLE_Msk) == TCC_SYNCBUSY_ENABLE_Msk)
{
/* Wait for Write Synchronization */
}
while ( true )
{
cc0=TCC0_REGS->TCC_CC[TCC0_CHANNEL0] & 0xFFFFFFU;
cc1=TCC0_REGS->TCC_CC[TCC0_CHANNEL1] & 0xFFFFFFUl;
}
}