2009-04-10 01:53 AM
ERROR on Hall handled by TIM4
2011-05-17 01:15 AM
Hi,
I want to report an error in the file stm32f10x_hall.c : If you use the TIM4 to handle the Hall sensors, the function ReadHallState(void) should be as follows: u8 ReadHallState(void) { u8 ReadValue; #if defined(TIMER2_HANDLES_HALL) ReadValue = (u8)(GPIO_ReadInputData(GPIOA)) & GPIO_MSK; #elif defined(TIMER3_HANDLES_HALL) ReadValue = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0)< ReadValue |= GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6)< ReadValue |= GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7); #elif defined(TIMER4_HANDLES_HALL) ReadValue = ((u8)(GPIO_ReadInputData(GPIOB))>>6) & GPIO_MSK; #endif return(ReadValue); } instead of u8 ReadHallState(void) { u8 ReadValue; #if defined(TIMER2_HANDLES_HALL) ReadValue = (u8)(GPIO_ReadInputData(GPIOA)) & GPIO_MSK; #elif defined(TIMER3_HANDLES_HALL) ReadValue = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0)< ReadValue |= GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6)< ReadValue |= GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7); #elif defined(TIMER4_HANDLES_HALL) ReadValue = ((u8)(GPIO_ReadInputData(GPIOA))>>6) & GPIO_MSK; #endif return(ReadValue); } The error is that you read the input data from the wrong port![ This message was edited by: walterma on 06-04-2009 17:03 ]2011-05-17 01:15 AM
Hello Walterma,
thanks for your bug reporting. Unfortunately I also have to say you should pay attention at GPIO initialization where #else // TIMER4_HANDLES_HALL /* TIM4 clock source enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); /* Enable GPIOB, clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure PB.06,07,08 as Hall sensors input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6, GPIO_Pin_7, GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); #endif should be GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7| GPIO_Pin_8; Regards, Billino2011-05-17 01:15 AM
Hi Billino,
thank you, I found also that error at the GPIO initialization. There are also a few errors at the definitions of some constants. For example you can find in MC_pwm_3shunt_prm.h following: #define PHASE_A_ADC_CHANNEL ADC_Channel_11 #define PHASE_A_GPIO_PORT GPIOC #define PHASE_A_GPIO_PIN GPIO_Pin_1 #define PHASE_B_ADC_CHANNEL ADC_Channel_12 #define PHASE_B_GPIO_PORT GPIOC #define PHASE_B_GPIO_PIN GPIO_Pin_2 #define PHASE_C_ADC_CHANNEL ADC_Channel_13 #define PHASE_C_GPIO_PORT GPIOC #define PHASE_C_GPIO_PIN GPIO_Pin_3 but in the c-file you don't use this constants: /* ADC1, ADC2, PWM pins configurations -------------------------------------*/ GPIO_StructInit(&GPIO_InitStructure); /****** Configure PC.00,01,2,3,4 (ADC Channels [10..14]) as analog input ****/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &GPIO_InitStructure); and you define the same constants in the c-file (stm32f10x_svpwm_3shunt.c): #define PHASE_A_ADC_CHANNEL ADC_Channel_11 #define PHASE_B_ADC_CHANNEL ADC_Channel_12 #define PHASE_C_ADC_CHANNEL ADC_Channel_13 that's not very useful :) I build a brushless controller with the STM32F103C8T6 and I use TIM4 for the hall-sensors, TIM1 (not remapped) for the PWMs and ADC_Channel_0, ADC_Channel_1, ADC_Channel_2 for zero-crossing-detection. I know that using constants for pin-declarations is hard, because the ports can also change and so on.. Please use the constants in your c-files instead of hard-coding. regards Walter Craffonara