Syncing separate PWM signals

I’m attempting to use two PWM pins, both of different instances, to generate two signals. My current task is to synchronize these two so that one goes through a certain amount of periods while the other signal is high. Specifically, I need a 250 KHz signal to go through 256 periods while a 40 Hz signal is high for 1.05 ms and low for the other 23.95 ms. However the signals don’t sync up on the oscilloscope, even though according to the math they should. Do I have to just figure out by plugging in different numbers until I find out which one works? Also, is there a way to make it so that the rising edge of the 250 KHz signal always comes a certain amount of time after the rising edge of the 40 Hz?

while 40Hz is exactly 6250 times slower than 250kHz, you have to check
that it's possible to set those exact values in the timers. I don't
remember off hand the math, but I think it's a clock multiplier off
some system clock tick, so it may turn out that either 250kHz or 40Hz
or both are not exact values, in which case the signals can not be in
sync. Also, 256 periods of 250kHz is 1.024 ms, not 1.05ms

How do you generate the PWM output (which hardware subsystems do you use)? And how do you controll them (by which software)?

When you use the PWMSS subsystems (either eCAP or PWM modules), you can synchronize two subsystems by setting some bits in the control registers. See SRM chapter 15 for details. Ie. you can use libpruio for easy access to those registers.

BR

PRUs might solve your issue.