STM8S003F3P6의  PORTC7/TIM1_CH2 을  PWM출력시

핀 REMAPPING을 해야함.

static void TIM1_Config(void)
{
   TIM1_DeInit();
  TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 4095, 0);

 /* Channel 1, 2,3 and 4 Configuration in PWM mode */

  TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE, CCR2_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCIDLESTATE_RESET);  /*TIM1_Pulse = CCR3_Val*/

  TIM1_OC2PreloadConfig(ENABLE);

  /* Enables TIM1 peripheral Preload register on ARR */  
  TIM1_ARRPreloadConfig(ENABLE);

  /* TIM1 counter enable */  
  TIM1_Cmd(ENABLE);    

  /* TIM1 Main Output Enable */
  TIM1_CtrlPWMOutputs(ENABLE);
}

타이머1만 설정해서는 안됨
먼저
아래내용을 참고하여 설정을 바꿔줘야한다.
(PORTC7을 PWM으로 사용하려면 OPTION BYTE의 AFR0값을 바꿔 줘야한다.
REMAPPING방법은 아래를 참고한다)

디버깅시는 STVP를 이용하여 변경할 수도 있고

소스코드내에 OPTION BYTE의 값을 바꾸는 코드를 추가할 수도 있다.


http://wiki.netduino.com/How-to-set-STM8S-alternate-function-remapping-option-AFRx.ashx?Code=1

http://wiki.netduino.com/How-to-set-STM8S-alternate-function-remapping-option-AFRx.ashx?NoRedirect=1



How to set STM8S alternate function remapping option (AFRx)

Modified on 2012/05/12 05:46 by CW2 Categorized as Netduino GO!

For STM8S in packages, where SPI_NSS is present as alternate function of a pin, the alternate function remapping option has to be programmed to enable hardware SPI_NSS. For example, STM8Sx03F3 have SPI_NSS on PA3 controlled by AFR1:

  1. Launch ST Visual Programmer (included in ST Toolset instalation),
  2. Make sure the hardware is properly configured (e.g. select STM8S003F3 in SWIM mode),
  3. Select OPTION BYTE tab,
  4. Read the current tab from the device (Ctrl+R),
  5. Change ARF1 value to Port A3 Alternate Function = SPI_NSS, Port D2 Alternate Function = TIM2_CH3,
  6. Program the current tab to the device (Ctrl+P).


Image



How to set STM8S alternate function remapping option (AFRx)

Modified on 2012/05/12 05:46 by CW2 Categorized as Netduino GO!

For STM8S in packages, where SPI_NSS is present as alternate function of a pin, the alternate function remapping option has to be programmed to enable hardware SPI_NSS. For example, STM8Sx03F3 have SPI_NSS on PA3 controlled by AFR1:

# Launch ST Visual Programmer (included in [http://www.st.com/internet/com/SOFTWARE_RESOURCES/TOOL/TOOLSET/sttoolset.zip|ST Toolset] instalation),

# Make sure the hardware is properly configured (e.g. select STM8S003F3 in SWIM mode),

# Select OPTION BYTE tab,

# Read the current tab from the device (Ctrl+R),

# Change ARF1 value to ''Port A3 Alternate Function = SPI_NSS, Port D2 Alternate Function = TIM2_CH3'',

# Program the current tab to the device (Ctrl+P).

[imageleft||{UP(How-to-set-STM8S-alternate-function-remapping-option-AFRx)}stvp-afr.png]




Posted by 풀등
,