Professional Documents
Culture Documents
Like every system, this system has input, processing and output, basic program structure is derscribed in the following flowchart
PWM from channel 3 PWM input copture zasis PWM from channel 1 PWM input copture xasis
Decoding y-
axis
Forward thrust
Decoding Xaxis
Torque for steering
PROCESS
Encoding servo
PWM output compare servo PWM to servo
Encoding thrust
PWM output compare thrust fan
PWM to EDF
Input capture
By using timer of the system, microcontroller have to read 3 signals generated by radio controller transmitter, these three signals correspond to three control sticks on the transmitter which is human interface, to be controlled by operator which in turn will control hovercraft according to data processing algorithm . these signals are in form of PWM ( pulse width modulation) of period of 20ms. It is done by using timer peripheral of the STM32f100 in input capture mode. Reading a PWM signal means that we are reading duty cycle of square wave.
Output of DECODER
50
-50
-100 1200
1300
1400
1800
1900
2000
Output of DECODER
50
-50
-100 1100
1200
1300
1700
1800
1900
Processing
Now we have proper Data in proper Scale to be processed further. We can process this information in our desired way and according to desired algorithm to make hovercraft stable and provide high level of stability, we term this process as DECODING of PWM
ENCODING of data
After processing we have information in variables which are OUTPUT of the system and requires to be modulated again, so to control speed of motors. We have three devices to be controlled , all of them requires PWM signals to be operated. These devices have their own parameters as described below. 1) brushless DC motor for LIFT 1000 us of +width corresponds to 0% speed 2000 us of +width corresponds to100% speed
2) brushless DC motor for ELECTRIC DUCT FAN 1000 us of +width corresponds to 0% speed 2000 us of +width corresponds to100% speed 3) Servo motor for rotating EDF 720 us of +width corresponds to -90 degrees 1520 us of +width corresponds to 0 degrees 2320 us of +width corresponds to +90 degrees These parameters are defined in the beginning of code, with some limitations #define min_servo 720 #define mid_servo 1520 #define max_servo 2320 #define min_thrust 1000 #define mid_thrust 1000 #define max_thrust 1500 #define mid_lift 1000 #define max_lift 1800 However value of Thrust can go upto 2000 us but we have limited it to 1500 us which is 50%, similarly we have limited lift to 80% of maximum After Processing, this data is modulated to PWM
ENCODING OF THRUST 1500 1450 1400 1350
ENCODED thrust
1300 1250 1200 1150 1100 1050 1000 -20 0 20 40 THRUST 60 80 100 120
Notice that when THRUST is below 0, it is limited to 1000 us, and when thrust goes above 100, it is limited to 1500. Similarly encoding of lift and servo is done.
Output Compare
Now a signal is to be generated depending upon encoded data, i.e encoded data represents the +width of PWM. It is done by using timer peripherals output compare mode.
using timer 3 PWM A:utilizing channel 1 and 2 for reading one pwm TIM3_ch1 channel 1: configured for rising edge (CCER |=0x0001) CC1P=0(rising polarity),CC1E=1. TIM3_ch2 channel 2: configured for falling edge (CCER |=0x0030) CC2P=1(falling polarity),CC2E=1. TI1 mapped on IC1 (CCMR1 |=0x0001 ) IC1=>TI1 TI1 mapped on IC2 (CCMR1 |=0x0200 ) IC2=>TI1 read PWM from A6 for PWM A ,so configure it as input floating
PWM B:utilizing channel 3 and 4 for reading one pwm TIM3_ch3 channel 3: configured for rising edge (CCER |=0x0100) CC3P=0(rising polarity),CC3E=1.
TIM3_ch4 channel 4: configured for falling edge (CCER |=0x3000) CC4P=1(falling polarity),CC4E=1 TI3 mapped on IC3 (CCMR2 |=0x0001 ) IC3=>TI3 TI3 mapped on IC4 (CCMR2 |=0x0200 ) IC4=>TI3 read PWM from B0 for PWM B ,so configure it as input floating CCMR1=0x0201; CCMR2=0x0201; CCER=0x3131; Mapping of channels of timer 3 on I/O pins TIM3_cH1->TI1-> Port A6 TIM3_cH2->TI2-> Port A7 TIM3_cH3->TI3-> Port B0 TIM3_cH4->TI4-> Port B1