XMC 4700 Pi 16 channel multiplexer controller - lorenzo-campana/bpm GitHub Wiki
This is a guide on how to program a XMC 4700 Relax Kit to drive a minicircuits USB / TTL RF SP16T Switch, a 16 channel multiplexer. The main functionalities of the project are the same as the Arduino project. The main difference is the use of the CCU4 timer function that the XMC provides. The final result is far better, with no jitter in the output signal.
The entire DAVE 4.4.2 project can be downloaded here and can be imported in DAVE (File -> Import... -> DAVE Project -> Select Archive File). The commented main.c
file can be found here.
Overview
The program is controlled through USB communication. All the parameter can be changed by sending an upper case letter followed by a space and an integer number. The letters for the parameter can be modified in the .proto
file in EPICS.
The default value of the letter for the parameters are:
- 'T' for
mode_select
: select switching mode- AUTO mode: automatic switch between all the selected channels; the switching starts after receiving an external trigger signal.
- MANUAL mode: the output is set on only one selected channel.
- 'D' for
dwell_time
: how long each channel is set as output in automatic mode. - 'H' for
channel_select
: channel selection for MANUAL mode; accepts an integer from 0 (all channel disconnected) to 16. - 'M' for
channel_mask
: channels selection for automatic mode; accept a number between 1 and 65535. To select the channels you want, convert a 16 bit binary number to decimal. eg 65535 = 1111111111111111 means that all channel are selected. - 'C' for
cycles
: how many times the channels selected for AUTO mode are set as output. - 'Y' for
global_delay
: how long the program waits befor start switching after receiving the external trigger signal in AUTO mode.
The code for the communication with the pi is inside an infinite loop in the main application; it waits for one or more bytes to come through the serial and then update the corresponding parameter. When you change the channel_select
parameter and you are in MANUAL mode, the program will also change the output immediately.
AUTO mode is instead implemented using interrupts. The program uses two different timer, both from the same CCU4 APP, connected to 2 time event interrupt. The timers are concatenated and they start when an external trigger signal connected to a pin interrupt arrives. We can see the timer structure in the following image:
Step by step guide
The project will use various DAVE APP:
- USBD_VCOM for the USB communication
- DIGITAL_IO for signal output
- TIMER
- INTERRUPT
USB communication
Let's start with the easiest APP. Add the USBD_VCOM APP from the browser. DAVE will automatically add a USBD APP and connect it to the clock APP. The USB doesn't need any configuration, it's ready to use and you don't even need to wire any pin to it.
Digital output
For our project we will need 5 DIGITAL_IO APP; add them and rename them D0 to D4. Configure them all the same way as you can see in the following image:
Now right click on the app and click on "Manual Pin Allocator". Select the desired output pin for each of the DIGITAL_IO APP.
Interrupt
Add two INTERRUPT APP to the project. Rename one to "interrupt_dwell_time" and the other to "interrupt_global_delay".
Double click on interrupt_global_delay and change the setting in this way:
Double click on interrupt_dwell_time and change the setting in this way:
Timer
Add two TIMER APP. Rename one "timer_dwel_time" and the other "timer_global_delay". For each of them in the "General Setting" tab uncheck the "Start after initialization" option, while in the "Event Setting" tab check the "Time interval event" option. Now right click on one of them and select "HW Signal Connections". In the connections windows connect the timer with its corresponding interrupt, as you can see in the following images:
Then add a PIN_INTERRUPT APP. Double click on it and modify the "General Setting" as you can see in the following image:
Finally connect this last interrupt to a pin using the "Manual Pin Allocator".
Upload and use
Generate the code and open the main.c
. Delete everything and copy this code. Before building the project, make sure the "APP Dependency" tab looks like this:
Connect both the debugger and the main usb port to the pc and upload the code using the debugger window. We can now test the switch using Hterm to send command to the XMC 4700.