Electronics > Microcontrollers

PIC32CM MC00 Curiosity Pro PWM measuring with TCC PWP or PPW

(1/1)

DR_NZ:
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  :-DD. 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!


--- Code: ---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;

       
       
    }
}


--- End code ---

Ground_Loop:
Isn't the TCC peripheral an output device for generating PWM signals?  I am doing something similar--if I'm interpreting your post correctly--with a PIC32MX564 using the ICAP peripheral to measure DC and Frequency of a PWM input.

DR_NZ:
Hi Ground_Loop,

Thanks for your reply. I started doubting that myself. Am I misinterpreting "capture" in the datasheet? My understanding is that indeed you can output PWM signals but also capture them using the same module as PPW or PWP.

Ground_Loop:
I interpret TCC as 'Timer/Counter for Control.'  I don't see a capture capability. Note also I have never used TCC.

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version