Sari la conținut
ELFORUM - Forumul electronistilor

voltampermetru cu pic 16f876


winston

Postări Recomandate

Cu mine vorbesti? Sunt singur aici, nu-i nevoie de plural. :)

Sa-nteleg ca vrei sa folosesti codul din postul anterior? Am sa te rog sa postezi aici daca merge sau nu. Daca nu merge sa postezi si ce anume nu merge.

Link spre comentariu
  • 6 luni mai târziu...
Vizitator Eolos

Hi there ! The code works fine with pic16f877A.. I created the hex file for pic18f4520 and pic18f4550 but i couldnt get any readings from the Lcd Display.

 

Can u re write it for pic 18f4520 or 50 ?

Link spre comentariu
Vizitator Eolos

The Code is Belown..

 

I use Port A and E for ADC reading by Opamp.. Port B is for LCD, Port C and D are for output that controls some leds, relays etc.. Crystal is 4 Mhz.

//LCD

sbit LCD_RS at RB7_bit;

sbit LCD_EN at RB6_bit;

sbit LCD_D4 at RB5_bit;

sbit LCD_D5 at RB4_bit;

sbit LCD_D6 at RB3_bit;

sbit LCD_D7 at RB2_bit;

 

sbit LCD_RS_Direction at TRISB7_bit;

sbit LCD_EN_Direction at TRISB6_bit;

sbit LCD_D4_Direction at TRISB5_bit;

sbit LCD_D5_Direction at TRISB4_bit;

sbit LCD_D6_Direction at TRISB3_bit;

sbit LCD_D7_Direction at TRISB2_bit;

 

//Declarare variabile

unsigned char ch, ADCx;

unsigned int Tens, Curent, PVV, P24, P48, OFV, PV, DV, PI, P2, P4, OF, DW;

unsigned long V, I, Pw, Av;

 

char text[10];

 

const char *mesg1="%100";

const char *mesg2="%90";

const char *mesg3="%80";

const char *mesg4="%70";

const char *mesg5="%60";

const char *mesg6="%50";

const char *mesg7="%40";

const char *mesg8="%30";

const char *mesg9="%20";

const char *mesg10="%10";

const char *mesg11="AKU BOS";

 

void strConstCpy(char *dest, const char *source) {

while(*source)

*dest++ = *source++ ;

 

*dest = 0 ;

}

 

//Functie principala

void main() {

INTCON = 0; // Dezactivare intreruperi

TRISA = 0xFF;

TRISE = 0xFF; // RA0, RA1 setate ca intrari

TRISC = 0x00; // RC3 si RC4 setati pe iesire

PORTC = 0; // Resetare port c

TRISD = 0x00; // RC3 si RC4 setati pe iesire

PORTD = 0;

 

Lcd_Init(); // Initializare LCD

Lcd_Cmd(_LCD_CURSOR_OFF); // Dezactivare cursor

Lcd_Cmd(_LCD_CLEAR); // Stergere Ecran

Delay_ms(600); // Delay 1 secunda

Lcd_Out(1,5,"HYPERNOVA"); // Mesaj initial 1, prima linie

Lcd_Out(2,2,"ELECTRIC"); // Mesaj initial 1 linia 2

Delay_ms(800);

Lcd_Cmd(_LCD_CLEAR); // Stergere ecran

Lcd_Out(1,4,"ALTERNATIVE"); // Mesaj initial 2, prima linie

Lcd_Out(2,4,"POWER SYSTEMS"); // Mesaj initial 2, linia 2

Delay_ms(1000);

Lcd_Cmd(_LCD_CLEAR);

 

while (1) {

//ADC

Tens = 0;

Curent = 0;

PVV = 0;

P24= 0;

P48 = 0;

OFV = 0;

for (ADCx=0; ADCx<10; ADCx++) {

Tens += ADC_Read(0); // Achizitie ADC pentru Tens

Curent += ADC_Read(1); // Achizitie ADC pentru curent

PVV += ADC_Read(7);

P24 += ADC_Read(2);

P48 += ADC_Read(5);

OFV += ADC_Read(6);

Delay_ms(30);

}

 

//Voltage

Tens = Tens/ADCx; // Alocare valoare Tens

V = (long)Tens*1000; // Converteste rezultat in milivolti

V = V/1023; // 0...1023 => 0...1000mV

ch = V/1000; // Extrage sute 100.00

Lcd_Chr(1,1,48+ch); // Afisare rezultat in format ASCII linia 1, coloana 1

ch = (V/100) % 10; // Extrage zeci 010.00

Lcd_Chr_CP(48+ch); // Afiseaza rezultat in format ASCII

ch = (V/10) % 10; // Extrage unitati 001.00

Lcd_Chr_CP(48+ch); // Afiseaza rezultat in format ASCII

Lcd_Chr_CP('.'); // Afiseaza caracter '.'

ch = (V/1) % 10; // Extrage sutimi 000.10

Lcd_Chr_CP(48+ch);

ch = V % 10; // Extrage zecimi 000.01

Lcd_Chr_CP(48+ch);

LCD_Chr_CP('V'); // Afiseaza caracter 'V'

Delay_ms(30);

 

//Current

Curent = Curent/ADCx; // Alocare valoare curent

I = (long)Curent*5000; // Convertire rezultat in milivolti

I = I/1023; // 0..1023 => 0-5000mV

ch = I/1000; // Extragere zeci 10.00

Lcd_Chr(1,9,48+ch); // Scrie rezultatul in format ASCII linia 1, coloana 9

ch = (I/100) % 10; // Extragere unitati 01.00

Lcd_Chr_CP(48+ch); // Scrie rezultatul in format ASCII

Lcd_Chr_CP('.');

ch = (I/10) %10; // Extragere sutimi 00.10

Lcd_Chr_CP(48+ch); // Scrie rezultatul in format ASCII

ch = I % 10; // Extragere zecimi 00.01

Lcd_Chr_CP(48+ch);

Lcd_Chr_CP('A'); // Afisare caracter 'A' la final

Delay_ms(30);

 

//Power

Pw = V*I/1000; // Seteaza valoare Putere

ch = Pw/1000; // Extrage mii 1000

Lcd_Chr(2,1,48+ch); // Scrie rezultatul in format ASCII linia 2, coloana 1

ch = (Pw/100) % 10; // Extrage sute 0100

Lcd_Chr_CP(48+ch);

ch = (Pw/10) %10; // Extrage zeci 0010

Lcd_Chr_CP(48+ch);

ch = Pw % 10; // Extrage unitati 0001

Lcd_Chr_CP(48+ch);

Lcd_Chr_CP('W'); // Afiseaza "W" la sfarsit

Delay_ms(30);

 

//Protective Read

PV = ADC_Read(7);

DV = ADC_Read(0);

PI = ADC_Read(1);

P2 = ADC_Read(2);

P4 = ADC_Read(5);

OF = ADC_Read(6);

DW= DV*PI /100;

 

//Protective 24V

if (P2>= 388 && P4< 388 && PV >=286 || P2>= 388 && P4< 388 && PV <286 && PI >=818 || P2>= 388 && P4< 388 && DW > 234) {

PORTC.F3 = 1;

PORTC.F4 = 0;

}

//Protective 48V

else if (P4>= 388 && P2< 388 && PV >=572 || P4>= 388 && P2< 388 && PV <572 && PI >=818 || P4>= 388 && P2< 388 && DW > 468) {

PORTC.F0 = 1;

PORTC.F6 = 0;

}

//Button Protective - Onn Off

else if (P2>= 388 && P4>= 388 || OF >= 388) {

PortC.F4 = 0;

PortC.F6 = 0;

PortC.F3 = 1;

}

else {

PortC.F4 = 1;

}

// Aku Seviye 24V Sistem

if (OF >= 388 && PV > 256 && PV <= 275) {

strConstCpy(text,mesg1);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 254 && PV <= 256) {

strConstCpy(text,mesg2);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 252 && PV <= 254) {

strConstCpy(text,mesg3);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 249 && PV <= 252) {

strConstCpy(text,mesg4);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 246 && PV <= 249) {

strConstCpy(text,mesg5);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 243 && PV <= 246) {

strConstCpy(text,mesg6);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 240 && PV <= 243) {

strConstCpy(text,mesg7);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 237 && PV <= 240) {

strConstCpy(text,mesg8);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 231 && PV <= 237) {

strConstCpy(text,mesg9);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 215 && PV <= 231) {

strConstCpy(text,mesg10);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV <= 215) {

strConstCpy(text,mesg11);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

// Aku Seviye 48V Sistem

else if (OF >= 388 && PV > 511 && PV <= 530) {

strConstCpy(text,mesg1);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 508 && PV <= 511) {

strConstCpy(text,mesg2);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 504 && PV <= 508) {

strConstCpy(text,mesg3);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 499 && PV <= 504) {

strConstCpy(text,mesg4);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 493 && PV <= 499) {

strConstCpy(text,mesg5);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 487 && PV <= 493) {

strConstCpy(text,mesg6);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 480 && PV <= 487) {

strConstCpy(text,mesg7);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 473 && PV <= 480) {

strConstCpy(text,mesg8);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 462 && PV <= 473) {

strConstCpy(text,mesg9);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 429 && PV <= 462) {

strConstCpy(text,mesg10);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

else if (OF >= 388 && PV > 401 && PV <= 429) {

strConstCpy(text,mesg11);

Lcd_Out(2, 9, text);

Delay_ms(5000);

Lcd_Cmd(_LCD_CLEAR);

}

}

}

Link spre comentariu
  • 3 luni mai târziu...
  • 1 an mai târziu...

Am construit si eu acest v-a. dupa schema de sus si intampin 1 problema:

 valoarea dupa virgula nu este stabila,variaza in limite mari uneori si 5 ordine de marime(sute de mA si mV)

      in conditiile in care tensiunea/curentul masurat este stabil pe multimetru.

 

Link spre comentariu

Nu cred ca-s chiar "ordine de marime"... inclin sa cred ca-s de fapt "unitati elementare"... :).

Pe de alta parte schema asta, dupa parerea mea, nu-i vreun "aparat de masura" performant... ii o exemplificare a ce poti face c-un microcontroler, nu o scula de laborator.

Poti sa modifici soft-ul sa faci media pe mai multe masuratori cu scaderea "vitezei de reactie"... poti sa alegi un PIC mai din zilele noastre... s.a.m.d.... oricum, sper ca n-ai cautat un trf. cu 20Vca neaparat... :D 

Link spre comentariu

Multumesc pt. raspuns Thunderer2018,am incercat solutia propusa de dvs. dar nu a avut nici un efect dar oricum, astfel mi-ati oferit alta idee

si am decuplat intrarile 2,3 cu cate 100nF la masa iar acum fluctuatiile s-au redus ca intensitate si frecventa.

Referitor la raspunsul ironic si rautacios( sper ca n-ai cautat un trf. cu 20Vca neaparat...) al lui informer imi cer scuze pt. ignoranta cu care v-am deranjat

dar mi-ati spus ce stiam deja:ca sunt prost.Pentru mine este acceptabil aceast v-a pt. ca nu fac cercetare iar cu programarea am ramas mult in urma pt. ca nu am programat decat in Basic mici programele pe timpul HC-urilor...

Editat de minel
Link spre comentariu
2 hours ago, minel said:

Referitor la raspunsul ironic si rautacios( sper ca n-ai cautat un trf. cu 20Vca neaparat...) al lui informer imi cer scuze pt. ignoranta cu care v-am deranjat

dar mi-ati spus ce stiam deja:ca sunt prost.Pentru mine este acceptabil aceast v-a pt. ca nu fac cercetare iar cu programarea am ramas mult in urma pt. ca nu am programat decat in Basic mici programele pe timpul HC-urilor...

Imi pare rau c-am devenit asa de seriosi incat nu mai putem intelege o gluma... te asigur ca n-am vrut sa dau nimic de inteles, am sa fiu mai atent pe viitor la exprimari.

Referitor la acel transformator, m-a distrat alegerea avand in vedere ce tensiuni stabilizate se obtin... atat si nimic mai mult. :|

Link spre comentariu

Citez autorul proiectului despre alegerea tensiunii respective:

"M-am folosit de un amplificator diferential cu AO, in speta 358, alimentarea sa va fi la o tensiune auxiliara de 20V si asta pentru a permite o mai buna flexibilitate in ceea ce priveste CMIR maxim admis pe intrari ( common mode imput range ), care la 358 constat ca este intre -0,3v si pana la Vcc. "

Link spre comentariu
34 minutes ago, minel said:

Citez autorul proiectului despre alegerea tensiunii respective:

"M-am folosit de un amplificator diferential cu AO, in speta 358, alimentarea sa va fi la o tensiune auxiliara de 20V si asta pentru a permite o mai buna flexibilitate in ceea ce priveste CMIR maxim admis pe intrari ( common mode imput range ), care la 358 constat ca este intre -0,3v si pana la Vcc. "

 

OK, multumesc... nu mai comentez ca se interpreteaza cum n-as vrea. :ewryt45w

Link spre comentariu

Creează un cont sau autentifică-te pentru a adăuga comentariu

Trebuie să fi un membru pentru a putea lăsa un comentariu.

Creează un cont

Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!

Înregistrează un nou cont

Autentificare

Ai deja un cont? Autentifică-te aici.

Autentifică-te acum
×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări