Author Topic: PIC32CM MC00 Curiosity Pro PWM measuring with TCC PWP or PPW  (Read 778 times)

0 Members and 1 Guest are viewing this topic.

Offline DR_NZTopic starter

  • Newbie
  • Posts: 2
  • Country: nz
PIC32CM MC00 Curiosity Pro PWM measuring with TCC PWP or PPW
« on: August 02, 2021, 04:47:53 am »
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: [Select]
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;

       
       
    }
}

 

Offline Ground_Loop

  • Frequent Contributor
  • **
  • Posts: 645
  • Country: us
Re: PIC32CM MC00 Curiosity Pro PWM measuring with TCC PWP or PPW
« Reply #1 on: August 05, 2021, 07:38:21 pm »
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.
There's no point getting old if you don't have stories.
 

Offline DR_NZTopic starter

  • Newbie
  • Posts: 2
  • Country: nz
Re: PIC32CM MC00 Curiosity Pro PWM measuring with TCC PWP or PPW
« Reply #2 on: August 05, 2021, 09:38:39 pm »
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.

" alt="" class="bbc_img" />
 

Offline Ground_Loop

  • Frequent Contributor
  • **
  • Posts: 645
  • Country: us
Re: PIC32CM MC00 Curiosity Pro PWM measuring with TCC PWP or PPW
« Reply #3 on: August 05, 2021, 11:23:07 pm »
I interpret TCC as 'Timer/Counter for Control.'  I don't see a capture capability. Note also I have never used TCC.
There's no point getting old if you don't have stories.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf