interfacing energy meter ic

Discussion in 'Embedded Systems and Microcontrollers' started by embedded.world, Mar 2, 2014.

  1. embedded.world

    Thread Starter Member

    Feb 27, 2014
    36
    0
    I have interfaced Ade7754.
    For voltage measurement, i have divided voltage by divider 1k/1.5M.
    So voltage gets divided by 1500.
    I have shorted Va,Vb & Vc of Ade5574.
    I am using Spi freq 0.5 mhz & mode 1.
    I am polling interrupt register.

    On reading voltage I am getting wrong values. It varies from 270 ac - 290 ac.
    Sometimes ic reads 6806 which is equivalent to 0xffffff of Vrms register. Can someone check my code:

    Code ( (Unknown Language)):
    1. main()
    2. {
    3.      RT=0;
    4.      delay_us(20000);    
    5.      RT=1;
    6.      delay_us(2000);        //10usec
    7.    
    8.     Spi_init( 500000 , mode_1 );
    9.    
    10.      CS = 0;
    11.      delay_us(100);  
    12.  
    13.     spi_wrt(0x80 | 0x0B);        //MMODE
    14.     spi_wrt(0x70);
    15.  
    16.     delay_us(200);
    17.     spi_wrt(0x80 | 0x0F);        //IRQEN
    18.     spi_wrt(0x03);
    19.     spi_wrt(0x80);
    20.  
    21.     delay_us(200);
    22.     spi_wrt(0x11);        //RSTATUS
    23.     temp = spi_rd();
    24.     temp = spi_rd();
    25.  
    26.  
    27.      while(1)
    28.     {
    29.         flag = 0;
    30.      
    31.         while(0 == flag)
    32.          {
    33.              spi_wrt(0x10);        //STATUS
    34.              val1 = spi_rd();;
    35.              val2 = spi_rd();
    36.  
    37.              if(val2 & 0x80) // if Va Zc interrupt
    38.              {
    39.                 flag = 1;
    40.              }
    41.  
    42.          }
    43.  
    44.           spi_wrt(0x2C);        //current read
    45.            val1 = spi_rd();;
    46.            val2 = spi_rd();
    47.            val3 = spi_rd();
    48.  
    49.         spi_wrt(0x11);        //RSTATUS
    50.         temp = spi_rd();
    51.         temp = spi_rd();
    52.  
    53.  
    54.         vrms=((unsigned long)val1<<16)|((unsigned long)val2<<8)|((unsigned long)val3);
    55.        
    56.         vrms = ( (0.5f * vrms) / 1848772 ) * 1500;       //0.5V/ 1848772counts is fullscale volage reading
    57.  
    58. }
     
    Last edited by a moderator: Mar 2, 2014
Loading...