Hi you all! I hope you are having a good week! 8)
I'm trying to generate a 2-PPM (Pulse Position Modulation) signal for optical transmission.
This modulation is simple. A time interval is divided into 2 position slots. Then the binary bits (0 or 1) are represented by a pulse located at the first or the second position. For example, if we want to send this binary data '001101' the output signal could be:
| 0 | 0 | 1 | 1 | 0 | 1 |
|ON OFF | ON OFF | OFF ON | OFF ON |ON OFF| OFF ON |
This can be done easily using Bit Banging on a Digital Pin with the use of the Compare Match Interruption from a Timer. However, this may suffer from jittering when the other interrupts are not disabled.
Another possibility that I would like to explore is the use of a Timer's PWM generator. I think this is possible cause the modulation proposed can be interpreted as a PWM signal with a constant duty cycle (50%) that is switching from its normal to its inverted state.
Following that statement, what I would like to do is to set up a PWM signal with a high frequency and while the signal is being transmitted (over the OC pins) address the register bits that configure the output state of the PWM signal. By doing that, data would be modulated by operating just these bits of the timer's register.
Is this possible? Which could be the speed limitations? Can I operate these registers while the timer is counting?
Thank you!
I think there is no simple way to generate this signal by timers. But you can get it easily by XORing SPI CLK and MOSI line.
Sir, that is a very useful solution! Has you tried before? I'm going to try this evening. However, let's complicate it a little bit. I was thinking on PWM cause there is a modulation called VPPM (Variable Pulse Position Modulation), that works exactly the same as the 2-PMM, however the duty cycle is variable. I have an image of this modulation.
Do you think there is an alternative to generate that without BitBanging? Thank you!
I think it can be done. Enable Fast PWM and the OCR interrupt. When in the OCR ISR, set the Normal/Inverse PWM mode for the next cycle. As long as your ISR completes before the timer hits TOP you should be able to change the PWM polarity for the next cycle. You can also change the duty cycle (for VPPM) since Fast PWM modes buffer the OCR changes until the timer overflows to BOTTOM.
If you are going to have 5 time slots per cycle your cycle time will have to be at least five times the maximum latency of your ISR, including being delayed by other interrupts such as Timer0 (millis()) and Serial (if you use Serial). What kind of speed did you hope for?
Thank you @johnwasser! I have achieved a Bitbanging using Timer interruptions and Serial enabled of an ON-OFF Keying (literally ON-OFF) of 140KHz using an Arduino Mega, I was expecting to get similar results and improve it a bit while at the same time changing the modulation scheme to VPPM.
So if I understood clearly, when the timer overflows on TOP, it will change its configuration, so it will buffered from one cycle to the next one. That's cool! Changing the duty cycle is less restrictive cause it is just for setting the brightness of the LED (This is an specific modulation for Optical Communications Systems).
It is possible to use a DMA (Direct Memory Access) to feed the configuration, or a similar way to buffer more than just one state, so I could increase the transmission speed?
Thank you!