2015-03-19 03:12 AM
Hi all!
Anyone help me what mean of function “ voidTIM_SetCounter(TIM_TypeDef* TIMx, uint16_t Counter); For example
TIM_SetCounter(TIM4, 32000);
I don’t know how can calculate varieble uint16_tCounter.
If you have an example of Encoder Interface Mode, youcan send to me.
Sory because I am bad English!!
Thank a lot of!!!
2015-03-19 07:37 AM
Sets the internal counter in the timer, equivalent to TIM4->CNT = 32000;
Looks to be a fairly arbitrary value, probably half the period of the counter. You don't supply sufficient context. I've posted several encoder/decoder examples, you'll need to be specific about which STM32 you're using, as ST makes several parts. Look also at the firmware library examples. Toward the end of2015-03-20 06:09 AM
Thank for reply!
I found a program on the Internet. But I don’t know function of it
(
TIM_SetCounter(TIM4, 32000); ) and what do it mean of value 32000??
This is program.#include ''stm32f10x.h''
GPIO_InitTypeDef GPIO_InitStructure;
void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
initialize the PLL and update the SystemFrequency variable. */
//SystemInit();
/* Enable GPIOB clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
}
void Timer4_Configuration(void)
{
TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12, TIM_ICPolarity_BothEdge, TIM_ICPolarity_BothEdge);
TIM_ARRPreloadConfig(TIM4, ENABLE);
TIM_SetCounter(TIM4, 32000);
TIM_Cmd(TIM4,ENABLE);
}
void GPIO_Remap_Configuration(void)
{
GPIO_PinRemapConfig(GPIO_Remap_TIM4, ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
int main(void)
{
uint16_t temp;
/* Configure the system clocks */
RCC_Configuration();
Timer4_Configuration();
GPIO_Remap_Configuration();
/* Configure PB.8, PB.9, PB.10, PB11, PB12, PB.13, PB14 and PB.15 as output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
while (1)
{
temp=TIM_GetCounter(TIM4);
GPIO_Write(GPIOB, GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_6)*64+GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7)*128+temp);
}
}
Thanks!
2015-03-20 07:58 AM
It sets the counter to the approximate mid-point of the count, moving the encoder back and forth will increment and decrement from that point.
min point in binary terms 32768The positive number can make the math easier, as it doesn't wrap.2015-03-21 05:54 AM
You mean 32768 = 65536/2 ?
thank you so much !!