Post Go back to editing

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

Thread Summary

The user is unable to detect power quality events or create a buffer when using the AD-PQMON-SL with process_data set to 0. The solution involves setting waveform_capture_mode to continuous or oneshot after enabling scan elements on waveform channels, and using an interrupt-based approach for waveform reading to avoid blocking and ensure continuous data collection. The user should also verify the correct COM port and baud rate settings.
AI Generated Content
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);

}

Parents
  •  If you are using the branch for waveform streaming then you need to follow the following procedure: the attribute that needs to be set is waveform_capture_mode to continuous if you want to have waveform streaming. Before setting this attribute you need to enable the scan elements on the waveform channels.The process_data is by default 1 so PQ metrology runs concurrently. Waveform_streaming_active becomes true only after the waveform_capture_mode is set to continuous or oneshot.When waveform_capture_mode is set to disable then the waveform_streaming_active is false and the isr is disabled and get_afe_input will resume nomal waveform reading (this is the legacy path – Scopy uses this).

    Here are some examples on how you can test it.
      1. Connect to the IIO context (USB, serial, or network — however IIOD is exposed)

    1. Enable the scan elements on the waveform channels (ua, ub, uc, ia, ib, ic, in) — this tells the IIO subsystem which

      channels to include in the buffer

    1. Create an IIO buffer with the desired size (multiples of 256 samples per block)
    2. Write continuous or oneshot to the waveform_capture_mode device attribute
    3. Read from the buffer (refill)

      To stop: write disabled to waveform_capture_mode.

      Steps 2-3 must come before step 4 — the firmware checks active_ch != 0 when the mode is set. If no channels are enabled, waveform_streaming_active stays false and the ISR won't write data.

      This works from any IIO client — iio_attr + iio_readdev CLI tools, libiio C API, pylibiio, Scopy, or any custom application that speaks the IIO protocol.

    Here is an example for what is written above (adjust the comport to your case):

    1. Enable scan elements

     iio_attr -u serial:COM31,115200,8n1 -c pqm voltage0 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm voltage1 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm voltage2 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm current0 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm current1 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm current2 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm current3 raw -e 1

    1. Set capture mode:

      iio_attr -u serial:COM31,115200,8n1 -d pqm waveform_capture_mode continuous

    1. Read waveform data (256 samples = 1 block, -s = number of samples):

      iio_readdev -u serial:COM31,115200,8n1 -b 256 -s 2560 pqm voltage0 voltage1 voltage2 current0 current1 current2

      current3

    1. That reads 2560 samples (10 blocks).
    2. Stop:

      iio_attr -u serial:COM31,115200,8n1 -d pqm waveform_capture_mode disabled

    1. Check block_count (optional, at any time):

      iio_attr -u serial:COM31,115200,8n1 -d pqm waveform_block_count

    Please tell me if you succeed or if you encounter any problems. 

Reply
  •  If you are using the branch for waveform streaming then you need to follow the following procedure: the attribute that needs to be set is waveform_capture_mode to continuous if you want to have waveform streaming. Before setting this attribute you need to enable the scan elements on the waveform channels.The process_data is by default 1 so PQ metrology runs concurrently. Waveform_streaming_active becomes true only after the waveform_capture_mode is set to continuous or oneshot.When waveform_capture_mode is set to disable then the waveform_streaming_active is false and the isr is disabled and get_afe_input will resume nomal waveform reading (this is the legacy path – Scopy uses this).

    Here are some examples on how you can test it.
      1. Connect to the IIO context (USB, serial, or network — however IIOD is exposed)

    1. Enable the scan elements on the waveform channels (ua, ub, uc, ia, ib, ic, in) — this tells the IIO subsystem which

      channels to include in the buffer

    1. Create an IIO buffer with the desired size (multiples of 256 samples per block)
    2. Write continuous or oneshot to the waveform_capture_mode device attribute
    3. Read from the buffer (refill)

      To stop: write disabled to waveform_capture_mode.

      Steps 2-3 must come before step 4 — the firmware checks active_ch != 0 when the mode is set. If no channels are enabled, waveform_streaming_active stays false and the ISR won't write data.

      This works from any IIO client — iio_attr + iio_readdev CLI tools, libiio C API, pylibiio, Scopy, or any custom application that speaks the IIO protocol.

    Here is an example for what is written above (adjust the comport to your case):

    1. Enable scan elements

     iio_attr -u serial:COM31,115200,8n1 -c pqm voltage0 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm voltage1 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm voltage2 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm current0 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm current1 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm current2 raw -e 1

      iio_attr -u serial:COM31,115200,8n1 -c pqm current3 raw -e 1

    1. Set capture mode:

      iio_attr -u serial:COM31,115200,8n1 -d pqm waveform_capture_mode continuous

    1. Read waveform data (256 samples = 1 block, -s = number of samples):

      iio_readdev -u serial:COM31,115200,8n1 -b 256 -s 2560 pqm voltage0 voltage1 voltage2 current0 current1 current2

      current3

    1. That reads 2560 samples (10 blocks).
    2. Stop:

      iio_attr -u serial:COM31,115200,8n1 -d pqm waveform_capture_mode disabled

    1. Check block_count (optional, at any time):

      iio_attr -u serial:COM31,115200,8n1 -d pqm waveform_block_count

    Please tell me if you succeed or if you encounter any problems. 

Children
No Data

Before You Switch


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