91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-16
  • 語言: 其他
  • 標簽: STM32??PWM??輸入捕獲??

資源簡介

用STM32的TIM定時器進行PWM的輸入捕獲實驗,調試航模遙控器。

資源截圖

代碼片段和文件信息

#include“ppmin.h“
Contral?My_Contral;
void?PWMInConfiguration(void)
{
GPIO_InitTypeDef?GPIO_InitStructure;
TIM_ICInitTypeDef?TIM_ICInitStructure;
TIM_TimebaseInitTypeDef?TIM_TimebaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2|RCC_APB1Periph_TIM3|RCC_APB1Periph_TIM4?ENABLE);?//時鐘配置?
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_TIM1?ENABLE);?

GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_0|GPIO_Pin_6|GPIO_Pin_8;????//GPIO配置?
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IN_FLOATING;?
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;?
GPIO_Init(GPIOA?&GPIO_InitStructure);?

GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_6;????//GPIO配置?
GPIO_Init(GPIOB?&GPIO_InitStructure);

TIM_TimebaseStructure.TIM_Period=?0xffff;
TIM_TimebaseStructure.TIM_Prescaler=2;
TIM_TimebaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimebaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimebaseStructure.TIM_RepetitionCounter=0;
TIM_TimebaseInit(TIM1&TIM_TimebaseStructure);
TIM_TimebaseInit(TIM2&TIM_TimebaseStructure);
TIM_TimebaseInit(TIM3&TIM_TimebaseStructure);
TIM_TimebaseInit(TIM4&TIM_TimebaseStructure);

TIM_ICInitStructure.TIM_Channel?=?TIM_Channel_1;?//通道選擇?
TIM_ICInitStructure.TIM_ICPolarity?=?TIM_ICPolarity_Rising;?//上升沿觸發?
TIM_ICInitStructure.TIM_ICSelection?=?TIM_ICSelection_DirectTI;?//管腳與寄存器對應關系?
TIM_ICInitStructure.?TIM_ICPrescaler=TIM_ICPSC_DIV1;//輸入預分頻,意思是控制在多少個輸入周期做一個捕獲,如果輸入的信號頻率沒有變,測得的周期也不會變,比如選擇四分頻,則沒四個輸入周期做一次捕獲,這昂再輸入信號不頻繁的情況下,可以減少軟件被不斷中斷的次數?

TIM_PWMIConfig(TIM1?&TIM_ICInitStructure);?//根據參數配置TIM外設信息
TIM_PWMIConfig(TIM2?&TIM_ICInitStructure);?//根據參數配置TIM外設信息
TIM_PWMIConfig(TIM3?&TIM_ICInitStructure);?//根據參數配置TIM外設信息
TIM_PWMIConfig(TIM4?&TIM_ICInitStructure);?//根據參數配置TIM外設信息 ?
TIM_SelectInputTrigger(TIM1?TIM_TS_TI1FP1);
TIM_SelectInputTrigger(TIM2?TIM_TS_TI1FP1);
TIM_SelectInputTrigger(TIM3?TIM_TS_TI1FP1);
TIM_SelectInputTrigger(TIM4?TIM_TS_TI1FP1);
TIM_SelectMasterSlaveMode(TIM1TIM_MasterSlaveMode_Enable);
TIM_SelectMasterSlaveMode(TIM2TIM_MasterSlaveMode_Enable);
TIM_SelectMasterSlaveMode(TIM3TIM_MasterSlaveMode_Enable);
TIM_SelectMasterSlaveMode(TIM4TIM_MasterSlaveMode_Enable);?
TIM_SelectSlaveMode(TIM1TIM_SlaveMode_Reset);
TIM_SelectSlaveMode(TIM2TIM_SlaveMode_Reset);
TIM_SelectSlaveMode(TIM3TIM_SlaveMode_Reset);
TIM_SelectSlaveMode(TIM4TIM_SlaveMode_Reset);
TIM_Cmd(TIM1?ENABLE);
TIM_Cmd(TIM2?ENABLE);
TIM_Cmd(TIM3?ENABLE);
TIM_Cmd(TIM4?ENABLE);??
}
void?PPMInCompute(void)
{
int?temp1temp2temp3temp4;
temp1=TIM2->CCR2;
temp2=TIM4->CCR2;
temp3=TIM1->CCR2;
temp4=TIM3->CCR2;
if(temp1>3880)
{
My_Contral.NS=temp1-3880;
}
else?if(temp1<3680)
{
My_Contral.NS=temp1-3680;
}
else
{
My_Contral.NS=0;
}
if(temp2>3800)
{
My_Contral.WE=temp2-3800;
}
else?if(temp2<3600)
{
My_Contral.WE=temp2-3600;
}
else
{
My_Contral.WE=0;
}
if(temp2>3800)

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????217??2012-08-16?16:44??ppmin.h
?????文件????????3371??2012-08-16?16:55??ppmin.c

評論

共有 條評論