ina219 akım voltaj ve güç sensörü modülü ile akım ölçtüm. Sadece en basit olan kalibrasyonsuz akım ölçümünü gerçekleştirdim. Bus voltage ölçümü ve güç ölçümü yapmadım. Malum; gerilim 5V.Buradan gücü hesapladım.
pic18f2550 ve mikroc kullandım.
kodlar:
sbit LCD_RS at rb2_bit;
sbit LCD_EN at rb3_bit;
sbit LCD_D7 at rb7_bit;
sbit LCD_D6 at rb6_bit;
sbit LCD_D5 at rb5_bit;
sbit LCD_D4 at rb4_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;
void lcd_clear(void)
{
lcd_cmd(_lcd_clear);
}
unsigned int current (void)
{
unsigned int result;
unsigned short msb,lsb;
lcd_out(1,1,"olcum");
i2c1_start();
i2c1_wr(0x80);
i2c1_wr(0x01);
i2c1_repeated_start();
i2c1_wr(0x81);
msb=i2c1_rd(1);
lsb=i2c1_rd(0);
i2c1_stop();
result = msb;
result=result*256+lsb;
lcd_out(1,1,"bitti");
return result;
}
///////////////////////////////
void main()
{
unsigned int result,resultfloat,power,powerf;
char resulttxt[7];
char currenttxt[14];
adcon1|=0x0f;
cmcon|=7;
i2c1_init(20000);
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
lcd_out(1,1,"Adil Can");
lcd_out(2,1,"Balcik");
while(1)
{
delay_ms(1000);
lcd_clear();
result=current()*100/93;
power=result*5;//10 times of power
resultfloat=result%10;
result=result/10;
lcd_out(1,1,"Current:");
wordtostr(result,resulttxt);
lcd_out(2,1,ltrim(resulttxt));
lcd_chr_cp(',');
wordtostr(resultfloat,resulttxt);
lcd_out_cp(ltrim(resulttxt));
lcd_out_cp(" mA");
delay_ms(1000);
lcd_clear();
lcd_out(1,1,"Power:");
powerf=power%10;
power=power/10;
wordtostr(power,resulttxt);
lcd_out(2,1,ltrim(resulttxt));
lcd_chr_cp(',');
wordtostr(powerf,resulttxt);
lcd_out_cp(ltrim(resulttxt));
lcd_out_cp(" mW");
delay_ms(1000);
lcd_clear();
lcd_out(1,1,"..calculating..");
}
}
youtube bağlantısı:
https://www.youtube.com/watch?v=FLBzrH9kTvI