AnsweredAssumed Answered

generate PWM

Question asked by D.Nantanat on Apr 23, 2012
hi all
i'm newbie

i just start stm8s105c6 by generate PWM from TIM1 4channels
from the stm8sfwlib example >>TIM1_7PWM_Output

see this code

                                   
 #include "stm8s.h"
           
            /**
              * @addtogroup TIM1_7PWM_Output====i need output C1 C2
              * @{
              */
           
            /* Private typedef -----------------------------------------------------------*/
           
            /* Private define ------------------------------------------------------------*/
            #define CCR1_Val  ((u16)2047) //50%=2047
            #define CCR2_Val  ((u16)2047) //
           
            /* Private macro -------------------------------------------------------------*/
            /* Private variables ---------------------------------------------------------*/
            /* Private function prototypes -----------------------------------------------*/
            /* Private functions ---------------------------------------------------------*/
            /* Public functions ----------------------------------------------------------*/
           
            /**
              * @brief Example firmware main entry point.
              * @par Parameters:
              * None
              * @retval
              * None
              */
            void main(void)
            {
           
              /* TIM1 Peripheral Configuration */
              TIM1_DeInit();
           
              /* Time Base configuration */
                /*
                TIM1_Period = 4095
              TIM1_Prescaler = 0
              TIM1_CounterMode = TIM1_COUNTERMODE_UP
              TIM1_RepetitionCounter = 0
                */
           
              TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 4095, 0);
           
              /* Channel 1, 2,3 and 4 Configuration in PWM mode */
             
                /*
                TIM1_OCMode = TIM1_OCMODE_PWM2
              TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
              TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
                TIM1_Pulse = CCR1_Val
              TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
              TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH
              TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
              TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
             
                */
              TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, CCR1_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);
           
              /*TIM1_Pulse = CCR2_Val*/
              TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, CCR2_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);
           
              /* TIM1 counter enable */
              TIM1_Cmd(ENABLE);
           
              /* TIM1 Main Output Enable */
              TIM1_CtrlPWMOutputs(ENABLE);
             
             
              while (1);
            }
           
            #ifdef USE_FULL_ASSERT
           
            /**
              * @brief  Reports the name of the source file and the source line number
              *   where the assert_param error has occurred.
              * @param file: pointer to the source file name
              * @param line: assert_param error line source number
              * @retval
              * None
              */
            void assert_failed(u8* file, u32 line)
            {
              /* User can add his own implementation to report the file name and line number,
                 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
           
              /* Infinite loop */
              while (1)
              {
              }
            }
            #endif



and just need you all help me!
i want :
portA.3 to be the input to generate the output to portC.1
portA.4 to be the input to generate the output to portC.2


can you suggest me?


really thanks!



blesss

nantanat


Ps. sorry for my bad english.. hope you guys understand me ;)

Outcomes