kokaisf
Newbie level 3
hello everybody, i have a problem about an acquisition of sinus signal.
so I need the amplitude of tow signals. so I do it with the pic16f88.
this is my program.
the problem is : when i do the simation whit proteus, I do not get anything on the LCD.
so I need the amplitude of tow signals. so I do it with the pic16f88.
this is my program.
Code:
#include <16F88.h>
#device ADC=10 // conversion 10 bits
#include <math.h> //Ajoute la lib math
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#define LCD_DATA_PORT getenv("SFR:PORTB")
#byte TMR0 = 0x01F
#byte PORTA = 0x5F
#byte PORTB = 0x6F
#byte ADCON0 = 0x1F
#byte ADCON1 = 0x9F
#byte ANSEL = 0x9B
#byte OPTION_REG = 0x81
#byte INTCON = 0x0B
#byte TRISA = 0x85
#byte TRISB = 0x86
#bit RP0 = 0x03.5
#bit RP1 = 0x03.6
#bit ADFM = 0x9F.7
#bit VCFG1 = 0x9F.5
#bit VCFG0 = 0x9F.4
#bit TOCS = 0x81.5
#bit PSA = 0x81.3
#bit GIE = 0x0B.7
#bit TMR0IE = 0x0B.5
#bit INT0IF = 0x0B.1
#define RS_PIN PIN_B1
#define RW_PIN PIN_B2
#define ENABLE_PIN PIN_B0
#define Data4 PIN_B4
#define Data5 PIN_B5
#define Data6 PIN_B6
#define Data7 PIN_B7
#include <lcd.c>
float phi = 0;
float tension = 0; // effective voltage
float courant = 0; // effective curent
int16 lue_phi = 0;
int16 lue_tension = 0; // read voltage
int16 lue_courant = 0;
float conso_energie = 0; //consommation
float conso_puissance = 0;
float deltaT = 0;//the operating time
float real_valueT = 0;
float real_valueI = 0;
const float cont_tension = 130; //coeficient for the effective voltage
const float cont_courant = 10; // coeficient for the effective curent
const float deux_pi = 6.28 ;
const float frequence = 50; // the frequency
const float coef = 5/1024;
//Acquisition the curent and the phase
void Acquisition()
{
while (lue_phi<2.5)
{
TMR0 = 0;
lue_phi = read_adc(); //read the signal of the phase
delay_us(100);
}
lue_courant = read_adc(); //read curent
//delay_ms(100);
real_valueI = ceil(coef*lue_courant); // have the amplitude of curent signal
courant =cont_courant*lue_courant; // the effective curent
phi = 0.0001*deux_pi*frequence*TMR0; // phase value
lue_phi = 0;
}
// Acquisition of the voltage
void ATension()
{
lue_tension = read_adc();
real_valueT = ceil(coef*lue_tension);
tension =cont_tension*lue_tension; //the effective value
}
void main()
{
RP0 = 1;
TRISA = 0b00000011;
TRISB = 0b00000000;
ADFM = 0;
VCFG1 = 0;
VCFG0 = 0;
ANSEL = 0b00000011;//analog input configuration
TOCS = 0; // TMR0 in timer mode
PSA = 1;
RP0 = 0;
lcd_init();
delay_ms(20);
lcd_putc("\fENERGIE");
while (1)
{
ADCON0 = 01000101;
Acquisition();
ADCON0 = 01001101;
ATension();
lcd_gotoxy(1,2);
printf(lcd_putc,"%5.5f kwh",real_valueI);
}
}