Post Go back to editing

Power quality event can't be detected when process_data = 0

Category: Hardware
Product Number: AD-PQMON-SL

Hardware: AD-PQMON-SL

 

Goal:

Obtain the waveform when a power quality event occurs

 

Problem Description:

  1. When process_data = 1, interrupt event can be detected.
  2. When process_data = 0, interrupt event failed to be detected.
  3. iio_device_attr_write_double() failed to overwrite process_data from 0 to 1.

 

Error Video:

 

Troubleshooting step that has been taken:

In my full coding, I can overwrite process_data from 1 (default value) to 0 to enable waveform data collection.

 

Coding:

 

#include <stdio.h>

#include <stdlib.h>

#include <iio.h>


int main() {

    // Configuration
    struct iio_context* ctx = iio_create_context_from_uri("serial:/dev/ttyACM0,115200,8n1");
    const struct iio_device* dev = iio_context_get_device(ctx, 0);
    struct iio_channel* chn = iio_device_get_channel(dev, 10);
    const char* chnName = iio_channel_get_name(chn);
    printf("Channel[10] name: %s \n", chnName);


    // Process Data
    double process_data = 9.0;
    iio_device_attr_write_double(dev, "process_data", 1.0);
    iio_device_attr_read_double(dev, "process_data", &process_data);
    printf("Process data: %lf \n", process_data);


	// Read countEvent
    double chnAttrValue = 0.0;

    while (true)
    {
        iio_channel_attr_read_double(chn, "countEvent", &chnAttrValue);

        if (chnAttrValue != 0.0)
        {
            printf("countEvent: %lf \n", chnAttrValue);

            break;
        }
    }




    iio_context_destroy(ctx);

}

  • Hi , if you want to have events and waveform at the same time, I recommend using one of the versions that implement the waveform reading based on interrupts, since in the implementation on main the status is polled. The process data was added to stop the library computing while the waveform is read and transmitted, since the library is blocking, hence the waveform data will have discontinuities. If you use the interrupt version for waveform reading you can make it work in the same time. I recommend using the interrupt only for the waveform and the other readings can still happen by pooling the STATUS0 register (like the implementation on main).  You can look here for an example and adapt it: projects: eval-pqmon: Waveform streaming · analogdevicesinc/no-OS@498d01f  - this is just an example since it is not on main.

  • Hi  ,

    I'm using analogdevicesinc/no-OS at 498d01fe981cd7f71929336123a8813070790827 to build hex file. Then i run simplest coding below at Windows.

    Whatever value of process data = 1 or 0, buffer can't be created, power quality events also fail to be detected.

    #include <stdio.h>
    
    #include <stdlib.h>
    
    #include <iio.h>
    
    
    int main() {
    
        // Configuration
        struct iio_context* ctx = iio_create_context_from_uri("serial:COM4,921600,8n1");
        const struct iio_device* dev = iio_context_get_device(ctx, 0);
        struct iio_channel* chn = iio_device_get_channel(dev, 10);
        const char* chnName = iio_channel_get_name(chn);
        printf("Channel[10] name: %s \n", chnName);
    
    
        // Process Data
        double process_data = 9.0;
        //iio_device_attr_write_double(dev, "process_data", 0.0);
        iio_device_attr_read_double(dev, "process_data", &process_data);
        printf("Process data: %lf \n", process_data);
    
        //Buffer
        struct iio_buffer* buffer = iio_device_create_buffer(dev, 256, false);
    
        if (!buffer) {
            fprintf(stderr, "Error: Failed to create buffer\n");
    
        }
    
        // Read countEvent
        double chnAttrValue = 0.0;
    
        while (true)
        {
            iio_channel_attr_read_double(chn, "countEvent", &chnAttrValue);
    
            if (chnAttrValue != 0.0)
            {
                printf("countEvent: %lf \n", chnAttrValue);
    
                break;
            }
        }
    
    
    
    
        iio_context_destroy(ctx);
    
    }

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.