ssdst
How to generate high-frequency pulses in OpenPLC
thiagoralves
This will depend a bit on the hardware platform you're using, but in general, just use an analog output (%QW0, %QW1, %QW2.. etc) that is associated with a PWM-capable pin. The range is 0-65535. Frequency is fixed (hardware dependent), but you can control the duty cycle.
Reply 0 0
ssdst
This will depend a bit on the hardware platform you're using, but in general, just use an analog output (%QW0, %QW1, %QW2.. etc) that is associated with a PWM-capable pin. The range is 0-65535. Frequency is fixed (hardware dependent), but you can control the duty cycle.
 
Thank you very much for your answer

Taking Raspberry Pi as an example, I know how to send high-frequency pulses in Linux, but I don't know how to integrate it into OpenPLC. In my understanding, the scanning cycle of OpenPLC limits its maximum frequency of sending pulses. Below is the C code I found that can send high-frequency pulses in Linux. What should I do to apply it to OpenPLC

 

#include <pigpio.h>
#include <stdio.h>

int main(int argc, char *argv[]) {

    if (gpioInitialise() < 0) return -1;
    int gpioPin = 18;
    gpioSetMode(gpioPin, PI_OUTPUT);
    unsigned int pulseCount = 3000;
    if( 0 != gpioWaveClear())
    {
     printf("clear wave failed.\n");  
   }

    gpioPulse_t pulses[pulseCount * 2];
    for (int i = 0; i < pulseCount; i++) {
        pulses[i * 2].gpioOn = (1 << gpioPin);
        pulses[i * 2].gpioOff = 0;
        pulses[i * 2].usDelay = 10;
        pulses[i * 2 + 1].gpioOn = 0;
        pulses[i * 2 + 1].gpioOff = (1 << gpioPin);
        pulses[i * 2 + 1].usDelay = 10;
    }
    
    gpioWaveAddNew();
    gpioWaveAddGeneric(pulseCount * 2, pulses);

    int waveId = gpioWaveCreate();
    if (waveId < 0) {
        fprintf(stderr, "Wave creation failed.\n");
        gpioTerminate();
        return -1;
    }

    int res = gpioWaveChain((char *)&waveId, 1);
    if (res != 0 )
    {
    printf("gpio wave chain failed.\n");
  }
  

    while (gpioWaveTxBusy()) {
        gpioDelay(10);
    }
    

    gpioWaveTxStop();
    gpioWaveClear();

    gpioTerminate();

    return 0;
}
 
Reply 0 0
thiagoralves
You can’t do this on a PLC runtime. This pulse generation depends 100% on the CPU, which means that the CPU is busy generating pulses and can’t do anything else. This does not work on a PLC, because you won’t have any CPU left to run the other tasks (I’m ignoring the multi-core aspect of the Pi just to simplify the explanation). The right way to generate pulses is by using a hardware peripheral that can create the pulses independently of the CPU, so the CPU is free to do other things. The Pi has a PWM unit that can be used for this. The PWM is attached to location %QW0. If you write a value between 0-65535 on a variable located at %QW0 then the PWM pin will generate a square wave with the duty cycle proportional to the value you wrote, where 0 is 0% duty cycle and 65535 is 100% duty cycle.
Reply 0 0
ssdst
You can’t do this on a PLC runtime. This pulse generation depends 100% on the CPU, which means that the CPU is busy generating pulses and can’t do anything else. This does not work on a PLC, because you won’t have any CPU left to run the other tasks (I’m ignoring the multi-core aspect of the Pi just to simplify the explanation). The right way to generate pulses is by using a hardware peripheral that can create the pulses independently of the CPU, so the CPU is free to do other things. The Pi has a PWM unit that can be used for this. The PWM is attached to location %QW0. If you write a value between 0-65535 on a variable located at %QW0 then the PWM pin will generate a square wave with the duty cycle proportional to the value you wrote, where 0 is 0% duty cycle and 65535 is 100% duty cycle.

Thank you very much for your answer. I understand what you mean, but what should I do if I want to accurately send a specific number of high-frequency pulses?
Reply 0 0
thiagoralves
You can’t do this on OpenPLC.
Reply 0 0
ssdst
You can’t do this on OpenPLC.
get it  . thank u very much
Reply 0 0
Reply