2018-11-07 12:00 PM
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
Solved! Go to Solution.
2018-12-11 08:18 AM
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
2018-12-11 08:18 AM
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