Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] acquisition of a sinu signa

Status
Not open for further replies.

kokaisf

Newbie level 3
Newbie level 3
Joined
Jan 4, 2018
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
41
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.
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);
    
   }
  
   
 }
the problem is : when i do the simation whit proteus, I do not get anything on the LCD.
 

Hi,

"Nothing" ... means a blank LCD?

Then step back. Deactivate all your measurement and calculation stuff and focus on displaying text on the LCD.

Klaus
 

Hi,

Again my question: Is there a blank display?

If there is no blank display, then tell us exactly what's on the display.
Or are there random characters? --> screenshot.
Changing characters?

Klaus
 

hello,



this function lcd_putc() looks like for using caracteres, not for a string
but, maybe i am wrong, i don't know your Lcd library.
can you display "ENERGIE" on it ?
what means \f ?

it is allways better to check on REAL WORLD than with a simulator.
 

From his code I can tell that he is using CCS PICC Compiler as I am familiar with it.
 

hello,
I had a lcd program on this forum and that's what I used.
the lcd_putc () sends any information on the lcd.
and in my program, what appears in the first place is: "ENERGY"
so the lcd screen does not stay blank. only the second information (printf(lcd_putc,"%5.5f kwh",conso_energie)) does not come out. that's my problem.
below is my montage on proteus
Capture.JPG
and the compiler is ccs pic
 

Does not it seem obvious to you that image resolution is poor, making it impossible to identify pinout of microcontroller as well as details on the circuit ?
 

Hi,

U3A is useless, R7, R11, too.
But this is not the original problem.

Now to your problem:
The code line of your post#8 (printf(lcd_putc,"%5.5f kwh",conso_energie)) is not included in the code of post#1.
--> give correct informations

Conso_energie is initialized with value 0, but never changed/ calculated afterwards.
--> did you read through your own code? What output do you expect?

Klaus
 

yes, you are right. I made some changes after posting the first message.
this is the correct code line:printf(lcd_putc,"%5.5f kwh",real_valueI).
and thi is a piture of the PIC:Capture2.JPG.
 

nota: it is usual to init float value with a decimal point

Code:
float conso_energie = 0.0; //consommation
float conso_puissance = 0.0 ;  
float deltaT = 0.0 ;//the operating time
float real_valueT = 0.0 ; 
float real_valueI = 0.0 ;


does printf support floating point to ascii conversion , for this 16F MCU ?

else use

Code:
 char txt[17];

   floatTostr(ConsoEnergy, txt,3) ;  // conversion avec 3 decimales
   lcd_putc(txt);

.. then add "Kwh"
 

this function lcd_putc() looks like for using caracteres, not for a string
but, maybe i am wrong, i don't know your Lcd library.

It's the correct way to print strings with CCS C. Seeing no output suggests that the LCD library isn't setup right or the display not connected as intended.

Unfortunately it's only the first of many problems involved with the project. There's also: measurement circuit unsuitable for AC, most likely incorrect processing of ADC values.
 

Hello,

LCD seems correct

post#8
... what appears in the first place is: "ENERGY" so the lcd screen does not stay blank....

kokaisf , try to display a known value .. like 4.998

concerning your schematic:
internal impedance source for ADC must be << 10K, so
R9,R10,R5,R6 100K are too much use 10K maxi or less
R7,R11 ... 10K .. => 1K




where is the load on AC generator , is it the self + 50 ohms ?
 

Why don't you zip and post your complete CCS PICC project files and Proteus file so that people who want to help you can simulate and see what is happening. CCS PICC has it's own adc configuration and initialization functions. Use them before while(1) loop. Did you check the device header file for that information ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top