本设计为步进电机开环驱动,使用STC15W408AS单片机作为主控,12V电源输入,使用两个A4950电机驱动,最高电流可达3.5A。三个输入使用光耦隔离,就算驱动板炸了也不会炸主控,四个拨码开关可调节细分和电流(扭矩),预留串口接口可烧程序或用于监控调试。
原理图,PCB,程序都已经上传附件。
成品图:正面
背面:
应用外观:
整体外观:
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件)
单片机源程序如下:
- #include <reg51.h>
- #define Timer0_time 35
- #define Timer0_H (65536-Timer0_time)/256
- #define Timer0_L (65536-Timer0_time)%256
- sbit led_green = P3^6; //指示灯
- sbit led_red = P3^7;
- sbit in_clk = P3^2; //输入信号上限1.2KHz
- sbit in_dir = P1^7;
- sbit in_en = P1^6;
- sbit sw0 = P2^0; //选择开关
- sbit sw1 = P2^1;
- sbit sw2 = P2^2;
- sbit sw3 = P2^3;
- sbit in1 = P2^4; //电机驱动
- sbit in2 = P2^5;
- sbit in3 = P2^6;
- sbit in4 = P2^7;
- unsigned char code step8_tab[8]={0x8F,0XAF,0X2F,0X6F,0X4F,0X5F,0X1F,0X9F};
- unsigned char duty=0,target=30,set=0,clin=0;
- char step=0;
- void delayms(unsigned int x) //@35MHz
- {
- unsigned int y;
- for(x;x>0;x--)
- for(y=3000;y>0;y--);
- }
- void delay(unsigned int x)
- {
- for(x;x>0;x--);
- }
- void sys_init()
- {
- EX0=1;
- IT0=1;
-
- TMOD=0X01;
- TH0=Timer0_H;
- TL0=Timer0_L;
- EA=1;
- ET0=1;
- TR0=1;
- }
- void main()
- {
- unsigned char div,cur;
- P2=0X0F;
- cur=P2 & 0x03;
- div=P2 >>2;
- div=div & 0x03;
- switch(cur) //拨码选择电流/扭矩
- {
- case 0X03: target=30; break;
- case 0X02: target=40; break;
- case 0X01: target=55; break;
- case 0X00: target=65; break;
- default : target=30;break;
- }
- switch(div) //拨码选择分频系数
- {
- case 0X03: set=0; break;
- case 0X02: set=2; break;
- case 0X01: set=4; break;
- case 0X00: set=8; break;
- default : set=0;break;
- }
-
- P3=0XFF;
-
- sys_init();
- while(1)
- {
-
- }
- }
- void init0() interrupt 0
- {
- unsigned char i;
- clin++;
- if(clin>=set) //细分
- {
- clin=0;
- if(in_en)
- {
- if(in_dir) //正转
- {
- step++;
- if(step>=8)
- step=0;
- P2=step8_tab[step];
-
- }
- else //反转
- {
- step--;
- if(step<0)
- step=7;
- P2=step8_tab[step];
-
- }
-
- }
-
- }
- }
- void timer0() interrupt 1
- {
- TH0=Timer0_H;
- TL0=Timer0_L;
- duty++;
- if(duty>=100)
- duty=0;
- (duty<target)?(P2=step8_tab[step]):(P2=0X0F);
- }
复制代码
所有资料51hei提供下载:
步进电机驱动.zip
(59.1 KB, 下载次数: 24)
|