PORT and TIM issue with Discovery Board STM32F407
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-10 7:47 AM
I am working on a sine wave program as a part of an Amateur Radio project. I have a working code producing what I want using TIM3-- PWM and PORTC. I am unfortunately unable to neither change the TIM3 to any other TIM nor am I able to change my PORTC to PORTE. The code follows closely the PWM example by STM and Andrew Markham's approach to the interrupt handle. I can post code, although I am not sure of the proper messaging protocol for code in this forum. Since the code is working fine using TIM3 and PORTC, I would have thought that either change would have been a simple task. I have of course tried to change only one at a time. Changes compile fine with no errors; but no output is found on the appropriate pin using an oscilloscope, except the TIM3/PORTC arrangement. Thanks for any help.
Jack (W0FNQ)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-10 8:24 AM
You can paste source using the Format Code Block (Paintbrush [<>] icon). I want to see complete compilable code.
Timers have specific pin utilization, so you can't randomly associate them. The part data sheet should show what routing options are available.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-10 10:15 AM
Thanks for reply. I am hoping to use TIM4 and PORTE pin 2. Here is the code:
* Jack Generaux (W0FNQ)
*
* Some concepts and sine table from:
******************************************************************************
* @file USART/main.c
* @author Andrew Markham
* @version V1.0.0
* @date 27-April-2012
* @brief Main program body
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include ''stm32f4xx_conf.h''
#include <
stdio.h
>
#include ''Oscillator.h''
#include ''stm32f4xx.h''
void PWM_Config(int period)
{
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
/* GPIOC and GPIOB clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC , ENABLE);
/* GPIOC Configuration: TIM3 CH1 (PC6) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Connect TIM3 pins to AF2 */
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM3);
/* No prescale, run at maximum frequency */
uint16_t PrescalerValue=0;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = period;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3, ENABLE);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE);
}
void PWM_SetDC(uint16_t dutycycle)
{
TIM3->CCR1 = dutycycle;
}
void INTTIM_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM2 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 10 - 1; // 1 MHz down to 100 KHz
TIM_TimeBaseStructure.TIM_Prescaler = 84 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM IT enable */
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
}
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
PWM_SetDC(pulse_width);
// Calculate a new pulse width
phase_accumulator+=R;
angle=(uint8_t)(phase_accumulator>>24);
pulse_width = sinetable[angle];
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-10 11:53 AM
PE2 has no timer associativity. Please refer to the
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf
for your part. PE5/PE6 are TIM9_CH1 and CH2 respectivelyUp vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-10 12:13 PM
thanks for the reference pointer. I will explore other possible combinations.
