why do some CTIMER selections prevent printfs in main, but others don't?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

why do some CTIMER selections prevent printfs in main, but others don't?

1,844 Views
jmueckl
Contributor IV

The following code uses CTIMER3 to create a 100ms timer, the output of which is hard wired to a PINT Pin Interrupt to initiate a software function, and a 30KHz variable duty cycle PWM signal using CTIMER4.  I am developing on an LPC54018 (OM40003UL) development board in debug mode.  I know that the code operates correctly because I am able to view both signals on my oscilloscope while the printf in the while loop continually prints data variables to the console. 

During my development I first attempted to use CTIMER1 in match0 and match1 modes to generate the 30KHz PWM signal.  While both hardware signals were visible on my oscilloscope, the printf in my while loop ceased to be displayed.  It wasn’t until I changed CTIMER1 to CTIMER4 match 0 & match 1 that the code operated as intended.  I also found that CTIMER4 match 3 failed in the same way I described.    

Note that in each case I assigned the appropriate timer output pin in the pin configuration tool, and for each match case I modified the symbol kCTIMER_Match_x to the appropriate match number.

Can someone explain why some ctimers I attempted might prevent my printf statements, yet produce the correct PWM signal?  Can I determine which one works without having to test each potential option?

     ctimer_config_t T3config;

     ctimer_config_t T4config;   

     CTIMER_GetDefaultConfig(&T3config);

     CTIMER_Init(CTIMER3, &T3config);

     T3matchConfig.enableCounterStop  = false;

     T3matchConfig.matchValue         = CLOCK_GetFreq(kCLOCK_AsyncApbClk) / 20;  // 10Hz

     T3matchConfig.outControl         = kCTIMER_Output_Toggle;

     T3matchConfig.outPinInitState    = true;

     T3matchConfig.enableInterrupt    = false;

     T3matchConfig.enableCounterReset = true;

     // CTIMER3 100ms timer

     CTIMER_SetupMatch(CTIMER3, kCTIMER_Match_1, &T3matchConfig);

     CTIMER_StartTimer(CTIMER3);

 

     // CTIMER4 establishes a 30KHz PWM signal

     timer4Clock = CLOCK_GetFreq(kCLOCK_BusClk); // 180MHz

     CTIMER_GetDefaultConfig(&T4config);

     CTIMER_Init(CTIMER4, &T4config); 

     CTIMER_RegisterCallBack(CTIMER4, &ctimer_callback[0], kCTIMER_SingleCallback);

     /* Get the PWM period match value and pulse width match value of 30Khz PWM signal */

     CTIMER_GetPwmPeriodValue(30000, dutyCycle, timer4Clock);

     CTIMER_SetupPwmPeriod(CTIMER4, kCTIMER_Match_0, g_pwmPeriod, g_pulsePeriod, true);

     CTIMER_StartTimer(CTIMER4);

     while (1)

     {

             if (MeasTemp_flag == true)

             {

                    MeasTemp_flag = false;

                    gt_pint0_Cnt++;

                    tempCalc = max31865.temperature(); 

                    tempAve += tempCalc;

                   fprintf(fp, "%8lu  %10f\n", tempCalc, tempAve);

             }

     }

}

Labels (1)
0 Kudos
10 Replies

1,773 Views
jmueckl
Contributor IV

I can't give out the rest of this code because it is proprietary.  If we can't solve it in this way I'll just have to resort to using the timers that work.  If this is not a known issue than it can remain unknown until someone else finds it.

0 Kudos

1,790 Views
jmueckl
Contributor IV

Project Code Attached

0 Kudos

1,779 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi,

Whole project, that I can directly run on my IDE and board.

Just this code, there is build error.

Alice_Yang_0-1620873071957.png

 

0 Kudos

1,791 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello jmueckl,

Share your whole project, not only the piece of code.

 

0 Kudos

1,815 Views
jmueckl
Contributor IV

Yes, it does.  It stops if I set a breakpoint in either my 100ms timer ISR or my 30KHz PWM ISR.

0 Kudos

1,809 Views
converse
Senior Contributor V

Is MeasTemp_flag defined as volatile? If not, it MUST be!

see https://www.embedded.com/introduction-to-the-volatile-keyword/

 

 

0 Kudos

1,806 Views
jmueckl
Contributor IV

Yes it is  

volatile bool MeasTemp_flag = false;

 

0 Kudos

1,836 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello jmueckl,

When the printf doesn't work, does MeasTemp_flag is true ? 

And where change this flag? Interrupt function?

Recommend you describe and show a project that just includes the doesn't work CTIMER.

 

BR

Alice

0 Kudos

1,833 Views
jmueckl
Contributor IV

Here is the interrupt service routine

void pint_intr_callback(pint_pin_int_t pintr, uint32_t pmatch_status)  {
if (pintr == kPINT_PinInt2)
{
   MeasTemp_flag = true;
}


The main loop tests to see if MeasTemp_flag is true, and if so, it printf's the temperature.

In all the cases I tested, both signals were displayed on the oscilloscope. That tells me that all the CTimers worked the same as the other.  

 

 

0 Kudos

1,823 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello,

So set a breakpoint on your  interrupt service routine function, does it stop on it?

 

0 Kudos