当前位置:网站首页>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
边栏推荐
- 图书管理系统(山东农业大学课程设计)
- HMS core machine learning service helps zaful users to shop conveniently
- LeetCode 5. 最长回文子串
- 虚假的暑假
- 月报总结|Moonbeam6月份大事一览
- How to use stustr function in Oracle view
- [North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array
- 618深度複盤:海爾智家的制勝方法論
- 台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条...
- Data security industry series Salon (III) | data security industry standard system construction theme Salon
猜你喜欢

LeetCode 2. 两数相加

大廠面試總結大全

What if the win11 app store cannot load the page? Win11 store cannot load page

Classifier visual interpretation stylex: Google, MIT, etc. have found the key attributes that affect image classification

Summary | three coordinate systems in machine vision and their relationships

Win11应用商店无法加载页面怎么办?Win11商店无法加载页面

Bone conduction non ear Bluetooth headset brand, bone conduction Bluetooth headset brand recommendation
![[fluent] dart data type string type (string definition | string splicing | string API call)](/img/7b/cc624aa33f45fbed0bbe354253158b.jpg)
[fluent] dart data type string type (string definition | string splicing | string API call)

TCP server communication process (important)

Hard core! One configuration center for 8 classes!
随机推荐
Masa framework - DDD design (1)
台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条...
头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
TypeScript数组乱序输出
Seal Library - installation and introduction
PCL least median square method fitting plane
SQL solves the problem of continuous login deformation holiday filtering
618 reprise en profondeur: la méthode gagnante de la famille Haier Zhi
Set the background picture in the idea (ultra detailed)
历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...
隐私计算技术创新及产业实践研讨会:学习
电脑设备打印机驱动安装失败如何解决
做机器视觉哪个软件好?
How to use stustr function in Oracle view
pwm呼吸灯
PCL 最小中值平方法拟合平面
PCL point cloud image transformation
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
SSM integration exception handler and project exception handling scheme
虚假的暑假