风扇模块
风扇模块由精密的N20电机、电机驱动和螺旋桨构成,主要用于搭建风车、DIY电风扇、制作灭火机器人等应用。
该模块使用LG-L9110(H桥)芯片驱动电机。可通过INA,INB的电平组合实现正转、反转、刹车、高阻4种状态。
参数表
风扇模块采用的是L9110马达驱动控制芯片,
风扇模块原理图:
示例代码:
#define M1 2
#define M2 3
int8_t MSpeed = 0;
uint8_t Dir = 0;
void setup() {
// put your setup code here, to run once:
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
InitTimer2();
}
void InitTimer2(void) //100us@12.000MHz
{
TCCR2A=0;
TCCR2B=_BV(CS21)|_BV(CS20);
TIMSK2=_BV(TOIE2);
TCNT2=206;
sei();
}
ISR(TIMER2_OVF_vect)
{
TCNT2=206; //定时器中断 100us
MotorPwmCtrl();
}
void MotorControl(int8_t Speed)
{
if (Speed >= 0)
{
Dir = 1;
MSpeed = Speed;
}
else
{
Dir = 0;
MSpeed = -Speed;
}
MSpeed /= 10;
}
void MotorPwmCtrl(void)
{
static uint8_t time = 0;
if (time < MSpeed)
{
if (Dir)
{
digitalWrite(M1, HIGH);
digitalWrite(M2, LOW);
}
else
{
digitalWrite(M2, HIGH);
digitalWrite(M1, LOW);
}
}
else
{
digitalWrite(M1, LOW);
digitalWrite(M2, LOW);
}
if (++time >= 10)
{
time = 0;
}
}
void loop() {
// put your main code here, to run repeatedly:
static uint32_t timer;
static uint8_t n = 0;
if (timer > millis())
return;
if (n == 0)
{
MotorControl(100);
timer = millis() + 2000;
n = 1;
}
else if (n == 1)
{
MotorControl(0);
timer = millis() + 2000;
n = 2;
}
else if (n == 2)
{
MotorControl(50);
timer = millis() + 2000;
n = 3;
}
else if (n == 3)
{
MotorControl(-50);
timer = millis() + 2000;
n = 0;
}
}