TODOPIC

Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: Mr.pelax en 10 de Abril de 2012, 21:59:23

Título: AMPERIMETRO AC con PIC y sensor ACS712ELCTR-30A
Publicado por: Mr.pelax en 10 de Abril de 2012, 21:59:23
Hola gente estoy realizando un amperimetro AC con el PIC 16F84A y el sensor ACS712 de 30A.
Estoy programando con el HI-TECH. :mrgreen:

El problema me surgue a la hora de compilarlo me da el siguiente error.

"HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode)  V9.71a
Copyright (C) 2010 Microchip Technology Inc.
Serial number: HCPICP-654321 (PRO)
Error   [499] ; 0. undefined symbol:
   _DelayMs(pelax.obj   "

Si alguien me puede ayudar se los agradeceria.

Adjunto codigo
Código: [Seleccionar]
//----------------------------------------------
// 3 Digits Digital Ampmeter Max. 30A dc/ac
// PIC16F684 @ 8MHz internal RC
// 19 March 2012
// Compiler : Hitech-c

//----------------------------------------------

#include<pic.h>
#include <stdlib.h>
#include <math.h>
#include"delay.h"

// Configuration bit
// - Use internal RC for Oscillator
// - Watch-Dog Disabled
// - Power-up Timer Enabled
// - Internal reset MCLR pin use as I/O
// - Internal/External Switchover Disabled because using INTIO
// - Fail-Safe Clock Monitor Disabled because using INTIO

__CONFIG(INTIO&WDTDIS&PWRTEN&MCLRDIS&UNPROTECT&UNPROTECT&BORDIS&IESODIS&FCMDIS);


#define  TIME_TO_INTERRUPTS      13333   // 1/(50Hz*3) = 6.67mS
#define  INTERRUPT_OVERHEAD      12      // obtain by simulation
#define  TMR1RESET (0xFFFF-(TIME_TO_INTERRUPTS-INTERRUPT_OVERHEAD))




// Code for NPN transistor driver for driving 7-segment
                  // 0    1    2    3    4    5    6    7    8    9  blank
const char SegCode[11] = {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF};
const char Column[3] = {0x02,0x01,0x04};
static char Segment[3] = {0x7f,0x7f,0x7f};   // digit display buffer
static unsigned char ColCount=0x00;
static unsigned char Digit;
unsigned long result;
unsigned char i;



void Initial_IO(void);
void Display(void);
void HTO7S(unsigned long Num);
unsigned int read_adc(void);
unsigned int CalADC(unsigned int ADC);
unsigned int VToA(unsigned int Volt);
   

//-------------------------------------------
// Main Program
//-------------------------------------------
void main()
{
   OSCCON = OSCCON | 0b01110000;   // use internal 8MHz OSC   
   Initial_IO();
   
   
   while(1){
      HTO7S(VToA(read_adc()));
      DelayMs(200);
   }
   
}   

//----------------------------------------------
// Initialize CPU function
//----------------------------------------------
void Initial_IO(){
   
   CMCON0 = 0b00000111;   // comparator off CxIN set to analog input
   ANSEL = 0b00001000;      // set AN3 to analog input, the rest are i/o
   
   PORTA = 0x11111111;
   TRISA = 0b00010000;      // RA4 to input for ADC
   
   PORTC = 0b11111111;
   TRISC = 0b00000000;
   

   //--------------------------
   // Setup A to D
   //--------------------------
   ADCON0 = 0b10001101;   // right justified, Ch3(pin3)
   ADCON1 = ADCON1 | 0b000100000; // Conversion Clock Fosc/8
   
   
   //-------------------------
   // Setup timer 1 to interrupt every 6.67mS
   T1CON = 0b00000001;    // Set Timer 1 to 1:1 prescaler, timer on
   TMR1H = (TMR1RESET >> 8) & 0x00ff;   // load timer1 high
   TMR1L = (TMR1RESET & 0x00ff);      // load timer1 low
   
   TMR1IE = 1;   // Enable timer 1 interrupt
   TMR1IF = 0;   // Clear timer 1 interrupt flag
   PEIE = 1;   // Enable peripheral interrupt
   GIE = 1;   // Enable global interrupt

}

//--------------------------------------
// Timer 1 interrupt service
//--------------------------------------
static void interrupt Timer1_isr(void){
   if(TMR1IF)
   {
      TMR1IF = 0;     
      TMR1H = (TMR1RESET >> 8) & 0x00ff;
      TMR1L = (TMR1RESET & 0x00ff);
      Display();
   }
     
}

//------------------------------------
// Display number every 16.67mS per digit
//------------------------------------
void Display(void){
   
   PORTA = 0b00100111;     // off all digits column and Segment G
   PORTC = 0b00111111;   // off segment a-f   
   
   if (ColCount>=3)
   ColCount=0;
       
   PORTC = Segment[ColCount];
   PORTA = ((Segment[ColCount] & 0b01000000)>>1) | (Column[ColCount]^0x07);
   ColCount++;
   
}

//--------------------------------------
// Convet HEX 2 byte(ADC result) to 3 x 7-Segment code
//--------------------------------------
void HTO7S(unsigned long Num)
{

   unsigned long res;

   Segment[0]=SegCode[Num/100];
   if (Segment[0]==0x40)
   Segment[0]=0xFF;
   
   res = Num%100;
   Segment[1]=SegCode[res/10];
   res=res%10;
   Segment[2]=SegCode[res];
}   


//--------------------------------------
// Read 10 bit ADC
//--------------------------------------
unsigned int read_adc(void){
   
         GODONE = 1;
         while(GODONE){;}   
         return (((ADRESH << 8)) | ADRESL);
}


//--------------------------------------------------------------------------
// Claculate volt to amp for Vcc 5V
// See details on website
// http://coolcircuit.com/project/digital_amp_meter/picmicro_digital_amp_meter.html
//---------------------------------------------------------------------------
unsigned int VToA(unsigned int ADC_Count){
      double A;
         
         A = 0.074 * (float)ADC_Count;
         A = fabs(A-37.888);
         A = A * 10.0;
     
         // before return we must scale value by 10 for display   
         return (unsigned int)A;     
         //return ((unsigned int)(fabs(((0.074 * (double)ADC_Count) - 37.888))*10.0));
   
}

//------------------------------------
// Calculate ADC to Voltage
// use for test only
//------------------------------------
unsigned int CalADC(unsigned int ADC){

   float volt;   
   
      volt = 5.0 * (float)ADC;
      volt = volt / 1023.0;
      volt = volt * 10.0;   // scale by 10 for display 0.x - 5.x
      return ((unsigned int)(volt));
}
Título: Re: AMPERIMETRO AC con PIC y sensor ACS712ELCTR-30A
Publicado por: migsantiago en 10 de Abril de 2012, 22:05:41
Hola, dale un espacio a esta línea.

#include "delay.h"
Título: Re: AMPERIMETRO AC con PIC y sensor ACS712ELCTR-30A
Publicado por: Suky en 10 de Abril de 2012, 22:08:32
Un delay en Hitech no sería: __delay_ms(...)  :huh:
Título: Re: AMPERIMETRO AC con PIC y sensor ACS712ELCTR-30A
Publicado por: Mr.pelax en 10 de Abril de 2012, 22:28:26
hola muchas gracias suky era el problema en el delay, tenia que poner __delay_ms(...). Ahora sigo con el avance del proyecto ! Los mantendre al tanto.

Saludos y gracias   ((:-))
Título: Re: AMPERIMETRO AC con PIC y sensor ACS712ELCTR-30A
Publicado por: callecuatro1976 en 13 de Diciembre de 2014, 07:52:55
tengo una pregunta me estoy haciendo una fuente con voltimetro y amperímetro y no logro conectar el amperímetro osea como coloco la resistencia de medición ya que uno todas las masas y no me da me mide 50 amper y me pasa la tencion de 5 volt hay algún esquema para guiarme de como se conecta y medir con la misma fuente
Título: Re: AMPERIMETRO AC con PIC y sensor ACS712ELCTR-30A
Publicado por: KILLERJC en 13 de Diciembre de 2014, 13:51:35
Creo que lo mas simple es:

(http://sub.allaboutcircuits.com/images/00165.png)

Y deberias calcular el valor de tu Rshunt para que:
1- La salida de tension no sea mayor de 5V, si queres medir hasta 30A y estas seguro que no pasa mas de esa corriente, entonces calculalo con 35/40A, perdes un poco de exactitud pero te aseguras que nunca llegue a 30A.
2- Que soporte la potencia necesaria.

De ultima podes usar una resistencia mucho mas pequeña y usar un AO para amplificarlo, si ves que se va muy grande los valores. Para que sea mas exacto deberias tener una resistencia de 1% de tolerancia como minimo.
Y la resistencia es un paso, es como si conectaras un amperimetro al circuito, es decir tenes que abrirlo y que la corriente pase toda por la resistencia.
Título: Re: AMPERIMETRO AC con PIC y sensor ACS712ELCTR-30A
Publicado por: kidpic en 17 de Diciembre de 2014, 11:20:20
Hola estuve leyendo sobre el sensor ACS712 esta tiene una salida analógica y Mr Pelax esta utilizando un pic 16f84a que no acepta señales analógicas. ¿Estas utilizando alguna interface para llegar al PIC 16f84a??
Gracias 
Título: Re: AMPERIMETRO AC con PIC y sensor ACS712ELCTR-30A
Publicado por: KILLERJC en 17 de Diciembre de 2014, 13:19:33
Hola estuve leyendo sobre el sensor ACS712 esta tiene una salida analógica y Mr Pelax esta utilizando un pic 16f84a que no acepta señales analógicas. ¿Estas utilizando alguna interface para llegar al PIC 16f84a??
Gracias 

Lesiste mal el numero del PIC, es un 16F684