• AVR Freaks

Hot!Reading unknown power value from PmeanA register of M90E32AS Energy meter IC

Author
vijayakumar.sargunam
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2012/10/12 22:59:47
  • Location: 0
  • Status: offline
2020/08/05 21:04:26 (permalink)
0

Reading unknown power value from PmeanA register of M90E32AS Energy meter IC

Hi Friends,
I am interfacing dsPIC33F with M90E32AS 3 phase energy meter IC. Iam trying to read the power value from the energy meter IC. For reading 32 bit power value there are two 16-bit registers involved, one is PmeanA/B/C for MSB and PmeanLSB A/B/C for LSB. we have to combine both the register and multiply with 0.00032 to get the exact power value. that I have done like below.
int PmA_read() // For reading MSB of power value 
{
CS=0;
SPI2BUF=SBUF=0x80B1;
while(SPI2STATbits.SPITBF==1){}
SPI2BUF=0x0;

while(SPI2STATbits.SPITBF==1){}
delay_rx();

CS=1;
HiByte = SPI2BUF;
return HiByte;
}

int PmALSB_read() // For reading LSB of power value and combine both LSB and MSB to get total power
{
CS=0;
SPI2BUF=SBUF=0x80C1;
while(SPI2STATbits.SPITBF==1){}
SPI2BUF=0x0;

while(SPI2STATbits.SPITBF==1){}
delay_rx();
CS=1;
LoByte = SPI2BUF;
TPmA = (HiByte << 16)| LoByte;
Total = TPmA * 0.00032;
return Total;
}

but when I programmed the IC I can only get some unknown value in PmeanA register like 65428. I can able to get power value for phase B only. both A and C phase power values are unknown. How can I solve the problem. I am using the same type of code for reading power values in other phases (B and C) also.
 
Thanks
S.Vijayakumar
#1

5 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3946
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Reading unknown power value from PmeanA register of M90E32AS Energy meter IC 2020/08/06 01:26:23 (permalink)
    2 (1)
    Provided you have no coding issue, I expect this to be an M90E32AS resp. a PEBKAC issue, not a dsPIC issue:
    • All phases connected ?
    • All phases sourcing beyond the "threshold power"?
    • M90E32AS configured correctly ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    vijayakumar.sargunam
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2012/10/12 22:59:47
    • Location: 0
    • Status: offline
    Re: Reading unknown power value from PmeanA register of M90E32AS Energy meter IC 2020/08/06 23:07:51 (permalink)
    0
    Thanks for you suggestion du,
          
    • All phases connected ?
    • All the phases are connected since I am getting the voltage and current value from all the phases
    • Plz refer the attached output image in that i displayed all phase voltage, current, MSB of power value in decimal, energy. In that phase b power value coming correctly but not phase a and phase c.
    • All phases sourcing beyond the "threshold power"?
    • Not sure how to check it?
    • M90E32AS configured correctly ?
    • I am attaching the source code for configuration I have done for M90E32AS
    • void soft_reset_write()
      {
          CS=0;
       SPI2BUF=0x0070;
       while(SPI2STATbits.SPITBF==1){}
       SPI2BUF=0x0789A;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
      }
      void acc_write()
       {
       CS=0;
       SPI2BUF=0x007F;
       while(SPI2STATbits.SPITBF==1){}
       SPI2BUF=0x55AA;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
       }
      void MMode0_write()
      {
          CS=0;
          SPI2BUF=0x0033;
          while(SPI2STATbits.SPITBF==1){}
          SPI2BUF=0x0087;
          while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
      }
      void en_write()
       {
       CS=0;
       SPI2BUF=0x0000;
       while(SPI2STATbits.SPITBF==1){}
       //SPI2BUF=0xFF;
          SPI2BUF=0x01;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
       }
      void PL_H_write()
       {
       CS=0;
       SPI2BUF=0x0031;
       while(SPI2STATbits.SPITBF==1){}
       
          SPI2BUF=0x0861;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
       }
      void PL_L_write()
       {
       CS=0;
       SPI2BUF=0x0032;
       while(SPI2STATbits.SPITBF==1){}
       
          SPI2BUF=0xC468;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
       }

      void PStartTH_write()
      {
          CS=0;
       SPI2BUF=0x0035;
       while(SPI2STATbits.SPITBF==1){}
       SPI2BUF=0x0AFC;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
      }
      void QStartTH_write()
      {
       CS=0;
       SPI2BUF=0x0036;
       while(SPI2STATbits.SPITBF==1){}
       SPI2BUF=0x0AEC;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
      }

      void PPhaseTH_write()
      {
          CS=0;
       SPI2BUF=0x0038;
       while(SPI2STATbits.SPITBF==1){}
       SPI2BUF=0x00BC;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
      }
      void Pagain_write()
      {
       CS=0;
       SPI2BUF=0x0047;
       while(SPI2STATbits.SPITBF==1){}
       SPI2BUF=0x0008;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
      }
      void Pbgain_write()
       {
       CS=0;
       SPI2BUF=0x0049;
       while(SPI2STATbits.SPITBF==1){}
       SPI2BUF=0x0008;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
       }
      void Pcgain_write()
       {
       CS=0;
       SPI2BUF=0x004B;
       while(SPI2STATbits.SPITBF==1){}
       SPI2BUF=0x0008;
       while(SPI2STATbits.SPITBF==1){}
       delay_rx();
       CS=1;
       }

    Attached Image(s)

    #3
    LdB_ECM
    Super Member
    • Total Posts : 434
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Reading unknown power value from PmeanA register of M90E32AS Energy meter IC 2020/08/06 23:33:30 (permalink)
    4 (1)
    You are using the wrong flag SPITBF only speaks for the FIFO is doesn't mean completed transmission of the byte. You need to use the SRMPT flag to get completion of the send.
     
    So use
    while(SPI2STATbits.SRMPT==0){}

    everywhere you have
    while(SPI2STATbits.SPITBF==1){}

     
    Comment out all the delay_rx(); calls they are then junk and not needed.
     
    Now Bidirectional with the FIFO in polled mode (not using interrupts) is a little tricky because you need to pull an RX byte out for each transmitted but the FIFO is is the way. Confirm you have it all working byte for byte and I we can move onto to using the FIFO with polled mode.
    post edited by LdB_ECM - 2020/08/06 23:43:20
    #4
    du00000001
    Just Some Member
    • Total Posts : 3946
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Reading unknown power value from PmeanA register of M90E32AS Energy meter IC 2020/08/07 03:32:30 (permalink)
    0
    I don't know how you came to this, but these 65000+ values might indicate negative power when treated as signed integers !
    Does this ring a bell ... ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #5
    LdB_ECM
    Super Member
    • Total Posts : 434
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Reading unknown power value from PmeanA register of M90E32AS Energy meter IC 2020/08/07 07:10:38 (permalink)
    5 (1)
    Seriously follow the code and understand the operation of an SPI before you make wild assumptions?
    I was hoping he would work thru it and learn but you have clouded the water so I will detail the answer.
     
    So here is his code to read the first MSB A value .. .follow what it does
    int PmA_read() // For reading MSB of power value 
    {
    CS=0;
    SPI2BUF=SBUF=0x80B1;
    while(SPI2STATbits.SPITBF==1){}
    SPI2BUF=0x0;
    while(SPI2STATbits.SPITBF==1){}
    delay_rx();
    CS=1;
    HiByte = SPI2BUF;
    return HiByte;
    }

     
    The big hint here is I GUARANTEE you he doesn't read what he thinks he is ... the return is JUNK
     
    What he actually returns is the junk word that came in when he wrote 0x80B1.
    Even funnier he has one WORD left completely in the buffer which came in when he wrote 0x0.
    When he reads the LSB he will get that junk word and again leave another extra exchange in the fifo.
     
    The code can't work and is continually overflowing the RX FIFO. All he is seeing is the cycle between reading junk values and when it lines up that he reads a value but probably from another phase. It is called failure to understand how an SPI bus works .... AKA you write twice you need to read twice.
     
    Need I add the code is stupidly dangerous you have to make delay_rx stupidly long to guarantee you got the RX before you slam the CS line back high. If he tests the right flag he doesn't even need that delay. Also note the soft_reset likely leaves junk in the FIFO as well.
     
    post edited by LdB_ECM - 2020/08/07 07:47:55
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5