当前位置:网站首页>Lampe respiratoire PWM
Lampe respiratoire PWM
2022-07-02 16:43:00 【Que tout brûle】
Mission:
- Sortie du minuteur d'apprentissagePWM,RéalisationPWMRespirateur
- Compris.PWMLe principe de la lampe respiratoire
AvecpwmPoints de connaissance sur le contrôle des lampes respiratoires
Auparavant, on utilisait une fonction de retard pour contrôler l'appareil à gouverner,La fonction Delay prend le micro - ordinateur à puce uniquecup,Inefficacité
pwmModulateur de largeur d'impulsion(Cycle de service):Contrôle des niveaux élevés et faibles
Commande du circuit analogique à l'aide de la sortie numérique du microprocesseur
Haut niveauLEDAllumez,Faible niveauLEDéteint
La longueur du haut niveau détermineLEDLa luminosité de
Pour avoir un cycle complet,La longueur des niveaux élevés et bas varie constamment,Durée du cycle(Fréquence)Sans changement,Un cycle se répète
pwmParstm32Le minuteur produit,Minuterie avancéeTIM1,Minuterie normaleTIM2,TIM3,TIM4




ccrx Indique la position de variation des niveaux élevés et faibles au cours d'un cycle
ccrx Réglage vers le Haut réduction du rapport de haut niveau , Ajuster le rapport élevé vers le bas pour augmenter 

Peut être réalisé séparément pour faire LED1OuLED2Lumière., Mais les deux ne peuvent pas s'allumer en même temps
Code complet:
main.c
int main(void)
{
u16 t = 500;
u8 dir = 1;
//delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
//uart_init(115200);
LED_Init();
TIM3_PWM_Init(59999,23);
while(1)
{
delay_ms(10);
if(dir)t=t+400;
else t=t-400;
if(t>60000)dir = 0;
if(t==500)dir = 1;
// TIM_SetCompare3(TIM3,t);
TIM_SetCompare4(TIM3,t);
pwm.c
void TIM3_PWM_Init(u16 arr,u16 psc){
//TIM3 PWMInitialisation arrValeur de recharge pscCoefficient de pré - Division
GPIO_InitTypeDef GPIO_InitStrue;
TIM_OCInitTypeDef TIM_OCInitStrue;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStrue;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);//ActiverTIM3Et lesGPIOHorloge
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//ActiverGPIOBHorloge(LEDInPB0Pin)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//ActiverAFIOHorloge(Minuterie3Accès3 Besoin de remap à BP5Pin)
// GPIO_InitStrue.GPIO_Pin=GPIO_Pin_0; // TIM_CH3
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_1; // TIM_CH4
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP; // Multiplexage Push - pull
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_50MHz; // Réglage de la vitesse de sortie maximale
GPIO_Init(GPIOB,&GPIO_InitStrue); //GPIO Paramètres d'initialisation du port
// GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE); //Cartographie, Remap n'est utilisé que pour 64、100、144Un micro - ordinateur à puce unique
// Quand il n'y a pas de remap ,TIM3 Quatre canaux CH1,CH2,CH3,CH4Correspondant séparémentPA6,PA7,PB0,PB1
// Quand une partie du remap ,TIM3 Quatre canaux CH1,CH2,CH3,CH4Correspondant séparémentPB4,PB5,PB0,PB1 (GPIO_PartialRemap_TIM3)
// Quand le remap complet ,TIM3 Quatre canaux CH1,CH2,CH3,CH4Correspondant séparémentPC6,PC7,PC8,PC9 (GPIO_FullRemap_TIM3)
TIM_TimeBaseInitStrue.TIM_Period=arr; //Définir la valeur de recharge automatique
TIM_TimeBaseInitStrue.TIM_Prescaler=psc; //Coefficient de pré - Division
TIM_TimeBaseInitStrue.TIM_CounterMode=TIM_CounterMode_Up; //Débordement du compteur
TIM_TimeBaseInitStrue.TIM_ClockDivision=TIM_CKD_DIV1; //Facteur de division de fréquence de l'horloge, Avec un peu de retard ,Généralement réglé àTIM_CKD_DIV1
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStrue); //TIM3Paramètres d'initialisation(ParamètresPWMCycle)
TIM_OCInitStrue.TIM_OCMode=TIM_OCMode_PWM1; // PWMMode1:CNT < CCR Niveau effectif de sortie
//TIM_OCInitStrue.TIM_OCMode=TIM_OCMode_PWM2;
TIM_OCInitStrue.TIM_OCPolarity=TIM_OCPolarity_High;// Définir la polarité- Le niveau effectif est :Haut niveau
TIM_OCInitStrue.TIM_OutputState=TIM_OutputState_Enable;// Activer la sortie
//
//TIM_OC3Init(TIM3,&TIM_OCInitStrue); //TIM3L'accès à3 PWM Configuration du mode
//
// TIM_OC3PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OC4Init(TIM3,&TIM_OCInitStrue); //TIM3L'accès à4 PWM Configuration du mode
TIM_OC4PreloadConfig(TIM3,TIM_OCPreload_Enable); //Activer le pré - chargement des registres
TIM_Cmd(TIM3,ENABLE); //ActiverTIM3
}
Attention!:
PWMFréquence de l'horloge=72000000/(59999+1)*(23+1) = 50HZ (20ms),
ParamètresValeur de chargement automatique60000,Pré - DivisionCoefficient24
边栏推荐
- Where can I open computer administrator permissions
- 机器学习-感知机模型
- Kubernetes three open interfaces first sight
- Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
- 数学分析_笔记_第6章:一元函数的Riemann积分
- PCL 最小中值平方法拟合平面
- LeetCode 3. 无重复字符的最长子串
- OSPF - detailed explanation of NSSA area and full NSSA area (including configuration command), LSA type 7 lsa-7
- Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
- La boîte de connexion du hub de l'unit é devient trop étroite pour se connecter
猜你喜欢

Which software is good for machine vision?

dried food! Understand the structural vulnerability of graph convolution networks

Mathematical analysis_ Notes_ Chapter 6: Riemann integral of univariate function

How to choose the right kubernetes storage plug-in? (09)

The light of ideal never dies

头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》

电脑管理员权限在哪里可以打开

SQL solves the problem of continuous login deformation holiday filtering

月报总结|Moonbeam6月份大事一览

Kubernetes three open interfaces first sight
随机推荐
SQL solves the problem of continuous login deformation holiday filtering
Machine learning perceptron model
Summary of monthly report | list of major events of moonbeam in June
Written by unity Jason
LeetCode 5. 最长回文子串
day4
Kubernetes family container housekeeper pod online Q & A?
The login box of unity hub becomes too narrow to log in
Aike AI frontier promotion (2.15)
数学分析_笔记_第6章:一元函数的Riemann积分
Library management system (Shandong Agricultural University Curriculum Design)
Yyds dry goods inventory student attendance system based on QT design
A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits
Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm
Understand the key technology of AGV -- the difference between laser slam and visual slam
Vscade set multi line display of tab
PyC file decompile
mysql min() 求某条件下最小的值出现多个结果
sim2real环境配置教程
Recalling the college entrance examination and becoming a programmer, do you regret it?