L6234无刷直流电机控制

我本来今天想来一发源码分析的,但是我手头没有鼠标,我一想截图那么多就算了,我发一个电机驱动的代码就行。
[simplefoc-云台电机2804+as5600]
[simplefoc-原理图(stl6234+ina240)]
所以一个输出要两个接口控制
l6234 驱动器有 3 个输出:out1、out2 和 out3。每个输出由 2 个引脚控制:输入 (in) 和使能 (en),例如 out1 由 in1 和 en1 控制。下图显示了每个半桥的控制逻辑:
逻辑电平
输出电平
另外这个原理图看左边,为了方便可以把使能脚直接都拉低
这样使用三个引脚模拟也是可以的
1.l6234 三相电机驱动器
2.6 x 33k 欧姆电阻器
3.3 x 10k 欧姆电阻器
4.4 x 1 欧姆电阻器(功率为 2 w 或更高)
5.2 x 1n4148 二极管
6.100 uf 电解电容器(16v 或更高)
7.1 uf 电解电容器(16v 或更高)
8.220 nf (0.22 uf) 陶瓷电容器
9.100 nf (0.1 uf) 陶瓷电容器
10.10 nf (0.01 uf) 陶瓷电容器
11.2 x 按钮
12.12v 电源
#define speed_up a0#define speed_down a1#define pwm_max_duty 255#define pwm_min_duty 50#define pwm_start_duty 100byte bldc_step = 0, motor_speed;unsigned int i;void setup(){ ddrd |= 0x38; // configure pins 3, 4 and 5 as outputs portd = 0x00; ddrb |= 0x0e; // configure pins 9, 10 and 11 as outputs portb = 0x31; // timer1 module setting: set clock source to clki/o / 1 (no prescaling) tccr1a = 0; tccr1b = 0x01; // timer2 module setting: set clock source to clki/o / 1 (no prescaling) tccr2a = 0; tccr2b = 0x01; // analog comparator setting acsr = 0x10; // disable and clear (flag bit) analog comparator interrupt pinmode(speed_up, input_pullup); pinmode(speed_down, input_pullup);}// analog comparator isrisr(analog_comp_vect){ // bemf debounce for (i = 0; i 100) { delaymicroseconds(i); bldc_move(); bldc_step++; bldc_step %= 6; i = i - 20;}motor_speed = pwm_start_duty;acsr |= 0x08; // enable analog comparator interruptwhile (1){ while (!(digitalread(speed_up)) && motor_speed pwm_min_duty) { motor_speed--; set_pwm_duty(motor_speed); delay(100); }}}void bemf_a_rising(){ adcsrb = (0 << acme); // select ain1 as comparator negative input acsr |= 0x03; // set interrupt on rising edge}void bemf_a_falling(){ adcsrb = (0 << acme); // select ain1 as comparator negative input acsr &= ~0x01; // set interrupt on falling edge}void bemf_b_rising(){ adcsra = (0 << aden); // disable the adc module adcsrb = (1 << acme); admux = 2; // select analog channel 2 as comparator negative input acsr |= 0x03;}void bemf_b_falling(){ adcsra = (0 << aden); // disable the adc module adcsrb = (1 << acme); admux = 2; // select analog channel 2 as comparator negative input acsr &= ~0x01;}void bemf_c_rising(){ adcsra = (0 << aden); // disable the adc module adcsrb = (1 << acme); admux = 3; // select analog channel 3 as comparator negative input acsr |= 0x03;}void bemf_c_falling(){ adcsra = (0 << aden); // disable the adc module adcsrb = (1 << acme); admux = 3; // select analog channel 3 as comparator negative input acsr &= ~0x01;}void ah_bl(){ portb = 0x04; portd &= ~0x18; portd |= 0x20; tccr1a = 0; // turn pin 11 (oc2a) pwm on (pin 9 & pin 10 off) tccr2a = 0x81; //}void ah_cl(){ portb = 0x02; portd &= ~0x18; portd |= 0x20; tccr1a = 0; // turn pin 11 (oc2a) pwm on (pin 9 & pin 10 off) tccr2a = 0x81; //}void bh_cl(){ portb = 0x02; portd &= ~0x28; portd |= 0x10; tccr2a = 0; // turn pin 10 (oc1b) pwm on (pin 9 & pin 11 off) tccr1a = 0x21; //}void bh_al(){ portb = 0x08; portd &= ~0x28; portd |= 0x10; tccr2a = 0; // turn pin 10 (oc1b) pwm on (pin 9 & pin 11 off) tccr1a = 0x21; //}void ch_al(){ portb = 0x08; portd &= ~0x30; portd |= 0x08; tccr2a = 0; // turn pin 9 (oc1a) pwm on (pin 10 & pin 11 off) tccr1a = 0x81; //}void ch_bl(){ portb = 0x04; portd &= ~0x30; portd |= 0x08; tccr2a = 0; // turn pin 9 (oc1a) pwm on (pin 10 & pin 11 off) tccr1a = 0x81; //}void set_pwm_duty(byte duty){ if (duty pwm_max_duty) duty = pwm_max_duty; ocr1a = duty; // set pin 9 pwm duty cycle ocr1b = duty; // set pin 10 pwm duty cycle ocr2a = duty; // set pin 11 pwm duty cycle}代码我就先不解释了,看懂需要看atmega的书手册
这个是atmega的中文数据手册了:
链接:https://pan.baidu.com/s/13bg6a6kgsjhuscstlkjt9q 提取码:3lna

10V/20A恒定电流、恒定电压降压型转换器
华为智选720全效空气净化器1Pro京东商城开启首销
5倍速快速成长,浪潮存储是怎么做到的?
航天器首次探测到宇宙射线电子波的爆发
通过任意长度的铜线控制远端负载的电压
L6234无刷直流电机控制
展开说说机器视觉与计算机视觉的区别
OPPO Reno率先升级互传,有OPPO手机的小伙伴们赶快下载尝鲜吧
我国传感器市场主要还是要走性价比的路线
网线顺序颜色排列
物流行业形成了以无人机、无人车为代表的新型供应链体系 朝着智能化方向发展
苹果否认近期推出 iPhone 6 电池更换计划
如何快速看懂电气原理图
如何在透传数据流中增加必要的扩展业务
台湾LED路灯换装开始 各厂商极力备战
智能服装有哪些功能,又能给我们生活带来哪些变化?
基于1394总线的工业相机图像采集程序设计
荣耀音乐小巨蛋怎么样
编程软件LiteBee Go迎来更新,该如何安装和使用
如何连接两个µC来控制GMSL