 |
:: مهندس متواجد ::
تاريخ التسجيل: Sep 2012
الدولة: المغرب
المشاركات: 109
|
|
نشاط [ abou yasser ]
قوة السمعة:0
|
|
12-11-2012, 12:42 PM
المشاركة 1
|
|
السلام عليكم
لقد قمت بكتابه كود التحكم في dc motor ب ل pwm ب pic16f876
في المحاكاة عمل لكن في الواقع لم يعمل
و لقد استعملت انا و اصدقائي MOSFET و 1n4007 من اجل الموتور و هذا هو الكود
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
float temp;
char duty;
char txt1[] = "ENSEM";
char txt2[] = "R:";
char txt3[15];
void affiche(char x)
{int y;
y=((duty*100)/255);
IntToStr(y, txt3);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt1);
Lcd_Out(2,1,txt2);
Lcd_Out(2,4,txt3);
Lcd_Out(2,10,"%");
}
void main()
{
ADCON0=0b00000101; //Configuration de L'ADC
ADCON1=0b10001110;
ADC_Init();
PWM1_Init(20000);
LCD_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,4,txt1);
Lcd_Out(2,4,txt2);
while(1)
{
temp=ADC_Read(0); //lecture du CAN
delay_ms(500);
duty=((255*temp)/1023); //rapport cyclique=((100%*valeur)/1023)
affiche(duty);
PWM1_Start(); //debut de pwm
PWM1_Set_Duty(duty); //le rapport cyclique
delay_ms(500);
}
}
|
|