![]() |
樓主牛人,學習了! |
mqwu 發表于 2014-10-1 11:12 請教下,如何控制直流馬達停止及圈數? |
非常好東西,學習一下! |
沒有影響,因為PIC18系列運行一個指令周期很短,只要4個時鐘周期,你若用4M的晶振, 也就需要1uS,而數碼管的動態掃描用的delay(10),就相當于10x10uS,遠比E2PROM寫和讀長。 |
當運行EEPROM_write();時, 對數碼管顯示,步進電機有影響嗎 |
其實理工男蠻苦的,整天面對電子元件和電腦,較盡腦汁做一些屌絲們都不愿意做的事,也沒有樓上你說的那么有才, 只是忘掉世俗的浮躁和唯物拜金,做一點自己喜歡的事情罷了。同時也為了能夠生存混口飯吃,就這么簡單。 |
是的,你說的非常正確 |
底下那個傳感器是用來檢測標簽到位嗎 |
mqwu 發表于 2014-10-1 11:12 兄弟你太有才了,不得不佩服,這樣具有學習能力的單片機大有前途呀。 |
用來貼產品的標簽,每次員工值接用一只手就可以貼標簽了, 沒有這個勢必要用兩只手,相當于解放一只手拿產品做別的事,效率提高了,下一步,我打算用直流帶減速器馬達, 用PWM+AD來改變占空比控制,這樣電路更簡潔,程序更優化,我查了下,淘寶上賣的都是這種設計,我準備做個5臺給生產線試用 |
本帖最后由 明白 于 2014-10-1 11:13 編輯 步進電機速度高了,噪音挺大 機器用來干什么的? 先占個位! ![]() |
非常有水平,做得挺牛 建議樓上跟中央臺《我愛發明》欄目聯系,會優先采納。 |
Label feeder |
27.35 KB, 下載次數: 38, 下載積分: 黑幣 -5
好東西 ,樓主能上傳個電路圖嗎? |
佩服啊 換個殼子的話 就可以量產做產品了 應該有銷路的. |
大神級別的作品啊 學習了 |
source code /**********************************************************/ /* PIC18F4620 ????: 1?42 6???????, 1?L298N????,2??????AD?? */ /* 1??????????? */ #include <pic18.h> __PROG_CONFIG(1,0xc200); __PROG_CONFIG(2,0x001e); __PROG_CONFIG(3,0x0100); __PROG_CONFIG(4,0x0081); __PROG_CONFIG(5,0xc00f); __PROG_CONFIG(6,0xe00f); __PROG_CONFIG(7,0x400f); #define uchar unsigned char #define uint unsigned int #define seg1 PORTAbits.RA2 #define seg2 PORTAbits.RA3 #define seg3 PORTAbits.RA4 #define seg4 PORTAbits.RA5 #define reset_check PORTEbits.RE0//pull-up with a 4.7K res to Vcc #define count_clr PORTEbits.RE1//pull-up with a 4.7K res to Vcc const uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; const uchar coil_active[]={0x01,0x05,0x04,0x06,0x02,0x0a,0x08,0x09}; static uchar wait_t=0,speed=100; uint count; uchar num0,num1,num2,num3; void delay(uint z); void Port_init(void); void display(void); void EEPROM_write(uchar wr_data,uchar wr_addr); void timer0_init(void); uchar EEPROM_read(uchar addr); void forward(void); void hyst_forward(void); void main() { uint temp1,temp2; Port_init(); timer0_init(); delay(10); temp1=EEPROM_read(0x01);//Æô¶ˉ¶áè¡éÏò»′Îê1óñêÇ©μÄêy¾Y£» temp2=EEPROM_read(0x02);//Æô¶ˉ¶áè¡éÏò»′Îê1óñêÇ©μÄêy¾Y£» count=temp1*256+temp2; while(1) { display(); if (reset_check==0) { delay(10); if(reset_check==0) { count++; hyst_forward(); EEPROM_write(count/256,0x01); EEPROM_write(count%256,0x02); if(count==10000) count=0; while(!reset_check); } } else forward(); if (count_clr==0) { delay(10); if (count_clr==0) { count=0; EEPROM_write(0,0x01);//clear the data from E2PROM EEPROM_write(0,0x02);//clear the data from E2PROM } } } } void delay(uint z) { uint x,y; for(x=0;x<z;x++) for(y=0;y<10;y++); } void Port_init(void) { TRISA=0x03; ADCON1=0x0D;//select AN0&AN1 as analog input channel; ADCON2=0x3A;//left justified, 20Tad, Tosc/32; TRISD=0x00; PORTD=0xff;//Numerical LED scanning; TRISC=0x00;//Step-Motor winding power-up; PORTC=0x00; TRISE=0x07;//set the PORTE as input I/O; } void timer0_init(void) { INTCON=0xE0;//GIE, PEIE and timer0 overflow interrupt; T0CON=0x08; TMR0H=(65535-1000)/256; //set the time to be 1ms; TMR0L=(65535-1000)%256; //set the time to be 1ms; TMR0ON=1; } void display(void) { num0=count/1000; num1=count%1000/100; num2=count%100/10; num3=count%10; PORTD=table[num0]; seg1=0; delay(10); seg1=1; PORTD=table[num1]; seg2=0; delay(10); seg2=1; PORTD=table[num2]; seg3=0; delay(10); seg3=1; PORTD=table[num3]; seg4=0; delay(10); seg4=1; } void EEPROM_write(uchar wr_data,uchar wr_addr) { GIE=0; EEIF=0; EEADR=wr_addr; EEDATA=wr_data; EECON1bits.EEPGD=0;// EECON1bits.CFGS=0;// EECON1bits.WREN=1; EECON2=0x55; EECON2=0xaa; EECON1bits.WR=1; while(!EEIF); PIR2bits.EEIF=0; EECON1bits.WREN=0; GIE=1; } uchar EEPROM_read(uchar addr) { uchar temp; EEADR=addr; EECON1bits.EEPGD=0; EECON1bits.CFGS=0; EECON1bits.RD=1; // asm("NOP"); temp=EEDATA; while(EECON1bits.RD); return temp; } void forward(void) { static uchar j; for (j=0; j<8; j++) { PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); } } //*μ±¼ì2éμĸ′λDÅoÅo󣬡¡Ñóê±ò»¶Îê±¼äèñêÇ©íÑàë¾íÖ½£¬Â¶3öà′òÔ±ã2ù×÷Ô±ÄÃè¡£a£ˉ/ void hyst_forward(void) { static uchar j; while(wait_t--) { for (j=0; j<8; j++) { PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); PORTC=coil_active[j]; delay(50); PORTC=0xff; delay(speed); PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); PORTC=coil_active[j]; delay(5); PORTC=0xff; delay(speed); } } } void interrupt timer0()//continous check if the speed & wait_t are changed { uchar i,count1; uint adval,sum=0; if (TMR0IF==1) { TMR0IF=0; TMR0ON=0; TMR0H=(65535-1000)/256; //set the time to be 1ms; TMR0L=(65535-1000)%256; //set the time to be 1ms; TMR0ON=1; count1++; if (count1==3) { for (i=0;i<10;i++)//sampling 10 times to get the stable data; { ADCON0=0x00; //convert AN0 channel; asm("NOP"); asm("NOP");asm("NOP"); GO=1; while(GO); adval=ADRESH; sum+=adval; speed=(int)sum/10/10;//due to dalay()routine, this needs to be divided by 10; } } if (count1==6) { count1=0; for (i=0;i<10;i++)//sampling 10 times to get the stable data; { ADCON0=0x04;//convert AN1 channel; asm("NOP"); asm("NOP");asm("NOP"); GO=1; while(GO); adval=ADRESH; sum+=adval; wait_t=(int)sum/10/2;//upon this actual operation; } } } } |