AnsweredAssumed Answered

ADE7816 Line Cycle Accumulation Mode

Question asked by Leszek26 on Apr 17, 2013
Latest reply on Apr 30, 2013 by Leszek26

I built own circuit with the ADE7816 and Altera FPGA. I can communicate with the ADE7816 and I can measure voltage RMS and current RMS.

 

I have some problem when I try to implement Line Cycle Accumulation Mode to measure active and reactive energy.

 

I use NIOS II processor implemented inside Altera Cyclone III FPGA and I am talking to the ADE7816 using SPI bus.

 

I use two interrupts:

Timer 1 interrupt occurs every 15 seconds.

 

I program LINECYC register to 0x0600 after Reset.

My Timer 1 interrupt service routine sets the “timer1_occured” flag.

After main loop program (listing below) detects this, program enables line cycle accumulation mode by setting bits LWATT, LVAR and ZX_SEL in register LCYCMODE. I also set bit 5-th (LENERGY) in register MASK0 three times, because of pipelining.

So first time after reset everything works as expected: after 5 seconds after enabling this bit, ADE7816 generates IRQ0 interrupt (I see it with the scope). My program disables bit LENERGY in the STTATUS0 register and also in the MASK0 register.

 

The problem is that next time 2ms (instead of 5 seconds) after Timer 1 interrupt ADE7816 generates interrupt as soon as this interrupt is enabled, instead being generated after 5 seconds like after reset.

 

Below I show  main loop in my program and generated printouts:

 

 

 

 

            while(1)

            {

                        if(timer1_occured)

                        {

                                    IOWR_ALTERA_AVALON_PIO_DATA(PROBE_3_BASE, 0x01);

                                    enable_acc_int();

 

                                    if(!show_once)

                                    {

                                                printf("timer1_occured\n");

                                                read_linecyc_lcycmode();

                                                show_once=1;

                                    }

 

                                    if(energy_data_ready)

                                    {

                                                IOWR_ALTERA_AVALON_PIO_DATA(PROBE_4_BASE, 0x01);

                                                printf("energy_data_ready\n");

                                                read_linecyc_lcycmode();

                                                disable_acc_int();

                                                printf("after disabling acc_int\n");

                                                read_linecyc_lcycmode();

                                                printf("Measurement=%d\n", interruptCount_1);

                                                energy_data_ready=0;           //reset data_ready flag

                                                timer1_occured=0;                 //reset Timer1 flag

                                                show_once=0;

                                                IOWR_ALTERA_AVALON_PIO_DATA(PROBE_1_BASE, 0x00);

                                                IOWR_ALTERA_AVALON_PIO_DATA(PROBE_2_BASE, 0x00);

                                                IOWR_ALTERA_AVALON_PIO_DATA(PROBE_3_BASE, 0x00);

                                                IOWR_ALTERA_AVALON_PIO_DATA(PROBE_4_BASE, 0x00);

//                                              read_energy_data();

//                                              display_rms();

                                    }

                        }

 

 

LINECYC=0x0600

LCYCMODE=0x0

STATUS0=0x0000

MASK0=0x00020

 

timer1_occured

 

LINECYC=0x0600

LCYCMODE=0xB

STATUS0=0x03580

MASK0=0x00020

 

energy_data_ready

 

LINECYC=0x0x0600

LCYCMODE=0xB

STATUS0=0x035820

MASK0=0x00020

 

after disabling acc_int

 

LINECYC=0x0x0600

LCYCMODE=0x0

STATUS0=0x035820

MASK0=0x0000

 

Measurement=1

 

timer1_occured

 

LINECYC=0x0x0600

LCYCMODE=0xB

STATUS0=0x0358e0

MASK0=0x00020

 

energy_data_ready

 

LINECYC=0x0x0600

LCYCMODE=0xB

STATUS0=0x0358e0

MASK0=0x00020

 

after disabling acc_int

 

LINECYC=0x0x0600

LCYCMODE=0x0

STATUS0=0x0358e0

MASK0=0x0000

 

Measurement=2

*************************************************************************

Attachments

Outcomes