Author Topic: writing CC0 on SAMD20 appears to stall the timer  (Read 1522 times)

0 Members and 1 Guest are viewing this topic.

Offline snarkysparkyTopic starter

  • Frequent Contributor
  • **
  • Posts: 441
  • Country: us
writing CC0 on SAMD20 appears to stall the timer
« on: February 03, 2020, 01:54:42 pm »
I am trying to use TC7 in match PWM mode with output WO[1].   
If i start the timer with CC0 and CC1 setup for an initial period and duty the output works.

But if I try to change the period on the fly ( CC0 ) it appears to stall the timer.  At least the output ceases to toggle.

setup code
Code: [Select]
       // *******TC7 setup for match PWM waveform generation.  Used for feed step motor drive
       REG_TC7_INTFLAG = 0x000000ff;  // reset any interrupts pending

       REG_TC7_CTRLA = 0x000000;         // disable TC7 to make config changes
       while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);

       REG_TC7_CTRLBSET = TC_CTRLBSET_DIR;   // count up
       while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
   
   REG_TC7_CTRLA = TC_CTRLA_MODE_COUNT16 | TC_CTRLA_WAVEGEN_MPWM;   //  16 bit mode - match frequency generator
       while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);

       REG_TC7_INTENSET = TC_INTENSET_MC0;             // no interrupt routine. used as a flag for setting CC0 register immediately after match
   while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
   
   REG_TC7_CTRLC = TC_CTRLC_CPTEN1;
       while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY); //?

       REG_TC7_CTRLA |= TC_CTRLA_ENABLE;                         
       while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);






In a fast loop I try to write CC0 immediately after a match so the new CC0 value will still be above the current count.

Code: [Select]
if(REG_TC7_INTFLAG & TC_INTFLAG_MC0)   // check for MC0 match
{
REG_TC7_INTFLAG = TC_INTFLAG_MC0;   // writing should clear..
if(TC7CC0HasNewValueFlag)   // must write new CC0 value immediately after rollover of MC1
    {
TC7CC0HasNewValueFlag = 0;
REG_TC7_COUNT16_CC0 = FeedMotorRealTimeCCVal;
while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
}
}




All I want to do is change the output frequency via setting CC0.

Thanks




 

Offline snarkysparkyTopic starter

  • Frequent Contributor
  • **
  • Posts: 441
  • Country: us
Re: writing CC0 on SAMD20 appears to stall the timer
« Reply #1 on: February 03, 2020, 02:59:52 pm »
I fixed it.

In MPWM mode CC0 is the period and CC1 is the on time.  My code was suppose to double CC0 before writing to the register.

As it was operating CC0 and CC1 were getting the same value.   So no output

This fixed ..........

REG_TC7_COUNT16_CC0 = (FeedMotorRealTimeCCVal << 1);

Funny how asking the question makes you figure it out.

 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3671
  • Country: gb
Re: writing CC0 on SAMD20 appears to stall the timer
« Reply #2 on: February 03, 2020, 04:37:19 pm »
Funny how asking the question makes you figure it out.

Lost count of the number of times I've been part way through explaining a problem to a colleague at work and had a epiphany.  It's part of the development process, for me at least.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 8349
  • Country: fi
    • My home page and email address
Re: writing CC0 on SAMD20 appears to stall the timer
« Reply #3 on: February 03, 2020, 10:41:55 pm »
Rubber duck debugging works.

I think it has something to do with having to clean up our thoughts into a simple form to describe it out loud, and how that process makes solutions stand out.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->