Bueno, pues el titulo del post lo dice todo, hoy traigo un sistema electrónico que sirve para variar la velocidad de un motor mediante PWM, la modificación del ciclo de trabajo se hace mediante un teclado matricial y hay una pantalla lcd de 20 x 4.
Por fuera de esto tiene dos pulsadores que sirven para cambiar el sentido de giro del motor, se programó con CCS y el pic es el 16f877, aquí esta el esquema
#INCLUDE <16F877A.H>
#USE fast_io(C)
#FUSES NOWDT, XT, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#USE DELAY (CLOCK=4M)
#DEFINE use portd_lcd TRUE
#INCLUDE <FLEX_LCD420.C>
#USE fast_io(B)
#USE fast_io(D)
#BYTE PORTA=0X07
#BYTE TRISA=0X85
#BYTE PORTB=0x06
#BYTE TRISB=0X86
#BYTE PORTC=0X07
#BYTE TRISC=0X87
#BYTE PORTD=0X08
#BYTE TRISD=0X88
#BIT B1=PORTC.0
#BIT B2=PORTC.1
#BIT GIRO1=PORTC.7
#BIT GIRO2=PORTC.5
VOID MAIN(void){
trisa=0x00;
trisb=0x00;
trisc=0x00;
trisd=0x00;
porta=0x00;
portb=0x00;
portc=0x00;
portd=0x00;
lcd_init();
trisd=0x00;
trisb=0xF0;
trisc=0b10100000;
unsigned long int i;
unsigned long int total;
unsigned long int acumulador;
unsigned long int numero;
int enter;
int z;
int16 total_pwm;
output_low(PIN_C2);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,255,1);
set_pwm1_duty(0);
enter=0;
i=0;
total=0;
acumulador=0;
numero=0;
z=0;
total_pwm=0;
B1=0;
lcd_gotoxy(1,3);
lcd_putc("GIRO DERECHA " ) ;
lcd_gotoxy(1,1) ;
lcd_putc("DUTY: " ) ;
while(1){
while(enter<1){
portb=0x01;
if(portb==0x21){
while(portb==0x21){}
lcd_putc("1" ) ;
numero=1;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x41){
while(portb==0x41){}
lcd_putc("2 " ) ;
numero=2;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x81){
while(portb==0x81){}
lcd_putc("3" ) ;
numero=3;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
portb=0x02;
if(portb==0x22){
while(portb==0x22){}
lcd_putc("4" ) ;
numero=4;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x42){
while(portb==0x42){}
lcd_putc("5" ) ;
numero=5;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x82){
while(portb==0x82){}
lcd_putc("6 " ) ;
numero=6;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
portb=0x04;
if(portb==0x24){
while(portb==0x24){}
lcd_putc("7 " ) ;
numero=7;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x44){
while(portb==0x44){}
lcd_putc("8" ) ;
numero=8;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x84){
while(portb==0x84){}
lcd_putc("9 " );
numero=9;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
portb=0x08;
if(portb==0x48){
while(portb==0x48){}
lcd_putc("0 " ) ;
numero=0;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x88){
while(portb==0x88){}
enter=1;
}
if(z==2){
enter=1;
}
if(giro1==1){
B1=1;
lcd_gotoxy(1,3);
lcd_putc(" " );
lcd_gotoxy(1,3);
lcd_putc("GIRO IZQUIERDA" ) ;
lcd_gotoxy(7,1);
}
if(giro2==1){
B1=0;
lcd_gotoxy(1,3);
lcd_putc(" " ) ;
lcd_gotoxy(1,3);
lcd_putc("GIRO DERECHA" ) ;
lcd_gotoxy(7,1);
}
}
total_pwm = 10.24 * total;
lcd_gotoxy(1,2);
printf(lcd_putc,"PWM: %ld ", total); //m= y2 - y1 / x2 - x1
lcd_gotoxy(10,2);
lcd_putc('%');
set_pwm1_duty(total_pwm);
lcd_gotoxy(1,1);
enter=0;
total=0;
numero=0;
acumulador=0;
total_pwm=0;
z=0;
lcd_gotoxy(1,1);
lcd_putc(" " );
lcd_gotoxy(1,1);
lcd_putc("DUTY: " );
}
}
Alguna duda o algo me comentan!!!
Por fuera de esto tiene dos pulsadores que sirven para cambiar el sentido de giro del motor, se programó con CCS y el pic es el 16f877, aquí esta el esquema
#INCLUDE <16F877A.H>
#USE fast_io(C)
#FUSES NOWDT, XT, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#USE DELAY (CLOCK=4M)
#DEFINE use portd_lcd TRUE
#INCLUDE <FLEX_LCD420.C>
#USE fast_io(B)
#USE fast_io(D)
#BYTE PORTA=0X07
#BYTE TRISA=0X85
#BYTE PORTB=0x06
#BYTE TRISB=0X86
#BYTE PORTC=0X07
#BYTE TRISC=0X87
#BYTE PORTD=0X08
#BYTE TRISD=0X88
#BIT B1=PORTC.0
#BIT B2=PORTC.1
#BIT GIRO1=PORTC.7
#BIT GIRO2=PORTC.5
VOID MAIN(void){
trisa=0x00;
trisb=0x00;
trisc=0x00;
trisd=0x00;
porta=0x00;
portb=0x00;
portc=0x00;
portd=0x00;
lcd_init();
trisd=0x00;
trisb=0xF0;
trisc=0b10100000;
unsigned long int i;
unsigned long int total;
unsigned long int acumulador;
unsigned long int numero;
int enter;
int z;
int16 total_pwm;
output_low(PIN_C2);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,255,1);
set_pwm1_duty(0);
enter=0;
i=0;
total=0;
acumulador=0;
numero=0;
z=0;
total_pwm=0;
B1=0;
lcd_gotoxy(1,3);
lcd_putc("GIRO DERECHA " ) ;
lcd_gotoxy(1,1) ;
lcd_putc("DUTY: " ) ;
while(1){
while(enter<1){
portb=0x01;
if(portb==0x21){
while(portb==0x21){}
lcd_putc("1" ) ;
numero=1;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x41){
while(portb==0x41){}
lcd_putc("2 " ) ;
numero=2;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x81){
while(portb==0x81){}
lcd_putc("3" ) ;
numero=3;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
portb=0x02;
if(portb==0x22){
while(portb==0x22){}
lcd_putc("4" ) ;
numero=4;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x42){
while(portb==0x42){}
lcd_putc("5" ) ;
numero=5;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x82){
while(portb==0x82){}
lcd_putc("6 " ) ;
numero=6;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
portb=0x04;
if(portb==0x24){
while(portb==0x24){}
lcd_putc("7 " ) ;
numero=7;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x44){
while(portb==0x44){}
lcd_putc("8" ) ;
numero=8;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x84){
while(portb==0x84){}
lcd_putc("9 " );
numero=9;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
portb=0x08;
if(portb==0x48){
while(portb==0x48){}
lcd_putc("0 " ) ;
numero=0;
total=numero+acumulador;
acumulador=total*10;
z=z+1;
}
if(portb==0x88){
while(portb==0x88){}
enter=1;
}
if(z==2){
enter=1;
}
if(giro1==1){
B1=1;
lcd_gotoxy(1,3);
lcd_putc(" " );
lcd_gotoxy(1,3);
lcd_putc("GIRO IZQUIERDA" ) ;
lcd_gotoxy(7,1);
}
if(giro2==1){
B1=0;
lcd_gotoxy(1,3);
lcd_putc(" " ) ;
lcd_gotoxy(1,3);
lcd_putc("GIRO DERECHA" ) ;
lcd_gotoxy(7,1);
}
}
total_pwm = 10.24 * total;
lcd_gotoxy(1,2);
printf(lcd_putc,"PWM: %ld ", total); //m= y2 - y1 / x2 - x1
lcd_gotoxy(10,2);
lcd_putc('%');
set_pwm1_duty(total_pwm);
lcd_gotoxy(1,1);
enter=0;
total=0;
numero=0;
acumulador=0;
total_pwm=0;
z=0;
lcd_gotoxy(1,1);
lcd_putc(" " );
lcd_gotoxy(1,1);
lcd_putc("DUTY: " );
}
}
Alguna duda o algo me comentan!!!