Cov txheej txheem:
- Kauj ruam 1: Kho vajtse thiab Software yuav tsum tau
- Kauj ruam 2: STM32CubeMX Configuration
- Kauj Ruam 3: Keil UVision Coding
- Kauj ruam 4: Qhov tshwm sim:)
Video: Servo Tsav Tswj Nrog STM32F4 ARM MCU: 4 Cov Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:27
Nyob zoo cov phooj ywg:) Yog li, hauv txoj haujlwm no peb yuav tswj lub cav servo nrog STM32F4 ARM MCU. Hauv kuv qhov xwm txheej, kuv yuav siv daim ntawv tshawb pom, tab sis yog tias koj nkag siab qhov ntsiab lus ntawm qhov teeb meem, tom qab ntawd koj tuaj yeem thov nws rau txhua MCU. Yog li cia peb pib:)
Kauj ruam 1: Kho vajtse thiab Software yuav tsum tau
Hais txog kho vajtse peb yuav xav tau:
- MCU uas yog nyob rau hauv kuv rooj plaub STM32f4 Discovery board
- Ib qho kev pabcuam servo, zoo li SG90 lossis lwm yam
Hais txog software peb yuav xav tau:
- STM32CubeMX
- Keil Ua
Yog tias koj muaj tag nrho cov no, dhia mus rau kauj ruam tom ntej:)
Kauj ruam 2: STM32CubeMX Configuration
Raws li koj paub, rau kev tswj hwm lub cav servo peb xav tau PWM teeb liab. Cov kev xav tau ntawm PWM teeb liab zoo li qhov no:
- PWM lub sijhawm yuav tsum yog 20 mS
- Lub sijhawm yuav tsum nyob nruab nrab ntawm 0.5 mS txog 2.5 mS. Thaum lub sijhawm yog 0.5 mS, tom qab ntawd servo yuav tig 0 degrees, 1.5 mS rau 90 degrees, thiab 2.5 mS rau 180 degrees.
Yog li, peb yuav tsum teeb tsa PWM thiab rau lub hom phiaj ntawd peb yuav siv Timer1.
- Ua ntej, xaiv TIM1 los ntawm ntu Timers. Cov kauj ruam no
-
Tom qab ntawd, los ntawm ntu ntu
- Xaiv Internal Clock Cov kauj ruam no
- PWM Generation CH1 Cov kauj ruam no
-
Tom qab ntawd, los ntawm Configuration ntu
- Teem Prescaler rau 160 Cov kauj ruam no
- Teem Sijhawm Sijhawm rau 2000 Cov kauj ruam no
- Teem Pulse rau 50 Cov kauj ruam no
- Ib qho ntxiv, los ntawm Clock Configuration teeb tsa APB1 Timer moos rau 16MHz. Cov kauj ruam no
Tam sim no, wb tham me ntsis txog cov kauj ruam no:
Peb APB1 Timer moos zaus yog 16MHz. Yog li, nws txhais tau tias nws yuav tsum tau 16, 000, 000 zuam kom tau 1 thib ob. Txawm li cas los xij, peb teeb tsa peb cov prescaler rau 160. Nws txhais tau tias, peb faib peb zaus los ntawm tus lej ntawd thiab txo tus lej zuam mus rau 100, 000. Yog li, rau 1 thib ob peb xav tau 100, 000 zuam. Txawm li cas los xij, peb xav tau 20mS ntawm PWM lub sijhawm raws li peb tau hais ua ntej. Yog li, raws cov lej yooj yim, peb xav tau 2000 zuam rau 20mS. Yog li, los ntawm kev teeb Lub Sijhawm Sijhawm rau 2000 peb txiav txim siab lub sijhawm ntawm PWM teeb liab uas yog 20mS. Tam sim no peb yuav tsum txiav txim siab tus lej zauv kom tau txais Sijhawm los ntawm 0.5mS txog 2.5mS. Peb tuaj yeem tau txais qhov sib npaug no los ntawm kev ua lej yooj yim thiab nws yog:
On_Time = (Tick_Number / 100). Nco ntsoov tias qhov no yog on_time uas hloov lub kaum sab xis ntawm servo motor. Yog li, hauv qab daim duab kuv suav nrog cov kauj ruam no. Yog tias koj muaj lus nug sau hauv cov lus thiab kuv yuav teb sai li sai tau.
Duab ntawm kev suav
Tom qab ua tag nrho cov no tsim cov cai:)
Kauj Ruam 3: Keil UVision Coding
Yog li, ua ntej txiav txim siab seb peb xav ua dab tsi? Peb xav tau, los sau ua haujlwm uas lees paub qib thiab sau nws mus rau servo. Yog li, peb yuav ua li cas? Raws li peb tau hais ua ntej, txhawm rau hloov lub kaum sab xis peb yuav tsum hloov pauv raws sijhawm. Peb cov ces kaum hloov ntawm [0, 180] thiab peb tus lej zuam uas txiav txim siab lub sijhawm hloov ntawm [50, 250]. Yog li, peb xav tau daim phiaj ua haujlwm uas daim duab qhia lub kaum sab xis rau ntau ntawm cov zuam. Piv txwv li, rau 0 degree 50 zuam, rau 180 degree 250 zuam thiab ntxiv rau … Yog li cia peb sau peb daim ntawv qhia ua haujlwm:
int daim ntawv qhia (int st1, int fn1, int st2, int fn2, int tus nqi) {rov qab (1.0*(tus nqi-st1))/((fn1-st1)*1.0)*(fn2-st2)+st2; }
Nov yog peb daim ntawv qhia ua haujlwm. Koj puas txaus siab tias nws muab los li cas? Ces nyeem ntawd. Yog li, peb coj peb cov kab ke thiab tus nqi uas peb xav ua daim duab qhia chaw.
Tam sim no, cia peb sau txoj haujlwm uas lees txais lub kaum ntse ntse thiab qhia nws mus rau ntau yam zuam:
void servo_write (int angle) {htim1Instance-> CCR1 = daim ntawv qhia (0, 180, 50, 250, kaum sab xis); }
Raws li koj tuaj yeem pom, txoj cai no lees txais lub kaum ntse ntse thiab qhia nws rau thaj tsam ntawm tus lej zuam. Ib qho ntawd, tus lej zuam tau muab rau CCR1 sau npe uas tswj hwm lub sijhawm thiab yog li, lub kaum ntse ntse.
Txawm li cas los xij, txhawm rau txhua yam ntawm no los ua haujlwm peb xub pib pwm uas tuaj yeem ua tiav los ntawm kab kab xwb:
HAL_TIM_PWM_Start (& htim1, TIM_CHANNEL_1);
Yog li, peb muaj lub luag haujlwm uas lees txais lub kaum ntse ntse thiab sau nws mus rau servo. Cia peb sim nws thiab sau peb cov haujlwm cheb uas yooj yim heev:
void servo_sweep (tsis muaj dab tsi) {rau (int i = 0; i <= 180; i ++) {servo_write (i); HAL_Delay (10); } rau (int i = 180; i> = 0; i--) {servo_write (i); HAL_Delay (10); }}
Yog li, nws tsuas suav txog 180 thiab tom qab ntawd nqis mus rau 0 thiab sau cov txiaj ntsig no rau servo:) Yog li, cia peb pom qhov tshwm sim!
Kauj ruam 4: Qhov tshwm sim:)
Yog li, qhov no yog qhov kawg. Yog koj muaj lus nug thov nug. Kuv yuav zoo siab txhawm rau teb lawv. Ua tsaug ntau ntau rau kev nyeem thiab vam tias kuv yuav pom koj hauv qhov haujlwm tom ntej:)
Pom zoo:
Stepper Tsav Tswj Cov Qauv Tsav Tsheb - Stepper Lub Cev Ua Raws Li Lub Hau Encoder: 11 Kauj Ruam (nrog Duab)
Stepper Tsav Tswj Cov Qauv Tsav Tsheb | Stepper Motor Raws li Rotary Encoder: Hauv ib qho ntawm Cov Lus Qhia yav dhau los, peb tau kawm paub yuav siv lub tshuab stepper li cas los ua tus lej nkag teb chaws. Hauv txoj haujlwm no, tam sim no peb yuav siv lub tshuab hluav taws xob stepper tig lub cav nkag los tswj tus qauv tsheb ciav hlau siv Arduino microcontroller. Yog li ntawd, tsis muaj f
Xaiv Cov Kauj Ruam Tsav Tsheb thiab Tsav Tsheb rau Arduino Automated Shade Screen Project: 12 Cov Kauj Ruam (nrog Duab)
Xaiv Cov Kauj Ruam Tsav Tsheb thiab Tsav Tsheb rau Arduino Automated Shade Screen Project: Hauv Cov Lus Qhia no, Kuv yuav hla cov kauj ruam uas kuv tau xaiv los xaiv Lub Kauj Ruam Tsav Tsheb thiab Tsav Tsheb rau qhov ua piv txwv Automated Shade Screen project. Cov ntxaij vab tshaus ntxoov ntxoo yog qhov nrov thiab pheej yig Coolaroo tes cranked qauv, thiab kuv xav hloov
Yuav Ua Li Cas Siv Drone Quadcopter Brushless DC Tsav los ntawm Kev Siv HW30A Brushless Tsav Ceev Tswj thiab Servo Tester: 3 Kauj Ruam
Yuav Ua Li Cas Siv Drone Quadcopter Brushless DC Motor los ntawm Kev Siv HW30A Brushless Motor Speed Controller thiab Servo Tester: Nqe lus piav qhia: Cov cuab yeej no hu ua Servo Motor Tester uas tuaj yeem siv los ua haujlwm servo lub cev los ntawm kev ntsaws yooj yim hauv servo lub cev muaj zog thiab muab lub zog rau nws. Cov cuab yeej kuj tseem tuaj yeem siv ua lub cim hluav taws xob rau kev tswj hluav taws xob ceev (ESC), tom qab ntawd koj tuaj yeem
Pike - Tsav Kev Nyab Xeeb, Tsav Ntse, Tsav Tus Pike!: 5 Kauj Ruam
Pike - Tsav Kev Nyab Xeeb, Tsav Zoo, Tsav Pike!: Zoo siab txais tos rau kuv qhov project hu ua Pike! Nov yog qhov haujlwm raws li ib feem ntawm kuv txoj kev kawm. Kuv yog tub ntxhais kawm NMCT ntawm Howest hauv Belgium. Lub hom phiaj yog ua kom qee yam ntse los ntawm kev siv Raspberry Pi. Peb muaj kev ywj pheej tiav uas peb xav ua ntse.Rau rau kuv nws wa
Kev Tswj Ceev ntawm DC Tsav Siv PID Algorithm (STM32F4): 8 Kauj Ruam (nrog Duab)
Kev Tswj Ceev ntawm DC Tsav Siv PID Algorithm (STM32F4): nyob zoo txhua tus, Qhov no yog tahir ul haq nrog lwm qhov haujlwm. Lub sijhawm no nws yog STM32F407 ua MC. Qhov no yog qhov kawg ntawm qhov haujlwm ib nrab semester. Vam tias koj nyiam nws. Nws xav tau ntau lub tswv yim thiab kev xav yog li peb nkag mus rau nws ua ntej.Ua ntej ntawm lub khoos phis tawj thiab