Hello, I've not posted before, though I've intermittently lurked for several years. However, I've now got something where I haven't found the answer previously discussed, and I think it will be an easy one for someone:
I'm using a teensy 3.2. I'm generating PWM on pins 3, 4, 9 & 10 (so I'm using both FTM0 and FTM1), and may use more in future. This is at only about 50 Hz, and my pulses are all in the 1.0mS to 2.0mS range (those pulses control ordinary radio-control components - servos and motor speed controllers).
However, I'm calculating my desired pulse width on the basis of a number of inputs, one of which is the output from a radio-control receiver, which provides a data packet at 18mS intervals (so about 55.5Hz). I redo my calculation every time I get a receiver data packet, and it would be convenient to generate a new set of output pulses each time I recalculate. The problem is synchronising the PWM output with when I've done the calculation - and if the frequencies don't match (which they don't exactly) I do my calculation just too late for the update to affect the PWM outputs, and then my output pulses lag nearly a whole cycle behind the input data that caused them.
So the ways this might work are:
1: Does the PWM library or the timers it sits on top of have a 'synchronise to external signal' option?
2: Is there a library a bit like PWM analogWrite which lets me specify a different pulse width for each of several pins, but I get one pulse of specified width on a pin when triggered, not on a regular cycle (though it would be triggered fairly regularly, immediately after each calculation). If not a library already, can someone point me to what part of the manual might let me achieve this?
3: It seems to me this might be possible by setting up for PWM at sure-to-be-lower-than-I-need frequency (say 40 Hz), but then when I want a pulse, manually writing to the relevant timer count register to make it think the time has come for a new pulse. That is, if it start a pulse each time a 16 bit timer overflows, when I wanted a pulse I'd write the duration wherever it needs to be, then 65535 into that timer's count register.
I've been reading the Flextimer chapter in the reference manual, and the PWM code in ...cores/teensy3/pins_teensy.c but I'm really not fluent at C or tried reading the manual before, and I'm finding it a bit baffling. Some pointers of where I should be focusing would be great (especially if the answer is not one of these two places). Thanks.
I'm using a teensy 3.2. I'm generating PWM on pins 3, 4, 9 & 10 (so I'm using both FTM0 and FTM1), and may use more in future. This is at only about 50 Hz, and my pulses are all in the 1.0mS to 2.0mS range (those pulses control ordinary radio-control components - servos and motor speed controllers).
However, I'm calculating my desired pulse width on the basis of a number of inputs, one of which is the output from a radio-control receiver, which provides a data packet at 18mS intervals (so about 55.5Hz). I redo my calculation every time I get a receiver data packet, and it would be convenient to generate a new set of output pulses each time I recalculate. The problem is synchronising the PWM output with when I've done the calculation - and if the frequencies don't match (which they don't exactly) I do my calculation just too late for the update to affect the PWM outputs, and then my output pulses lag nearly a whole cycle behind the input data that caused them.
So the ways this might work are:
1: Does the PWM library or the timers it sits on top of have a 'synchronise to external signal' option?
2: Is there a library a bit like PWM analogWrite which lets me specify a different pulse width for each of several pins, but I get one pulse of specified width on a pin when triggered, not on a regular cycle (though it would be triggered fairly regularly, immediately after each calculation). If not a library already, can someone point me to what part of the manual might let me achieve this?
3: It seems to me this might be possible by setting up for PWM at sure-to-be-lower-than-I-need frequency (say 40 Hz), but then when I want a pulse, manually writing to the relevant timer count register to make it think the time has come for a new pulse. That is, if it start a pulse each time a 16 bit timer overflows, when I wanted a pulse I'd write the duration wherever it needs to be, then 65535 into that timer's count register.
I've been reading the Flextimer chapter in the reference manual, and the PWM code in ...cores/teensy3/pins_teensy.c but I'm really not fluent at C or tried reading the manual before, and I'm finding it a bit baffling. Some pointers of where I should be focusing would be great (especially if the answer is not one of these two places). Thanks.