当前位置:网站首页>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 automatique
60000,Pré - Division
Coefficient24
边栏推荐
- Machine learning perceptron model
- LeetCode 2. Add two numbers
- 月报总结|Moonbeam6月份大事一览
- [fluent] dart data type string type (string definition | string splicing | string API call)
- day4
- TCP congestion control details | 2 background
- Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
- mysql min() 求某条件下最小的值出现多个结果
- 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
- unity Hub 登錄框變得很窄 無法登錄
猜你喜欢
Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 releases | geek headlines
PCL 点云镜像变换
Text intelligent expansion and contraction control of swiftui text component (tutorial includes source code)
SSM integration exception handler and project exception handling scheme
PCL point cloud image transformation
总结|机器视觉中三大坐标系及其相互关系
数据安全产业系列沙龙(三)| 数据安全产业标准体系建设主题沙龙
Foreign enterprise executives, continuous entrepreneurs, yoga and skiing masters, and a program life of continuous iteration and reconstruction
Set the background picture in the idea (ultra detailed)
随机推荐
PCL 最小中值平方法拟合平面
unity Hub 登錄框變得很窄 無法登錄
Yyds dry goods inventory student attendance system based on QT design
How to use stustr function in Oracle view
What if the win11 app store cannot load the page? Win11 store cannot load page
Student course selection system (curriculum design of Shandong Agricultural University)
Global and Chinese market of desktop hot melt equipment 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 2. 两数相加
Global and Chinese market of oil analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
False summer vacation
[fluent] dart data type boolean type (boolean type definition | logical operation)
PyC file decompile
Hard core! One configuration center for 8 classes!
Unity Json 编写
Everyone Xinfu builds: a one-stop intelligent business credit service platform
LeetCode 4. 寻找两个正序数组的中位数(hard)
隐私计算技术创新及产业实践研讨会:学习
SSM整合-异常处理器及项目异常处理方案
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)