Salted fish ZTMR example-control motor
Main control board: ZTMR1.1python development board
N20 gear motor ( motor on four-wheel drive)
N20 gear motor, all-metal structure, copper gear box, equipped with all-steel precision micro gears, suitable for making all kinds of precision robot models and technology models. This gear motor has a fire extinguishing capacitor at the tail to improve sensitivity.
(1) The length of the motor (including gearbox) is 24mm,
(2) Width 12mm,
(3) Height 10mm
(4) Shaft diameter: 3mm D-shaped shaft
(5) Shaft length: 4mm
(6) Voltage: 12v
Pin description
Pin | Explanation |
---|---|
B10 | Only when it is high level, the motor will turn |
B8 | PWM control A motor |
B9 | PWM control B motor |
B12 | AIN1 |
B13 | AIN2 |
B14 | BIN1 |
B15 | BIN2 |
PWM (Pulse Width Modulation Module)
from pyb import Pin,Timer
p = Pin('X1')
ti = Timer(2,freq=1000) #X1是定时器2的CH1
ch = ti.channel(1,Timer.PWM,pin=p) #设置PWM引脚
ch.pluse_width_precent(50) #设置PWM输出占空比
Pulse width modulation is an analog control method, which modulate the bias of the transistor base or MOS tube gate according to the corresponding load changes to achieve the change of the transistor or MOS tube conduction time, so as to achieve the output of the switching power supply change. In this way, the output voltage of the power supply can be kept constant when the working conditions change, and it is a very effective technology for controlling the analog circuit by using the digital signal of the microprocessor.
Check the ZTMR schematic diagram
Pin | Timer | Corresponding channel CH |
---|---|---|
B8 | TIM10 | CH1 |
TIM4 | CH3 | |
B9 | TIM4 | CH4 |
TIM11 | CH1 |
#main.py -- put your code here!
from pyb import Pin,Timer
cs = Pin('B10',Pin.OUT_PP) #B10设置为输出引脚输出高电平
cs(1)
ch1 =None
ch2 =None #初始化
#A电机正反转
p1 = Pin('B8')
tim1 = Timer(10, freq=120)
ch1 = tim1.channel(1, Timer.PWM, pin=p1)
ch1.pulse_width_percent(10)
AI1 = Pin('B12',Pin.OUT_PP)
AI2 = Pin('B13',Pin.OUT_PP)
AI1(1) #AI1值:0 0 1
AI2(0) #AI2值:0 1 0
#状态: 停 正转 反转
#B电机正反转
p2 = Pin('B9')
tim2 = Timer(4, freq=120)
ch2 = tim2.channel(4, Timer.PWM, pin=p2)
ch2.pulse_width_percent(50)
BI3 = Pin('B14',Pin.OUT_PP)
BI4 = Pin('B15',Pin.OUT_PP)
BI3(1) #BI1值:0 0 1
BI4(0) #BI2值:0 1 0
#状态: 停 正转 反转