Topic : STM8AF6166 TIM2 CC3 PWM out nothing happend ! [solved]

Forum : ST7/STM8

Original Post
Post Information Post
March 17, 2011 - 11:36am
Guest

Hello all,

I'm trying to pulse out a PWM with the output compare function.

TIM3 CC1 work fine (checked with the scope) but when trying to do the same with TIM2 CC3 nothing happend ! But this two channels are sharing the same pin !

TIM2 CC2 work fine, so the timer is running, what's wrong ?

Here is my code :
TIM2->PSCR = (u8)(TIM2_PRESCALER_64);
/* Set the Autoreload value */
TIM2->ARRH = (u8)(2000 >> 8);
TIM2->ARRL = (u8)(2000);

TIM2->CCER2 &= (u8)(~( TIM2_CCER2_CC3E | TIM2_CCER2_CC3P));
/* Set the Output State & Set the Output Polarity */
TIM2->CCER2 |= (u8)(TIM2_CCER2_CC3E | TIM2_CCER2_CC3P);

/* Reset the Output Compare Bits & Set the Output Compare Mode */
TIM2->CCMR3 = (u8)((TIM2->CCMR3 & (u8)(~TIM2_CCMR_OCM)) | (u8)TIM2_OCMODE_PWM1);

/* Set the Pulse value */
TIM2->CCR3H = (u8)(1000 >> 8);
TIM2->CCR3L = (u8)(1000);
TIM2->CR1 |= TIM2_CR1_CEN;

Of course i tryed with cosmic compiler and all other compiler, Ride7 and STVD, without success...

The datasheet said that I can do, but it doesn't !

Alternative code under Ride7 :
TIM2_TimeBaseInit (TIM2_PRESCALER_64, 2000); // 125Hz
TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, 1000, TIM2_OCPOLARITY_LOW);
TIM2_CCxCmd(TIM2_CHANNEL_3, ENABLE);
TIM2_Cmd(ENABLE);

Don't work !!!

Please help !!!

Replies
Post Information Post
+1
0
-1
March 17, 2011 - 1:29pm
Guest

I found by myself !

You need to set the option byte OPT2 = 0x02 (NOPT2 = 0xFD) to enable TIM2 CC3 and disable TIM3 CC1, following is the asm file to add in your project :

Quote:

;This file contains the values to program in the option bytes.
;You can change the values below according to the device datasheet.
;Be careful to respect the complement bytes,
; or the default values of the option bytes will be used.

;See the device datasheet for more information on the meaning of each bit.

cseg at 04800h

db 000h ;LOCKBYTE

db 000h ;OPT1
db 0FFh ;NOPT1

db 002h ;OPT2 //0x02 will enable TIM2 CC3 and disable TIM3 CC1
db 0FDh ;NOPT2

db 000h ;OPT3
db 0FFh ;NOPT3

db 000h ;OPT4
db 0FFh ;NOPT4

db 000h ;OPT5
db 0FFh ;NOPT5

db 000h ;OPT6
db 0FFh ;NOPT6

db 000h ;OPT7
db 0FFh ;NOPT7

end