Greetings everyone,
If you can lend a hand, please do not hesitate to assist me.
Hardware: NUCELO-F767ZI
I am currently working on a mechanical application where I need to trigger a signal using various components (refer to void output_pwm
) after each falling edge of an input signal. However, I have encountered an issue where if the output signal collides with a falling edge, it will continue to move towards the right side. It appears that the program experiences a conflict when detecting a new falling edge while still outputting another signal.
I have attached some screenshots from my Picoscope below:
- trigger the output signal 32 ms after the falling edge (the output signal doesnât collide with the falling edge of the input)
in this case it works perfectly.
- trigger the output signal 33 ms after the falling edge (the output signal does collide with the falling edge of the input)
In this case the output signal (green) keeps moving to the right side.
Here is my code:
#include "mbed.h"
#include <chrono>
#include <cstdio>
#include <ratio>
// the signal I want to output after a falling edge of square
PwmOut myPWM(PE_11);
// Define the input pin for detecting the falling edge
InterruptIn input(PF_15);
Thread pwm_thread;
// Signal to the PWM thread to start a new output sequence
volatile bool start_pwm_output = false;
// Output function for myPWM1
void output_pwm() {
// these are the signal parts of myPWM1
wait_us(32000); // wait 32 ms before output
myPWM.write(1);
wait_us(10000);
myPWM.period(1.0f / 15000.0f);
myPWM.write(0.5f);
wait_us(20000);
myPWM.write(0);
}
// PWM output thread
void pwm_output_thread() {
while (1) {
if (start_pwm_output) {
output_pwm();
start_pwm_output = false;
}
// Sleep for a short period to give other threads a chance to run
//ThisThread::sleep_for(1ms);
}
}
int main() {
// Start the PWM output thread
pwm_thread.start(pwm_output_thread);
// Set up the interrupt for detecting the falling edge
input.fall(callback(&output_pwm));
while (1) {
}
}
Considering that my board has only one core, is it technically possible to achieve what I want to do?
NOTE: I used wait_us()
because Iâm willing to controle the waiting time dynamically with a potentiometer. ThisThread::sleep_for()
isnât the best in this situation.
thank you in advance for your time.
best regards,
Ezzow