此帖出自MEMS传感器论坛
最新回复
BlueMicrosystem2例程里有定时器的例程可以参考一下
/**
* [url=home.php?mod=space&uid=159083]@brief[/url] Function for initializing timers for sending the information to BLE:
* - 1 for sending MotionFX/AR/CP and Acc/Gyro/Mag
* - 1 for sending the Environmental info
* @param None
* @retval None
*/
static void InitTimers(void)
{
uint32_t uwPrescalerValue;
/* Timer Output Compare Configuration Structure declaration */
TIM_OC_InitTypeDef sConfig;
/* Compute the prescaler value to have TIM4 counter clock equal to 10 KHz */
uwPrescalerValue = (uint32_t) ((SystemCoreClock / 10000) - 1);
/* Set TIM4 instance (Environmental)*/
TimEnvHandle.Instance = TIM4;
/* Initialize TIM4 peripheral as follow:
+ Period = 500 - 1 (10ms)
+ Prescaler = ((SystemCoreClock/2)/10000) - 1
+ ClockDivision = 0
+ Counter direction = Up
*/
TimEnvHandle.Init.Period = 50*100 - 1;
TimEnvHandle.Init.Prescaler = uwPrescalerValue;
TimEnvHandle.Init.ClockDivision = 0;
TimEnvHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_Base_Init(&TimEnvHandle) != HAL_OK) {
/* Initialization Error */
}
/* Set TIM1 instance (Motion)*/
TimCCHandle.Instance = TIM1;
TimCCHandle.Init.Period = 65535;
TimCCHandle.Init.Prescaler = uwPrescalerValue;
TimCCHandle.Init.ClockDivision = 0;
TimCCHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_OC_Init(&TimCCHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Configure the Output Compare channels */
/* Common configuration for all channels */
sConfig.OCMode = TIM_OCMODE_TOGGLE;
sConfig.OCPolarity = TIM_OCPOLARITY_LOW;
/* Output Compare Toggle Mode configuration: Channel1 */
sConfig.Pulse = uhCCR1_Val;
if(HAL_TIM_OC_ConfigChannel(&TimCCHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
#ifdef OSX_BMS_MOTIONCP // ((defined OSX_BMS_MOTIONCP) || (defined OSX_BMS_MOTIONPM))
/* Output Compare Toggle Mode configuration: Channel2 */
sConfig.Pulse = uhCCR2_Val;
if(HAL_TIM_OC_ConfigChannel(&TimCCHandle, &sConfig, TIM_CHANNEL_2) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
#endif /* OSX_BMS_MOTIONCP */
#ifdef OSX_BMS_MOTIONAR
/* Output Compare Toggle Mode configuration: Channel3 */
sConfig.Pulse = uhCCR3_Val;
if(HAL_TIM_OC_ConfigChannel(&TimCCHandle, &sConfig, TIM_CHANNEL_3) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
#endif /* OSX_BMS_MOTIONAR */
/* Output Compare Toggle Mode configuration: Channel4 */
sConfig.Pulse = uhCCR4_Val;
if(HAL_TIM_OC_ConfigChannel(&TimCCHandle, &sConfig, TIM_CHANNEL_4) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
/* Set TIM5 instance (Mic )*/
TimAudioDataHandle.Instance = TIM5;
/* Initialize TIM5 peripheral as follow:
+ Period = 100 - 1 (10ms)
+ Prescaler = ((SystemCoreClock/2)/10000) - 1
+ ClockDivision = 0
+ Counter direction = Up
*/
TimAudioDataHandle.Init.Period = MICS_DB_UPDATE_MUL_10MS*100 - 1;
TimAudioDataHandle.Init.Prescaler = uwPrescalerValue;
TimAudioDataHandle.Init.ClockDivision = 0;
TimAudioDataHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_Base_Init(&TimAudioDataHandle) != HAL_OK) {
/* Initialization Error */
Error_Handler();
}
}复制代码
详情
回复
发表于 2017-4-1 18:30
| ||
|
||
此帖出自MEMS传感器论坛
| ||
个人签名虾扯蛋,蛋扯虾,虾扯蛋扯虾
|
||
|
|
此帖出自MEMS传感器论坛
点评 | ||
|
||
此帖出自MEMS传感器论坛
| ||
|
||
此帖出自MEMS传感器论坛
点评 | ||
|
||
此帖出自MEMS传感器论坛
| ||
个人签名虾扯蛋,蛋扯虾,虾扯蛋扯虾
|
||
| |
个人签名虾扯蛋,蛋扯虾,虾扯蛋扯虾
|
|
此帖出自MEMS传感器论坛
点评 | ||
|
||
此帖出自MEMS传感器论坛
| ||
|
||
EEWorld Datasheet 技术支持