Está en la página 1de 8

UNIVERSIDAD NACIONAL DEL CALLAO

ESCUELA DE INGENIERIA ELECTRONICA

CURSO: MICROCONTROLADORES Y SISTEMAS EMBEBIDOS

PROFESOR: MG.ING. ASTOCONDOR VILLAR JACOB

GRUPO:

ALUMNOS:

TEMA: VOLTIMETRO CON DSPIC 30F4013


.

2018
TITULO: VOLTIMETRO CON dsPIC

OBJETIVO:

Desarrollar un voltímetro digital de 0 – 20 voltios, con el microcontrolador dsPIC30F4013, utilizaremos


una pantalla LCD 16x2 para poder observar la variación de voltaje y poder comprobar el resultado del
proyecto.

1. MATERIALES:
1.1 HADWARE:
 Microcontrolador dsPIC30F4013.
 Pantalla LCD 16x2.
 Resistencia de 1K (2 uni) ,3K (1 uni).
 Potenciómetro 10K.
 Cristal de 4M Hz.
 Capacitor de 22Pf.
 Un botón.
 Cables de conexión.
 PIC KIT 2.
1.2 SOFTWARE:
 PIC C Compiler.
 PICKIT 2.
 Proteus.

PICKIT 2: Luego de obtener el .Hex, abrimos el PICKIT3 y buscamos la carpeta donde guardamos el código,
una vez seleccionado hacemos las conexiones y luego tiene que quemarlo.
PROTEUS: Se recomienda que antes de quemar el código a su dsPIC simularlo para poder saber
si el código cumple con la funciones necesaria que necesite.
2. CIRCUITO dsPIC

2.1 LCD

Nota: Estudiar la función de cada pin especialmente los pines de control y datos del LCD

2.2 DIVISOR DE TENSION


Como el voltage de referencia del dsPIC30F4013 es de 0 a 5 v , y nosotros tenemos
que implementar un voltímetro de 0 a 20 v ,haremos uso de un circuito sencillo para
poder trabajar con 20 v ,sin que el microcontrolador se dañe.
R2
Vout  *Vin
R 2  R1
1k
Vout  * 20V  5V
1k  3k

Los 20 voltios de la fuente equivalen a 5v de entrada al dsPIC30F4013, Que es lo máximo


que puede resistir.

3. PROGRAMACION
3.1. Realizar un diagrama de flujo del programa
32. se presenta un programa como ayuda o referencia

// configuration de los fuses


#include <30F4013.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS2_PLL16 //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PR_PLL //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES WPSB16 //Watch Dog Timer PreScalar B 1:16
#FUSES WPSA512 //Watch Dog Timer PreScalar A 1:512
#FUSES PUT64 //Power On Reset Timer value 64ms
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV47 //Brownout reset at 4.7V
#FUSES LPOL_HIGH //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6)
//PWM module low side output pins have active high output polar
#FUSES HPOL_HIGH //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7)
//PWM module high side output pins have active high output polarity
#FUSES NOPWMPIN //PWM outputs drive active state upon Reset
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOCOE //Device will reset into operational mode
#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#FUSES RESERVED //Used to set the reserved FUSE bits
#device adc=12 //ADC 12 bits
#use delay(clock=4000000)
//código
#define LCD_ENABLE_PIN PIN_RD0
#define LC D_RS_PIN PIN_RD1
#define LCD_RW_PIN PIN_RD2
#define LCD_DATA4 PIN_RF5
#define LCD_DATA5 PIN_RF4
#define LCD_DATA6 PIN_RF1
#define LCD_DATA7 PIN_RF0
#include <lcd.c>
#include <math.h>
#include <stdlib.h>
float voltage;
float Lect_adc;
void main()
{
Lect_adc=0;// valor adc
voltaje=0;
lcd_init();
setup_adc_ports (sAN0|VREF_VREF);
setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_2); //especificamente configurado a 120
while(true)
{
set_adc_channel(0);
Lect_adc = read_adc();
delay_ms(20);
voltaje=((20.0*Lect_adc)/4095);
lcd_putc("\f");
lcd_gotoxy(1,2);
printf(lcd_putc,"Voltage = %f ",voltaje);
delay_ms(500);
}
}

4. PROGRAMACION optional en miKro C


sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_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;

unsigned int adc=0;


float Voltaje=0;
int Vo,decena,unidad,centena,millar1,unidad1,decena1,centena1,millar;
void main()
{
ADPCFG=0xFEFF;
TRISB.B0=0;
TRISB.B1=0;
TRISB.B2=0;
TRISB.B3=0;
TRISB.B4=0;
TRISB.B5=0;
TRISB.B8=1;
ADC1_Init();
LCD_Init();
LCD_Cmd(_LCD_CLEAR);
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Out(1,1,"Voltimetro");
LCD_Out(2,1,"De 5 voltios");
LCD_Cmd(_LCD_CLEAR);
delay_ms(1500);
LCD_Cmd(_LCD_CLEAR);
while(1)
{
millar =(adc/1000);
centena = ((adc%1000)/100);
decena = ((adc%100)/10);
unidad = (adc%10);
millar1 = (Vo/1000);
centena1 = ((Vo%1000)/100);
decena1 = ((Vo%100)/10);
unidad1 = (Vo%10);

adc=ADC1_Get_Sample(8);
delay_ms(50);
Voltaje=0.1221*adc;
Vo=Voltaje*10;
delay_ms(100);
LCD_out(2,1,"adc=");
LCD_chr(2,5,48+millar);
LCD_chr_cp(48+centena);
LCD_chr_cp(48+decena);
LCD_chr_cp(48+unidad);

LCD_out(1,1,"V=");
LCD_chr(1,3,48+millar1);
LCD_chr_cp('.');
LCD_chr_cp(48+centena1);
LCD_chr_cp(48+decena1);
LCD_chr_cp(48+unidad1);
delay_ms(250);
}
}

5. SIMULACION
 Medida del voltímetro con 20 V
 Medida del voltímetro con 10 V

También podría gustarte