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.

program in mikro ..current part has some problem.can u check?

Status
Not open for further replies.

swethamenon

Member level 4
Member level 4
Joined
Sep 12, 2012
Messages
70
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,745
Using sensors LV 20P &LA 25-NP V&I measured.output interms of voltage.in LV o/p resistor is 100ohm.so Is(sec current) can calculate.Is/Ip=2.5.I/p rsistance 5kohm.thAT IS THE FIRST PART.In PROTESUS its working.BUT current part nt ok.o/p resistance 100ohm.Ip/Is=1000.Here need Ip.Using POT both values of sensors given.

Code:
unsigned float adcval,adcval1,V1,Is,I,I1,Is1;
char val[7],val1[7];
void main()
{
TRISA=0XFF;
TRISD=0X00;
ADCON1=0X80;
lcd_init(&PORTD);
lcd_cmd(lcd_clear);
lcd_cmd(lcd_cursor_off);
 while(1)
 {
adcval=Adc_Read(0)*.0048;
Is=adcval/100;
I=Is/2.5;
V1=I*5000;
floattostr(V1,val);
val[5]='\0';
adcval1=Adc_Read(1)*.0048;
Is1=adcval1/100;
I1=Is1*1000;
floattostr(I1,val1);
val1[5]='\0';
lcd_cmd(lcd_clear);
lcd_out(1,1,"V=");
lcd_out(1,4,val);
lcd_out(2,1,"I=");
lcd_out(2,4,val1);
delay_ms(1000);
}
}
 
Last edited by a moderator:

Post your circuit. Are you using mikroC Pro? The documentation tells that if you use floattostr() then the string should be 17 to 23 characters i.e., val[17] and val1[17]. The other thing is you don't have to write val[5] = '\0'. floattostring() automatically adds the null character to the end of string while conversion. What is the voltage and current range you are measuring? Have you scaled down the inputs to adc to 0v to 5v range? Which mcu are you using? What do you mean by current part not ok? What values are you getting for current?

Can you explain your calculation method?

If the voltage you are measuring is 0v to 20v and it is scaled down to 0v to 5v for adc input then the raw adc value you will get will be 1023 for 10 bit adc and 4095 for 12 bit adc. If it is assumed that you are using 10 bit adc and you get some raw value of 659 (value will be 0 - 1023), then volt = 659 * (20/1023) = 12.88367546432063 V

If you are measuring 10A max and scaled down it to 0v to 5v for adc input then 0A = 0 adc raw value and 10A = 1023 adc raw value. If you get raw value 824 then I = 824 * (10/1023) = 8.054740957966764 A
 
Last edited:

ya..MikroC..PIC16F877a..Solar panel is the source..adc voltage is 5v.the sensors scaledown the v&I .
DIDNT GET "The documentation tells that if you use floattostr(0 then the string should be 17 to 23 charcaters i.e., val[17] and val1[17]. The other thing is you don't have to write val[5] = '\0'. "
In proteus lcd_out(1,1,"V=").instead of "V=" in LCD its shown '9'.why?
 

DIDNT GET "The documentation tells that if you use floattostr(0 then the string should be 17 to 23 charcaters i.e., val[17] and val1[17]. The other thing is you don't have to write val[5] = '\0'. "

I don't remember, but it is in some mikroC documentation... It is mentioned that if you use floattostr() function the string variable used must be declared with a minimum of 17 bytes. You have declared strings val[5] and val1[5]. You have to change it to val[17] and val1[17] in the variable declaration. Another thing is val[5] and val1[5] has 5 elements from 0 to 4, So, val[5] and val1[5] doesn't exist.

So, you can't use

Code C - [expand]
1
val[5] = '\0'

and

Code C - [expand]
1
val1[5] = '\0'



Are you using mikroC or mikroC Pro? I think you are using the old version of mikroC v8 or v8.1 or v8.2. Am I right? If yes, then you are also using 8 bit mode for LCD and So, you have to use lcd8 library. You have used PORTD for LCD. How are the lcd pins connected to portd? I think your have used lcd_init() function incorrectly. See the mikroC help for lcd_init() and lcd8_init() functions.
 
Last edited:

I don't remember, but it is in some mikroC documentation... It is mentioned that if you use floattostr() function the string variable used must be declared with a minimum of 17 bytes. You have declared strings val[5] and val1[5]. You have to change it to val[17] and val1[17] in the variable declaration. Another thing is val[5] and val1[5] has 5 elements from 0 to 4, So, val[5] and val1[5] doesn't exist.

So, you can't use

Code C - [expand]
1
val[5] = '\0'

and

Code C - [expand]
1
val1[5] = '\0'



Are you using mikroC or mikroC Pro? I think you are using the old version of mikroC v8 or v8.1 or v8.2. Am I right? If yes, then you are also using 8 bit mode for LCD and So, you have to use lcd8 library. You have used PORTD for LCD. How are the lcd pins connected to portd? I think your have used lcd_init() function incorrectly. See the mikroC help for lcd_init() and lcd8_init() functions.

MikroC..using 4mode operation.val[5] is correct..in proteus i gt the answer

- - - Updated - - -

I don't remember, but it is in some mikroC documentation... It is mentioned that if you use floattostr() function the string variable used must be declared with a minimum of 17 bytes. You have declared strings val[5] and val1[5]. You have to change it to val[17] and val1[17] in the variable declaration. Another thing is val[5] and val1[5] has 5 elements from 0 to 4, So, val[5] and val1[5] doesn't exist.

So, you can't use

Code C - [expand]
1
val[5] = '\0'

and

Code C - [expand]
1
val1[5] = '\0'



Are you using mikroC or mikroC Pro? I think you are using the old version of mikroC v8 or v8.1 or v8.2. Am I right? If yes, then you are also using 8 bit mode for LCD and So, you have to use lcd8 library. You have used PORTD for LCD. How are the lcd pins connected to portd? I think your have used lcd_init() function incorrectly. See the mikroC help for lcd_init() and lcd8_init() functions.

MikroC..using 4mode operation.val[5] is correct..in proteus i gt the answer

- - - Updated - - -

Code:
unsigned float adcval,adcval1,V1;
unsigned float Is,I,I1,Is1,w1,e;
char val[7];char val1[7];
char val2[7],val3[7];
void main()
{
e=0;
w1=0;
TRISA=0XFF;
TRISD=0X00;
ADCON1=0X80;
lcd_init(&PORTD);
lcd_cmd(lcd_clear);
lcd_cmd(lcd_cursor_off);
 while(1)
 {
adcval=Adc_Read(0)*.0048;
Is=adcval/100;
I=Is/2.5;
V1=I*5000;
floattostr(V1,val);
val[5]='\0';
adcval1=Adc_Read(1)*.0048;
Is1=adcval1/100;
I1=Is1*1000;
floattostr(I1,val1);
val1[5]='\0';
lcd_out(1,1,"V =");
lcd_out(1,4,val);
lcd_chr(1,10,'V');
lcd_out(1,12,"I=");
lcd_out(1,15,val1);
lcd_chr(1,16,'A');
w1=I1*V1;
floattostr(w1,val2);
val2[5]='\0';
lcd_out(2,1,"P =");
lcd_out(2,4,val2);
lcd_chr(2,10,'W');
e=e+(w1*1000);
floattostr(e,val3);
val3[5]='\0';
lcd_out(2,12,"E =");
lcd_out(2,15,val3);
lcd_chr(2,16,'W');
delay_ms(1000);
}
}

Energy calculation program is shown above..need correction..that power calculation portion onwards..some missing..when i simulated in proteus...went wrong
 

Ok. You are right. I thought you had declared val[5] and val1[5] but you have declared it as val[7] and val1[7]. So, val[5] = '\0' and val1[5] = '\0' is right. Are you getting values of V and I correctly? Can you zip and post your proteus .dsn file and also the mikroc files with both hex and cof files?

Edit: You have to use CMCON = 0x07; to disable the Comparators on PORTA. See datasheet CMCON should be 0b00000111 to disable both Comparators.
 
Last edited:

Ok. You are right. I thought you had declared val[5] and val1[5] but you have declared it as val[7] and val1[7]. So, val[5] = '\0' and val1[5] = '\0' is right. Are you getting values of V and I correctly? Can you zip and post your proteus .dsn file and also the mikroc files with both hex and cof files?

Edit: You have to use CMCON = 0x07; to disable the Comparators on PORTA. See datasheet CMCON should be 0b00000111 to disable both Comparators.

Energy is calculated in KWh..can u check whether its correct or not
Code:
unsigned float adcval,adcval1,V1,Is,I,I1,Is1,power,energy;
char val[7];
void main()
{
energy  = 0;
TRISA=0XFF;
TRISD=0X00;
ADCON1=0X80;
lcd_init(&PORTD);
lcd_cmd(lcd_clear);
lcd_cmd(lcd_cursor_off);

lcd_out(1,1,"V=");

lcd_out(1,9,"I=");

lcd_out(2,1,"E=");
 while(1)
{
adcval=Adc_Read(0)*.0048;
adcval1=Adc_Read(1)*.0048;
Is=adcval/100;
I=Is/2.5;
V1=I*5000;
floattostr(V1,val);
val[5]='\0';
lcd_out(1,3,val);
Is1=adcval1/100;
I1=Is1*1000;
floattostr(I1,val);
val[5]='\0';
lcd_out(1,11,val);
power = V1 * I1;
//floattostr(power,p_val);
//p_val[5]='\0';
//lcd_out(2,3,p_val);
energy =(energy + power)*(5/18);
floattostr(energy,val);
//val[5]='\0';
lcd_out(2,3,val);
delay_ms(1000);
}
}

I want to store energy value into Eeprom..
EEPROM _READ()and Eeprom_Write( , );
How to use it here??
 

Can you explain yur calculation method shown below

Code C - [expand]
1
2
3
4
5
adcval=Adc_Read(0)*.0048;
adcval1=Adc_Read(1)*.0048;
Is=adcval/100;
I=Is/2.5;
V1=I*5000;



Post your adc input circuit.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top