Post Go back to editing

ade7758 random vrms issue

Category: Hardware
Product Number: ade7758
Software Version: arduino IDE

Guys,.. I'm interfacing ADE7758 with Arduino MEGA2560. Now i'm facing issues on values of Vrms. I'm getting strange values which vary each time.SPI communication is alright I tryed to get default values of some registers i got it right. But when i read terms like frequency,Temperature the also show similar values like vrms.

Temperature 8650751
Vrms phase 14096
********************************************
Temperature 8650751
Vrms phase 14096
********************************************
Temperature 8650751
Vrms phase 14096

I'm using circuit on  data sheet but I connected VN and floating ground. otherwise I will get fluctuating values.


Parents
  • The image provided is difficult to read can you upload a better picture? 

    What is your current sensor? 

    For the voltage divider you should use multiple resistors for 220v or 120V for example 3X330K and a 1K resistor?

    Are your register values raw register values? 

    The temperature register is 8 bits are you reading 8 bits?

    Is this a conversion error? 

    Dave

  • Now I'm just measuring  Vrms. I didn't use a current sensor.
    The about register values they  are raw values.
    I was reading temperature register as 24bits by mistake now I corrected, still the values doesn't make sense .
    Now i just grounded all pins to make sure they return register but unfortunately they read some random values.


  • Its the circuit but later I had made changes    

  • taking reference from (ez.analog.com/.../ade7758-rms-calibration-help-me  ) I connected VN with AGND and DGND.

  • The image provided is difficult to read can you upload a better picture? 

    I need to see more data read VRMS 20 times at 2 different voltages if possible. 

    read these registers with your line voltage on the  voltage channel 

    mmode      // freq sel  the  appropriate votlage channel.

    LCYCMODE

    FREQ

  • With 220v /1000  or 220mvRMS I get AVRMS = 1605625 AIRMS = 871 using the example in the TXT file

    // Required Registers for 7758
    #define res       0x00
    
    #define AWATTHR   0x01  //16
    #define BWATTHR   0x02  //16
    #define CWATTHR   0x03  //16
    
    #define AVARHR    0x04   //16
    #define BVARHR    0x05   //16
    #define CVARHR    0x06   //16
    
    #define AVAHR     0x07    //16
    #define BVAHR     0x08    //16
    #define CVAHR     0x09    //16
    
    #define AIRMS     0x0A  //24
    #define BIRMS     0x0B  //24
    #define CIRMS     0x0C  //24
    
    #define AVRMS     0x0D  //24
    #define BVRMS     0x0E  //24
    #define CVRMS     0x0F  //24
    
    
    #define FREQ      0x10  //16
    #define TEMP      0x11  //8
    #define WFORM     0x12  //24
    
    #define OPMODE    0x13  //8
    #define MMODE     0x14  //8
    #define WAVMODE   0x15  //8
    #define COMPMODE  0x16  //8
    #define LCYCMODE  0x17  //8
    #define MASK      0x18  //24
    #define STATUS    0X19  //24
    #define RSTATUS   0x1A  //24
    #define ZXTOUT    0x1B  //16
    #define LINECYC   0x1C  //16
    #define SAGCYC    0x1D  //8
    #define SAGLVL    0x1E  //8
    #define VPINTLVL  0x1F  //8
    #define IPINTLVL  0x20  //8
    #define VPEAK     0x21  //8
    #define IPEAK     0x22  //8
    #define GAIN      0x23  //8
    
    #define AVRMSGAIN 0x24  //16
    #define BVRMSGAIN 0x25  //16
    #define CVRMSGAIN 0x26  //16
    
    #define AIGAIN    0x27  //16
    #define BIGAIN    0x28  //16
    #define CIGAIN    0x29  //16
    
    #define AWG       0x2A  //16
    #define BWG       0x2B  //16
    #define CWG       0x2C  //16
    
    #define AVARG     0x2D  //16
    #define BVARG     0x2E  //16
    #define CVARG     0x2F  //16
    
    #define AVAG      0x30  //16
    #define BVAG      0x31  //16
    #define CVAG      0x32  //16
    
    #define AVRMSOS   0x33  //16
    #define BVRMSOS   0x34  //16
    #define CVRMSOS   0x35  //16
    
    #define AIRMSOS   0x36  //16
    #define BIRMSOS   0x37  //16
    #define CIRMSOS   0x38  //16
    
    #define AWATTOS   0x39  //16
    #define BWATTOS   0x3A  //16
    #define CWATTOS   0x3B  //16
    
    #define AVAROS    0x3C  //16
    #define BVAROS    0x3D  //16
    #define CVAROS    0x3E  //16
    
    #define APHCAL    0x3F  //8
    #define BPHCAL    0x40  //8
    #define CPHCAL    0x41  //8
    
    #define WDIV      0x42  //8
    #define VARDIV    0x43  //8
    #define VADIV     0x44  //8
    #define APCFNUM   0x45  //16
    #define APCFDEN   0x46  //16
    #define VARCFNUM  0x47  //16
    #define VARCFDEN  0x48  //16
    #define CHKSUM    0x7E  //8
    #define VERSION   0x7F  //8
    									
    
    //blue pill powers iso side only need 5v for ade7758
    
    #include <SPI.h>
    #include "ADE7758_reg.h"
    
    void ADE7758_SPI_WRITE(uint8_t Address , uint32_t Data , uint8_t Number_of_bytes);
    uint32_t ADE7758_SPI_READ (uint8_t Address, uint8_t Number_of_bytes);
    void ADE7758_reg_config();
    
    
    
    
    //outputs
    #define PM_0 PB15
    #define PM_1 PA8
    #define RESET_B PB3
    #define SSB_A PA4
    #define SSB_B PB5
    #define SSB_C PB4
    
    //inputs
    #define CF1 PB6
    #define CF2 PB7
    #define CF3 PC14
    #define IRQ0 PB14
    #define IRQ1 PB13
    #define DREADY PB12
    
    #define FLAG PB0
    
    #define SSB_A PA4
    //SPI_1 Chip Select pin is PA4. You can change it to the STM32 pin you want.
    //LED1=PC_13  SERIAL_TX=PA_2  I2C_SCL=PB_8  SPI_MOSI=PA_7  PWM_OUT=PB_3
    //            SERIAL_RX=PA_3  I2C_SDA=PB_9  SPI_MISO=PA_6
    //                                          SPI_SCK =PA_5
    
    // bluepill      ADE7758
    //PA4  > SSB_A   >> SSB
    //PB5  > SSB_B
    //PB4  > SSB_C
    
    //PA2 > tx       >> TX
    //PA3 > rx       >> RX
    
    //PA5  > sclk    >> SCLK
    //PA6  > miso    >> MISO
    //PA7  > mosi    >> MOSI
    
    //PA8  > PM1     >>
    //PB15 > PM0     >>
    //PB14 > IRQ0    >> IRQ
    //PB13 > IRQ1    >> ZX
    
    //PB9  > sda     >> SDA
    //PB8  > scl     >> SCL
    
    //PB3  > RSTB    >>RESETB
    //PB12 > DREADY  >> ZX_I
    
    //PB6  > CF1
    //PB7  > CF2
    //PC14 > CF3
    
    byte data;
    uint32_t count;
    int32_t ARRAY[3250];
    int i = 0;
    
    
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(2000000);
      while (!Serial);  // wait for serial to be configured
    
    
      pinMode(SSB_A, OUTPUT);
      pinMode(RESET_B, OUTPUT);
      pinMode(MOSI, OUTPUT);
      pinMode(MISO, OUTPUT);
      pinMode(FLAG, OUTPUT);
    
    
      digitalWrite(SSB_A, LOW);   // sets up I/o state for spi coms before reset
      digitalWrite(MISO, LOW);
      digitalWrite(MOSI, LOW);
      digitalWrite(FLAG, LOW);
    
      //reset part
    
    
      delay(1000); // fixed delay will addin IRQ monitor later
    
      // pinMode(MOSI, INPUT);  // change mode for spi not sure if needed
      pinMode(MISO, INPUT);  // change mode for spi not sure if needed
      pinMode(IRQ0, INPUT);
    
      digitalWrite(SSB_A, HIGH);
    
      SPI.begin(); //Initialize the SPI_1 port
      SPI.setBitOrder(MSBFIRST); // Set the SPI_1 bit order
      SPI.setDataMode(SPI_MODE1); //Set the SPI_2 data mode 0
      SPI.setClockDivider(SPI_CLOCK_DIV16);      // Slow speed (72 / 16 = 4.5 MHz SPI_1 speed)
    
      Serial.println("Begin Setup");
     
    
     
     
      
      //ADE7758_SPI_READ(RSTATUS, 3); //clr startup IRQ
       
      //ADE7758_reg_config(); 
      delay(1000);
     
      
     
      
      //attachInterrupt(digitalPinToInterrupt(IRQ0), IRQ_irq, FALLING );
      //attachInterrupt(digitalPinToInterrupt(IRQ1), ZX_irq, FALLING );
    
    }
    
    
    void loop(){
            Serial.print("AVRMS = ");Serial.print(ADE7758_SPI_READ(AVRMS, 3)); Serial.print(" AIRMS = ");Serial.println(ADE7758_SPI_READ(AIRMS, 3));
            Serial.print("BVRMS = ");Serial.print(ADE7758_SPI_READ(BVRMS, 3)); Serial.print(" BIRMS = ");Serial.println(ADE7758_SPI_READ(BIRMS, 3));
            Serial.print("CVRMS = ");Serial.print(ADE7758_SPI_READ(CVRMS, 3)); Serial.print(" CIRMS = ");Serial.println(ADE7758_SPI_READ(CIRMS, 3));  
            delay(1000);
      
    }
    
    
    
    void IRQ_irq() {Serial.print('IRQ Status : ');ADE7758_SPI_READ(RSTATUS, 3);}
    
    
    void ZX_irq() {Serial.println("ZX tetected");}
    
    
    
    void ADE7758_reg_config()
    {
     // ADE7758_SPI_WRITE(LCYCMODE, 0x77, 1);
      Serial.print("LCYCMODE=");
      Serial.println(ADE7758_SPI_READ(LCYCMODE, 1), HEX);
    }
    
    
    
    
    void ADE7758_SPI_WRITE(uint8_t Address , uint32_t Data , uint8_t Number_of_bytes)
    {
      uint8_t mhb = 0, hb = 0, mb = 0, lb = 0, p = 0;
      uint32_t j;
     
      lb = (uint8_t)(Data & 0xff);
      mb = (uint8_t)((Data & 0xff00) >> 8);
      hb = (uint8_t)((Data & 0xff0000) >> 16);
      mhb =(uint8_t)((Data & 0xff000000) >> 24);
    
      
    
      digitalWrite(SSB_A, LOW);   //set csb low
    
      SPI.transfer((0x7f & Address)| 0x80);      // send write bit and address
    
      //send requested number of bytes
      switch (Number_of_bytes) {
        case 4:
          SPI.transfer(mhb);
        case 3:
          SPI.transfer(hb);
        case 2:
          SPI.transfer(mb);
        case 1:
          SPI.transfer(lb);
        default:
          break;
      }
    
      digitalWrite(SSB_A, HIGH);  //set csb high
    }
    
    
    
    
    
    
    uint32_t ADE7758_SPI_READ (uint8_t Address, uint8_t Number_of_bytes)
    {
      uint8_t mhb = 0, hb = 0, mb = 0, lb = 0;
      uint32_t j=0;
     
      digitalWrite(SSB_A, LOW);   //set csb low
    
      SPI.transfer(0x7f & Address);      // send read bit and address
    
      switch (Number_of_bytes) {
        case 4:
          mhb = SPI.transfer(0);   // dummy write
        case 3:
          hb = SPI.transfer(0);
        case 2:
          mb = SPI.transfer(0);
        case 1:
          lb = SPI.transfer(0);
        default:
        break;
          }
    
      digitalWrite(SSB_A, HIGH);  //set csb high
      
          j = (mhb << 24);
          j = j + (hb << 16);
          j = j + (mb << 8);
          j = j + (lb);
      
      return (j);
    }
    

  • I am using the ADE7758 evaluation board with a bluepill and Arduino IDE 

    Dave

  • Thanks bro due to some production reasons I had switched the Microcontroller to PIC . My code runs well but I have issues on response while reading V peak(0x21) I'm getting -1 as output.

Reply Children