welcom ! Handel home

2015年1月23日 星期五

Step Motor type

Step Motor   
永久磁鐵 PM (permanentmagnet Type) alnico (45", 90") , ferrite  陶鐵(7.5" , 15")
可變磁阻 VR ( Variable reluctance type) 15"
複合式 (Hybrid Type) 1.8"  .. 3.6"













I2C 1602 LCM Drive DEMO Code by C ( 20X4 )

I2C LCM  Drive DEMO Code  by C

===========================================
[i2c_drv.h]

#define Byte unsigned char
#define Word unsigned long

struct st{
Byte yy;
Byte xx;
char *mess;
};

extern Byte ASCIICODE[16];
extern unsigned char LCDBUFF[80];
extern struct st mess_array[];

extern void i2clcm_WriteCommand(unsigned char nData);
extern void i2clcm_WriteData(unsigned char nData);

extern void i2clcm_init(void);
extern void i2clcm_setxy(Byte posy,Byte posx);
extern void i2clcm_show_char(Byte posy,Byte posx,Byte chardata);
extern void i2clcm_Show_String(Byte posy,Byte posx,char *strdata);


extern void i2clcm_Show_byte(Byte posy,Byte posx,Byte chardata);
extern void i2clcm_Show_word(Byte posy,Byte posx,Word worddata);

// show value for 5 number Dec and point for set (0 to 4)
//Rang 65535 .. 0 or 6.5535 .. 0.0001
// ext: show 12345 => i2clcm_Show_number(1,1,12345,0)
// ext: show 1.2345 => i2clcm_Show_number(1,1,12345,1)
// ext: show 12.345 => i2clcm_Show_number(1,1,12345,2)
extern void i2clcm_Show_number(Byte posy,Byte posx,Word value,Byte pt);

extern void i2clcm_buffer_fill(Byte fillcode);
extern void i2clcm_Show_buffer(Byte count);


============================================

============================================
[i2c_drv.c]

//================================================
//*** i2clcm Drive V 1.0 ****
//20150121    Handel    edit v1.0
//================================================

extern int PCF8547_WriteData( unsigned char Data  );
extern int PCF8547_ReadData( unsigned char *pData );

#define Byte unsigned char
#define Word unsigned long

//***  I2C LCM Parameter
#define lcmrow 20
#define lcmcol 4
#define line1 0x80
#define line2 0xc0
#define line3 0x94
#define line4 0xd4

Byte ASCIICODE[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
Byte LCDBUFF[80];

struct st{
Byte yy;
Byte xx;
char *mess;
};

struct st mess_array[] = {
{ 1, 10,"mess1 "}, //0
{ 2, 10,"mess2 "}, //1
{ 3, 10,"mess3 "}, //2
{ 4, 10,"mess4 "}, //3
{ 1, 10,"ok "} , //4
{ 1,  1,"Handel  V1.0"},//5
{ 1,  1,"Hello !"}, //6
{ 1,  1,"OK    !"}, //7
{ 1,  1,"ERR   !"}, //8
{ 1,  1,"Test ..."} //9
};



void i2clcm_WriteCommand(unsigned char nData){
unsigned char  WR_Comm;

//__delay_cycles(500); // 10us * 10 = 100us

// d7,d6,d5,d4, x,en,rw,rs
// d7,d6,d5,d4, 1, 1, 0, 0
WR_Comm = (0x0c |(nData & 0xf0));
PCF8547_WriteData( WR_Comm );
// d7,d6,d5,d4, 1, 0, 0, 0
WR_Comm = (0x08 |(nData & 0xf0));
PCF8547_WriteData( WR_Comm );
// __delay_cycles(500); // 10us * 10 = 100us

// d3,d2,d1,d0, 1, 1, 0, 0
WR_Comm =0x0c |((nData & 0x0f)<<4 p=""> PCF8547_WriteData( WR_Comm );
// d3,d2,d1,d0, 1, 0, 0, 0
WR_Comm =0x08 |((nData & 0x0f)<<4 p=""> PCF8547_WriteData( WR_Comm );

//__delay_cycles(10000);//600us

}
void i2clcm_WriteData(unsigned char nData){
unsigned char  WR_Data;

// d7,d6,d5,d4, x,en,rw,rs
// d7,d6,d5,d4, 1, 1, 0, 1
WR_Data =0x0d |(nData & 0xf0);
PCF8547_WriteData( WR_Data );
// __delay_cycles(500); // 10us * 10 = 100us
// d7,d6,d5,d4, 1, 0, 0, 1
WR_Data =0x09 |(nData & 0xf0);
PCF8547_WriteData( WR_Data );
// __delay_cycles(500); // 10us * 10 = 100us

// d3,d2,d1,d0, 1, 1, 0, 1
WR_Data =0x0d |((nData & 0x0f)<<4 p=""> PCF8547_WriteData( WR_Data );
// __delay_cycles(500); // 10us * 10 = 100us
// d3,d2,d1,d0, 1, 0, 0, 1
WR_Data =0x09 |((nData & 0x0f)<<4 p=""> PCF8547_WriteData( WR_Data );

//__delay_cycles(500);//600us
}

void i2clcm_init(void){
i2clcm_WriteCommand( 0x33 );
i2clcm_WriteCommand( 0x32 );
//    WriteCommand( 0x38 );
//    WriteCommand( 0x28 );

i2clcm_WriteCommand( 0x28 );
//    __delay_cycles(1000000);  //delay ~60ns
i2clcm_WriteCommand( 0x08 );
    //__delay_cycles(5000);  //delay ~5ms
i2clcm_WriteCommand( 0x01 );
    //__delay_cycles(5000);  //delay ~5ms
i2clcm_WriteCommand( 0x06 );
    //__delay_cycles(5000);  //delay ~5ms
i2clcm_WriteCommand( 0x0C );
    //__delay_cycles(5000);  //delay ~5ms
    //WriteCommand( 0x0f );
}


void i2clcm_setxy(Byte posy,Byte posx){
Byte lcm_memadd;

if(posx > lcmrow )posx=lcmrow;
if(posy > lcmcol )posy=lcmcol;
if(posy==1)lcm_memadd = line1+posx-1;
if(posy==2)lcm_memadd = line2+posx-1;
if(posy==3)lcm_memadd = line3+posx-1;
if(posy==4)lcm_memadd = line4+posx-1;

i2clcm_WriteCommand( lcm_memadd );
}

void i2clcm_show_char(Byte posy,Byte posx,Byte chardata){
i2clcm_setxy(posy,posx);
i2clcm_WriteData(chardata);
}

void i2clcm_Show_String(Byte posy,Byte posx,char *strdata){
char *pp;

i2clcm_setxy(posy,posx);
    pp=strdata;
while(*pp !='\0'){
i2clcm_WriteData(*pp);
pp++;
}
}

void i2clcm_Show_byte(Byte posy,Byte posx,Byte chardata){

i2clcm_setxy(posy,posx);
i2clcm_WriteData(ASCIICODE[(chardata&0xf0)>>4]);
//i2clcm_setxy(posy,posx+1);
i2clcm_WriteData(ASCIICODE[(chardata&0x0f)]);
}


void i2clcm_Show_word(Byte posy,Byte posx,Word worddata){
i2clcm_Show_byte(posy,posx,(Byte )((worddata&0xff00)>>8));
i2clcm_Show_byte(posy,posx+2,(Byte )(worddata&0x00ff));
}

// show value for 5 number Dec and point for set (0 to 4)
//Rang 65535 .. 0 or 6.5535 .. 0.0001
// ext: show 12345 => i2clcm_Show_number(1,1,12345,0)
// ext: show 1.2345 => i2clcm_Show_number(1,1,12345,1)
// ext: show 12.345 => i2clcm_Show_number(1,1,12345,2)
void i2clcm_Show_number(Byte posy,Byte posx,Word value,Byte pt){

Byte n[5]={0,0,0,0,0};
    Byte i;

n[4]=  value %10;
n[3]= (value/10)%10;
n[2]= (value/100)%10;
n[1]= (value/1000)%10;
n[0]= (value/10000)%10;


i2clcm_setxy(posy,posx);
for(i = 0; i<=4 ; i++ ){
//i2clcm_setxy(posy,posx+i);
i2clcm_WriteData(ASCIICODE[n[i]]);
if(i==(pt-1)){
posx++;
i2clcm_setxy(posy,posx+i);
i2clcm_WriteData('.');
}
}

}

void i2clcm_buffer_fill(Byte fillcode){
Byte i;
for(i=0;i<80 fillcode="" i="" p="">}

//buffer show 8 bank , bank0..7
void i2clcm_Show_buffer(Byte count){
Byte i,loopadd;

loopadd= (count%8)*10;

i2clcm_setxy(count/20,count%20);

for(i=0;i<10 i="" p=""> i2clcm_WriteData(LCDBUFF[loopadd+i]);
}

}


===========================================

2015年1月4日 星期日

步進馬達 趨動

步進馬達的種類依照結構來分可以分成三種:
>>永久磁鐵PM式(permanentmagnet type):alnico (45", 90") , ferrite  陶鐵(7.5" , 15")
>>可變磁阻VR 式(variable reluctance type): 15"
>>複合式(hybrid type): 1.8".. 3.6"

步進馬達的特點
1.旋轉的角度和輸入的脈波數成正比,因此用開迴路控制即可達成高精
確角度。
2.啟動、停止、正反轉的應答性良好,控制容易。
3.每一步級的角度誤差小,而且沒有累積誤差。
4.靜止時,步進馬達有很高的保持轉矩(Holding Torque),可保持在停
止的位置,不需使用煞車迴路就不會自由轉動。
5.可靠性高,整個系統的價格低。


步進馬達依定子線圈的相數不同 可分成二相、三相、四相及五相
式,小型步進馬達以四相式較為普遍。圖3-1即為四相步進馬達的內部
接線圖。當送入一個脈衝電流至步進馬達,可在相對應處停止轉動,這
種走一步即停住而得到的角度稱為基本步進角。
步進角會因激磁方式不同而有所不同。
基本步進角的計算公式如下:
基本步進角=360°/(相數×轉子齒數)
例如:四相50尺的基本步進角為360°/(4×50)=1.8°
也就是說,四相50齒的步進馬達走200步正好是一圈。一般的小型步進
馬達齒數為50齒較多。