SASSI Sam
Newbie level 6
- Joined
- Nov 18, 2013
- Messages
- 11
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,356
Hi every body, I try to drive a DC Motor depending on temperature, this is my program with MikroC, but always the Motor is working with the same speed (duty), could some one pleaaase help me where is the problem!! thanks..
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 //////// sbit LCD_RS at RB1_bit; sbit LCD_EN at RB2_bit; sbit LCD_D7 at RB7_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D4 at RB4_bit; // Pin direction sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB7_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB4_bit; char str [16]; int temp; unsigned char duty = 0; void main() { TRISB = 0x00; TRISA = 0xFF; adc_init(); lcd_init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); PWM1_Init(1500); PWM1_Start(); PWM1_Set_Duty(duty); while (1) { temp = adc_read(0); temp = temp/2; delay_ms(10); inttostr(temp,str); lcd_out(1,1,str); delay_ms(10); ///////////////////// if(5<=temp<15) { delay_ms(40); PORTB = 0x01; Delay_ms(10); duty = 50; PWM1_Set_Duty(duty); } if(15<=temp<20) { delay_ms(40); PORTB = 0x01; duty = 127; PWM1_Set_Duty(duty); } if(20<=temp<70) { delay_ms(40); PORTB = 0x01; duty = 255; PWM1_Set_Duty(duty); } else { Duty = 0; PWM1_Set_Duty(duty); } } }
Last edited by a moderator: