Not able to generate 6 step pwm signal using timer1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-24 9:08 PM
Hi,
I am working with stm8s105c6 controller. I want to generate 6 PWM using timer1. For that I am using 6 step PWM sample. I am getting pwm at pc1, pc2, pc3 but complementry pwm at pb0, pb1, and pb2 is not available.
At pb0, pb1 and pb2 I am constantly getting 5V Dc. why?
will you plz help?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-25 8:11 AM
If you get constant 5 V, something is wrong. Either your supply voltage if to high ( 5 V vs 3.3V) or your drive 5 V to a non-5 Volt tolerant pin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-26 10:14 PM
PB2,PB1,PB0 has default function "analog input". You have to remap their function to TIM1 complementary outputs by programming option bits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-27 1:38 AM
how should I program option bits?
Please guide
thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-27 9:15 PM
I have set option bits too. Still I am not get complementary waveform at PB2 PB1 PB0. Now I am not getting 5v dc as am getting initially before option byte set.
But now only noise is present at this pins.
do i have to change anything else as hardware point of view or software
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-27 11:04 PM
Show your timer initialisation code...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-28 12:33 AM
*/
void main(void)
{
/* TIM1 configuration -----------------------------------------*/
TIM1_Config();
/* TIM4 configuration -----------------------------------------*/
TIM4_Config();
/* Main Output Enable */
TIM1_CtrlPWMOutputs(ENABLE);
enableInterrupts();
while (1)
{}
}
/**
* @brief Configure TIM1 to generate 6 Steps PWM signal
* @param None
* @retval None
*/
static void TIM1_Config(void)
{
/* TIM1 Peripheral Configuration */
TIM1_DeInit();
/* Time Base configuration */
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 4095, 0);
/* Channel 1, 2 and 3 Configuration in TIMING mode */
/* TIM1_Pulse = 2047 */
TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
2047, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_RESET,
TIM1_OCNIDLESTATE_SET);
/* TIM1_Pulse = 1023 */
TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 1023,
TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_SET);
/* TIM1_Pulse = 511 */
TIM1_OC3Init(TIM1_OCMODE_TIMING, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
511, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_SET);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM1_BDTRConfig( TIM1_OSSISTATE_ENABLE, TIM1_LOCKLEVEL_OFF, 1, TIM1_BREAK_DISABLE,
TIM1_BREAKPOLARITY_LOW, TIM1_AUTOMATICOUTPUT_ENABLE);
TIM1_CCPreloadControl(ENABLE);
TIM1_OC1PreloadConfig(ENABLE);
TIM1_OC2PreloadConfig(ENABLE);
TIM1_OC3PreloadConfig(ENABLE);
TIM1_ITConfig(TIM1_IT_COM, ENABLE);
/* TIM1 counter enable */
TIM1_Cmd(ENABLE);
}
/**
* @brief Configure TIM4 to generate a software COM event each 180 ms
* @param None
* @retval None
*/
static void TIM4_Config(void)
{
/* TIM4 Peripheral Configuration */
/* Time Base configuration */
TIM4_TimeBaseInit(TIM4_PRESCALER_128, 0xFF);
/*TIM4 counter enable */
TIM4_Cmd(ENABLE);
TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
}
#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(uint8_t* file, uint32_t 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
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
this is the code I am using
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-28 1:28 AM
I dont see any mistake. Try example from standard peripheral library. If it works, look for differences. It it doesnt works, look once again at option bytes and look for HW errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-28 1:32 AM
thank you sir.
I am using the example code from standard peripherals. And now clueless
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-28 1:39 AM
Are you sure that you have properly set option bytes and sure that you are looking at right pins ?
