cancel
Showing results for 
Search instead for 
Did you mean: 

How set a PWM using E_timer with a SPC570xx board?

TGecc
Associate

Good morning,

I'm trying to implement a simple PWM in a SPC5700 board usign an e timer. I'we follow all the suggestion in the datasheet and the compiler don't give any error but in debug mode my code doesn't work. So i wanna ask if i'm making some mistakes and where i can find some example of PWM using an etimer.

this is my code:

//BUS CLOCK 15000000
	ETIMER_0.ENBL.R = 0U;									/* disable all channels for configuration */
 
	ETIMER_0.CH[num_ch].CTRL1.B.CNTMODE=001U;				/*Count rising edges of primary source*/
	ETIMER_0.CH[num_ch].CTRL1.B.PRISRC=0x1CU ;				/*IP Bus clock divide by 16 prescaler*/
	ETIMER_0.CH[num_ch].CTRL1.B.ONCE=0U;					/*Count repeatedly*/
	ETIMER_0.CH[num_ch].CTRL1.B.LENGTH=1U;					/*Count until compare, then reinitialize*/
	ETIMER_0.CH[num_ch].CTRL1.B.DIR=0U;						/*normal count direction up*/
	//ETIMER_0.CH[num_ch].CTRL1.B.SECSRC;					/*not use a secondary count source*/
 
	ETIMER_0.CH[num_ch].CTRL2.B.RDNT = 0U;					/* disable redundant channel */
	ETIMER_0.CH[num_ch].CTRL2.B.OPS = 0U;					/* true polarity */
	ETIMER_0.CH[num_ch].CTRL2.B.OUTMODE=4U;					/*Toggle OFLAG output using alternating compare registers*/
 
	ETIMER_0.CH[num_ch].STS.B.TCF1=1;						/*Timer Compare 1 Flag*/
	ETIMER_0.CH[num_ch].STS.B.TCF2=1;						/*Timer Compare 2 Flag */
 
	ETIMER_0.CH[num_ch].COMP1.R=75000;						/* Comparator Load Register */
	ETIMER_0.CH[num_ch].COMP2.R=150000;						/* Comparator Load Register */
 
	ETIMER_0.CH[num_ch].CCCTRL.B.CLC2=0x5;					/*Load COMP2 with CMPLD2 upon successful compare with the value in COMP2*/
	ETIMER_0.CH[num_ch].CCCTRL.B.CLC1=0x3;					/*Load COMP1 with CMPLD1 upon successful compare with the value in COMP2*/
 
	ETIMER_0.CH[num_ch].LOAD.R=0;
	ETIMER_0.ENBL.R=1;										/*Timer channel is enabled*/

best regard

Tommaso Gecchelin

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
Erwan YVIN
ST Employee

Hello Tommaso ,

There is an example in SPC5Studio Tools suite

SPC570Sxx_RLA PWM-ICU Test Application for Discovery

cf function pwm_lld_enable_channel

Best Regards

Erwan

View solution in original post

1 REPLY 1
Erwan YVIN
ST Employee

Hello Tommaso ,

There is an example in SPC5Studio Tools suite

SPC570Sxx_RLA PWM-ICU Test Application for Discovery

cf function pwm_lld_enable_channel

Best Regards

Erwan