PWM en Mpalb Xc8 Con Teclado Matricial
PWM en Mpalb Xc8 Con Teclado Matricial
PWM en Mpalb Xc8 Con Teclado Matricial
* File: Main.c
*/
#include <xc.h>
#include <pic18f4550.h>
#include <stdio.h>
#include <stdlib.h>
#include "timers.h"
#include "pconfig.h"
#include "configuracion.h"
#include "adc.h"
#include "xlcd.h"
#include "delays.h"
long calculo;
long calculo1;
long duty;
//// Parametros del Motor DC
float K_phi;
#define pi=3.14;
; // Inductancia de armadura
//#define configura los pines a los cuales estara conectado el teclado matricial.
0xFF
};
char key,old_key;
//
//
//
void LCD_Clear()
while(BusyXLCD());
WriteCmdXLCD(0x01);
//
//
while( BusyXLCD() );
SetDDRamAddr( ddaddr );
// Funcion PWM
//PR2< 255
void PWM ( int canal,long frecuencia, long duty ){
//
if(canal==1){
calculo =_XTAL_FREQ/4;
calculo=calculo/frecuencia;
if(calculo>255){
calculo=calculo/4;
T2CONbits.T2CKPS0=1;
if(calculo>255){
calculo=calculo/4;
T2CONbits.T2CKPS1=1;
else{
T2CONbits.T2CKPS0=0;
T2CONbits.T2CKPS1=0;
calculo=calculo-1;
calculo=calculo*duty;
calculo=calculo*4;
Ciclo_de_Trabajo=calculo;
CCPR1L=calculo>>2;
CCP1CONbits.DC1B=calculo;
//*************************
TRISCbits.RC2=0;
CCP1CONbits.CCP1M3=1;
CCP1CONbits.CCP1M2=1;
CCP1CONbits.CCP1M1=0;
CCP1CONbits.CCP1M0=0;
T2CONbits.TMR2ON=1;
accion=0;
while( accion==0){
if (accion==0){
// variamos el ciclo de trabajo
CCPR1L=x>>2;
CCP1CONbits.DC1B=x;
__delay_ms(1);
if(x==Ciclo_de_Trabajo){
accion=1;
float ActualTemp;
unsigned char stringKey[10],stringKeyActual[10];
float ActualVel;
#define ON 1
#define OFF 0
OSCCON=0b01110010; // 8Mhz
PORTD = 0x00;
LATB = 0x00;
TRISCbits.RC0=0;
TRISCbits.RC1=0;
TRISCbits.RC2=0;
// TRISCbits.RC6=0;
TRISCbits.RC7=0;
Vin_Max=220;
IA_Max=22;
Wm_nominal=1700;
K_phi=98;
CONTACTOR=OFF;
START:
putrsXLCD("INGRESE VELOCIDAD");
Wref =0;
putrsXLCD("Wref: ");
while (1){
keypress = kbd_getc();
if(keypress!=0xFF){
putcXLCD(keypress ) ;
keypress =0;
while(keypress!='#')
do
while(!keypress);
CONTACTOR=ON;
//
// Eg_nominal= Vin_Max-IA_Max*(Ra);
//
//
//
//
Vm=Eg;
//
float duty_cycle=Vm/Vin_Max ;
duty_cycle=duty_cycle;
// PWM (canal,frecuencia,duty)
PWM(1, 2000,duty_cycle);
while(1){
SetChanADC (ADC_CH0);
ADCResult =0;
ActualVel = (ADCResult*1959.6)/1024;
putsXLCD(stringKeyActual);
putrsXLCD("vel: ");
while(BusyXLCD());
putrsXLCD("RPM");
while(BusyXLCD());
putrsXLCD(" ");
SetDDRamAddr(0xC0);
return;
__delay_ms(1);
}
row1port = 0;
row2port = 0;
row3port = 0;
row4port = 0;
if (key!=old_key){
old_key=key;
else
Delay10TCYx(20);
Delay1KTCYx(30);
Delay1KTCYx(10);