Académique Documents
Professionnel Documents
Culture Documents
//
//
//
CONTROL VELOCIDAD MOTOR DC CON PIC
//
//
//
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
#include <16f887.h>
#device adc=8
#fuses XT,NOWDT
#use delay(clock=4000000)
#byte trisb=0x86
#byte portb=0x06
#byte trisc=0x87
#byte portc=0x07
int1 cambio=0;
int16 lectura_AD;
//funcin principal
//funcin por interrupcin
/******************************************************************************/
/******************* FUNCIN GENERACIN MODULACIONES PWM
**********************/
#int_ccp2
void ccp2_int(){
if(++cambio==1){
else{
setup_ccp2(CCP_COMPARE_SET_ON_MATCH); //Modo comparacin, conmutacin salida a 1
ccp_2=255-lectura_AD;
}
set_timer1(0);
/******************************************************************************/
/******************** FUNCIN PRINCIPAL ***************************************/
void main(){
float velocidad;
//Porcentaje velocidad
trisc=0x00;
port_b_pullups(TRUE);
lcd_init();
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
enable_interrupts(int_ccp2);
enable_interrupts(GLOBAL);
while (true){
set_adc_channel(0);
delay_us(20);
lectura_AD=read_adc();
velocidad=(lectura_AD);
//Habiliatacin lectura AD
//Estabilizacin
//Lectura canal analgico
//Clculo % de velocidad
lcd_init();
printf(lcd_putc, "\fVelocidad = %3.0f%%", velocidad);
}
}