FlexCase S
Digital I/O Example
This guide is more advanced than the basic tutorials, so please contact us if you have additional questions before proceeding. Improperly connected I/O can cause damage on FCS 1.2 and lower.
The guide for FCS1.2 and lower can be followed for FCS 1.3 and higher, with the following important differences:
- The outputs have protection build in which prevents damage even when abused. Less caustion is required as the system not allow itself to be damaged.
- The recommended outputs are not populated by default on the newest revision. Please change them for one of the populated circuits on DO 1-4
- High side drives are active high instead of the previous active low.
Prerequisites
- Complete the quick start guide for a tutorial on connecting to the FlexCase and flashing binaries
- Complete the Simulink guide for building a model into a binary
- Download and unzip the latest Simulink samples (we will use DIO.slx)
Connect Digital Inputs to Outputs
You must remove the secondary lock from the back of the connector before you can add terminals. There should be an audible click once the terminal is properly seated, and the secondary lock will only re-insert properly if all terminals are secure (See the official guide for how to add and remove terminals, or see our modification guide).
Connect the following pins on the C2 connector:
- C2-C3 to C2-F1
- C3 will be configured as output PWM
- F1 will be configured as input PWM
- C2-B1 to C2-D3
- B1 will be configured as digital out
- D3 will be configured as digital in
Simulink Model
Open the sample model DIO.slx. Using the jumper connections from the previous step, this model exhibits the following behavior:
- Generates a boolean signal that toggles every two seconds
- Uses the boolean to switch between two duty cycles on a low-side PWM output (C3)
- Measures the duty cycle of the above output with a PWM input (F1)
- Uses the measured duty cycle to determine the timing to toggle a digital output (B1)
- Measures the digital output with a digital input (D3)
- Uses the digital input to drive the FlexCase diagnostic buzzer
If you are using 1.2+ hardware, you must also add a write of 1 to Digital Output Enable and Digital Input Enable in the “Run Once at Startup” subsystem for the tutorial to function normally. This will pull the digital inputs high by default, and the outputs in the above diagram will pull those pins to ground when active.
After verifying the above components, build and flash the model to the FlexCase microcontroller. Upon the completed flash, you will hear the diagnostic buzzer beeping in rapid succession for two seconds, followed by beeping at half the rate for another two seconds, and then repeat.
Additional Information on Model Components
It is important to understand how the digital outputs are connected to avoid destroying the output circuit. Before modifying this sample model, consult the additional information sections below. Activating the high-side and low-side simultaneously will cause a dead short.
FlexCase I/O Pins
Each digital output pin on the FlexCase is configurable for high-side or low-side operation.
In this sample, the outputs are connected low-side for safety, and to avoid the extra wiring for high-side. In low-side operation, when the output is set to high, the pin is connected to ground.
The input pins are pulled up internally, so that they will read high when the low-side output pin is not active, and read low (ground) when the output pin is active.
PWM Output (FTM PWM Config Block)
Warning: Simulink will assign default pin mappings when an FTM block is created, which may not be compatible or cause damage to the board. It is essential to review the settings on the block before building your model.
- CH6 duty cycle should be set to 0 and polarity set to Active Low to not use the high-side output. Initial duty cycle should also be set to 0. Make sure the internal pin assignment matches the FlexCase datasheet. When using low-side only, Simulink automatically assigns a pin to the high-side, so extra are must be taken.
- CH7 polarity should be set to Active High (default for low-side), so the duty cycle corresponds to the proportion of the cycle that output is grounded
- The channel pairs must be set to Independent to keep the high-side output off
- The output pins are set to match the naming on the FlexCase pinout
- In this case, DO15 EXT uses PTC1 for its low-side operation
- If you are driving outputs high-side, the low-side (odd-numbered) channels should be set to None for added safety
PWM Input (FTM Dual Edge Capture Block)
- This block only measures even channel numbers, set to PTC6/FTM3_CH2 in this example
- The measured time is the number of cycles of the 80 MHz clock, output as a 16-bit integer
- The prescaler should be set so that the measurement does not overflow a 16-bit counter
- For this example, the output frequency being measured (2442 Hz) and input prescaler of 128 are chosen so that the measured values are limited to the first 8 bits of the counter
- Measurement mode is set to negative pulse, which measures the time that the pin is grounded
- There will be a small offset in the timer value due to the time it takes for the input to be pulled up. This offset will vary depending on how the output circuit is configured.
Counter Logic
This control logic converts the duty cycle received into a pulsed signal for the digital output. The logic is similar to how an actual PWM signal is generated:
- The variables are limited to 8-bit for simplicity only
- The rolling_count increases each cycle until it rolls over
- When the value of the counter is above the threshold, the output is activated
- The rate of the rolling_count is determined by the input, which determines the “frequency” of the Buzzer beeps
- The threshold determines how long the Buzzer will stay on for, similar to the “duty cycle”
Digital Output (GPO Write)
In this example, the GPIO pin is configured for low-side operation. Similar to the PWM I/O in this example, the input will read a low voltage when the output is set to True.
- Pin is set to PTB5 to match the low-side of DO14 EXT on the FlexCase pinout
- Initial value is Low (not active)
- Drive strength Low is sufficient to activate the pin
Digital Input (GPI Read)
Any of the FlexCase digital inputs can be used in this mode, provided they are not already being used for a PWM signal read or quadrature decoder.
- The input pin is set to PTD11 to match one of the FlexCase digital inputs (QUAD2 A EXT)
- The pin is pulled up internally, so no pull resistor select should be set to None
Buzzer
In other software templates, the buzzer logic is usually kept in a predefined block and controlled with the BuzzerBool variable. Since the buzzer is driven by a PWM output, it is especially relevant to this guide and is therefore placed in the main area of the simulink model.
- When it is on, the buzzer should be driven at 50%, since the piezo-electric element vibrates best with an even waveform
- The buzzer can only be driven low-side with PTD5. The high-side channel FTM_CH2 pin should be set to PTE4 so that PTD12 is still available to be used as a digital input
- The buzzer can be driven between 2-8 KHz, and 4KHz is the default
Additional Information About Digital Inputs
The digital inputs can be used for quadrature encoders or simply as regular digital inputs.
For FCS1.1, FCB1.1, and older device versions, all digital inputs come with a default hardware pull-up to the supply voltage. The digital input (DI) pulls can be modified to either 5V pull up or a pull-down configuration.
In contrast, starting from FCS1.2, FCB1.2, FCE2.0, FCG1.0, and any newer devices, we’ve incorporated a software-controllable switch for enabling pull-up on digital inputs. In that case, you will need to set the MCU Digital Input Pull Up Enable high to activate the pull up. This feature provides users with enhanced control over the pull-up functionality.
When the digital input (DI) channel is pulled up, either through hardware configuration or by utilizing the software-controllable switch, it will register as ‘high’ for any voltage greater than 2V or in an unconnected state. Conversely, it will register as ‘low’ for connections with a voltage less than 2V. If the digital input (DI) is pulled down, either by software or hardware configuration:
- A supplied voltage greater than 2V will result in a high reading.
- You can apply a voltage up to the maximum voltage on the ECU (36V)
Additional Information About Digital Outputs
The diagram below shows the configuration for Digital Output Bank 1. Banks 2 and 3 are nearly identical in implementation.
Effectively, each output is configured as an H-bridge circuit, with the MCU having the ability to control the high and low side independently.
Our recommendation for integration is as follows:
- Whenever possible, low side drive is recommended.
- If general high side drive is required, use outputs 1 through 10
- Only use outputs 11 through 16 for high side if high side PWM is required. These outputs have the known high side issue and can be damaged if not integrated with care.
Configuration and Use
- Low side drive is active high.
- High side drive is active low. You must supply a voltage on the high side supply for high side drive to function
- IF HIGH AND LOW SIDE DRIVE ARE ACTIVE AT THE SAME TIME THE OUTPUT WILL BE DESTROYED.
Permissible output pin states are shown in the table below, using Digital Output 1 (DO1 EXT) as an example.
Low Side Setpoint | ||||
---|---|---|---|---|
PTD16 Unconfigured | PTD16 Low | PTD16 High | ||
PTD15 Unconfigured | Open Circuit. No connection | Open Circuit. No connection | Output connected to GND | |
High Side Setpoint | PTD15 Low | Output connected to +VCC | Output connected to +VCC | DANGER! CAN DAMAGE BOARD! |
PTD15 High | Open Circuit. No connection | Open Circuit. No connection | Output connected to GND |
Any voltage (within specified limits) can be supplied on the high side supply.
- The 5V output could be fed into the high side supply to make a 5V digital output
- A battery supply could be fed into the supply