Hi,
I'd like to use a Teensy 4.1 to implement the XY2-100 laser scanning control protocol. The protocol is a fairly simple serial protocol with the following signals:
CLOCK: ~10 MHz, 50% duty cycle
SYNC: Pulse every 20 ticks of CLOCK.
X DATA, Y DATA: Transmits a 16-bit data frame in sync with CLOCK, and triggered by edges of SYNC.
See http://www.alaser.com.tw/db/upload/webdata4/6alaser_201412422541519318.pdf for a timing diagram, etc.
An existing project to do this exists for the 3.2 (https://github.com/Tuet/XY2_100), but the code uses timers that do not exist on the 4.1 -- but at least that means it's feasible.
I've got a couple questions:
1. How do I properly generate a ~10 MHz square wave? Until now I've been doing an analogWrite at a 50% duty PWM duty cycle and setting the frequency via analogWriteFrequency, but this seems hacky. Surely there must be a better way with a hardware timer or similar? (If a hardware timer is the best option, is there a good source of examples/documentation apart from the SoC datasheet?)
2. How do I trigger actions in sync with the CLOCK or SYNC signals? Looping the CLOCK signal back to another input pin and setting a pin change interrupt seems like an option, but is there a better way?
3. The existing protocol implementation for the Teensy 3.2 uses the DMAChannel library for signal generation. I don't mind reading the source code for that, but is there supplemental documentation/examples somewhere?
- Franklin
I'd like to use a Teensy 4.1 to implement the XY2-100 laser scanning control protocol. The protocol is a fairly simple serial protocol with the following signals:
CLOCK: ~10 MHz, 50% duty cycle
SYNC: Pulse every 20 ticks of CLOCK.
X DATA, Y DATA: Transmits a 16-bit data frame in sync with CLOCK, and triggered by edges of SYNC.
See http://www.alaser.com.tw/db/upload/webdata4/6alaser_201412422541519318.pdf for a timing diagram, etc.
An existing project to do this exists for the 3.2 (https://github.com/Tuet/XY2_100), but the code uses timers that do not exist on the 4.1 -- but at least that means it's feasible.
I've got a couple questions:
1. How do I properly generate a ~10 MHz square wave? Until now I've been doing an analogWrite at a 50% duty PWM duty cycle and setting the frequency via analogWriteFrequency, but this seems hacky. Surely there must be a better way with a hardware timer or similar? (If a hardware timer is the best option, is there a good source of examples/documentation apart from the SoC datasheet?)
2. How do I trigger actions in sync with the CLOCK or SYNC signals? Looping the CLOCK signal back to another input pin and setting a pin change interrupt seems like an option, but is there a better way?
3. The existing protocol implementation for the Teensy 3.2 uses the DMAChannel library for signal generation. I don't mind reading the source code for that, but is there supplemental documentation/examples somewhere?
- Franklin