Mrunal Ahirrao
Full Member level 2
- Joined
- Nov 26, 2012
- Messages
- 133
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,298
- Location
- India
- Activity points
- 2,213
Hello,
I am trying to measure current from CT and I am able to measure current accurately above 1A but when measuring the current less than 1A then error occurs. I am using PIC16F886 with LCD 2x16. When current goes less than 1A suppose its 250mA then on display ideally it should be 0.25A but it is 2.50A displayed on LCD. Compiler I am using is MikroC. Here is my code:
By looking at reading it seems that the PIC is reading current correctly but not displaying correctly. Please guide me.
I am trying to measure current from CT and I am able to measure current accurately above 1A but when measuring the current less than 1A then error occurs. I am using PIC16F886 with LCD 2x16. When current goes less than 1A suppose its 250mA then on display ideally it should be 0.25A but it is 2.50A displayed on LCD. Compiler I am using is MikroC. Here is my code:
Code:
// LCD module connections
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;
// End LCD module connections
float I;//to store Current value
char Current[14];
void Current_Read()
{
int k;
ADCON0=0b01000101;
delay_us(20);
ADCON0.B2=1;
for(k=0;k<99;k++)
{
I=ADC_read(1); //reading ADC value
I=I*0.0048875; //finding voltage from ADC reading
I=I/4.4; //dividing by amplifying factor
I=I/120; //dividing by burden resistor value to get secondary current
I=I*2500; //multiplying secondary Current by transformer turns ratio
}
FloatToStr(I,Current);
delay_us(100);
Lcd_out(2,13,Current);
delay_ms(100);
}
void main()
{
TRISA = 0xFF; // set all pins of PORT A as input
TRISB =0x00;
ADCON1=0b00000000;
ADCON0=0b01000000;
ANSEL =0b0000011;
ANSELH=0x00;
CM1CON0.B7=0;
CM1CON0.B5=0;
CM2CON0.B7=0;
CM2CON0.B5=0;
Delay_ms(100);
ADCON0.B0=1;
delay_us(20);
ADCON0.B2=1;
Lcd_Init();
delay_us(100);
Lcd_Cmd(_LCD_CLEAR);
delay_us(100);
Lcd_Cmd(_LCD_CURSOR_OFF);
delay_us(100);
Lcd_out(2,1,"Current:");
while(1)
{
Current_Read();
Lcd_Chr(2,9,'A');
}// while
}// void main