FlexCase

Analog Input Guide

  • Read voltages of internal states through the ADC inputs
  • Measure controller ground with extended bipolar range

Prerequisites

  • Complete the quick-start guide for a tutorial on connecting and flashing binaries
  • Complete the Simulink guide for building a model into a flashable binary
  • Complete the FreeMASTER guide for viewing MCU variables live. Alternatively, you can use a CAN trace tool to view results if you have successfully read CAN outputs from the MCU
  • Download the latest Simulink sample software (we will use ADC.slx)

Compile and Run the Software Sample

This software sample uses the ADC to assess the power consumption of the FlexCase via the internal voltage and current measurements.

  • Open ADC.slx
  • If you are going to use FreeMASTER to view the results, be sure to change the variable storage types to “Volatile” temporarily
  • Build the model and flash to the MCU

Either through a CAN trace or through FreeMASTER, you should see the battvolt reading the supply voltage (mV), and the cursens reading between 100 and 200, depending on what options your FlexCase is equipped with. The cursens variable reads proportional to the current draw on the DCDC converter. Due to many factors, It has a non-linear relationship to the amperage measured at the external power supply, but can still be used as a heuristic for the power consumption of the FlexCase.

If you have successfully connected to the FlexCase via SSH, you can initiate a disk write test on the MPU to consume more power by running the following command in terminal:

Copy to Clipboard

This will write to temporary storage, and should take approximately 5 seconds to complete. You should see the increase power consumption reflected in the cursens variable.

Additional Information

Most analog reads have a voltage divider that scales down the input voltage to a safe voltage for reading. The factor is 1/12th, so a 36V input will reach the MCU at 3.0V

The included signals that have this voltage divider include

  • All Analog Inputs
  • Supply voltage measurement

The equation to calculate theoretical ticks is based on

which when solved yields

As an example, the theoretical scaling factor for a 12V input can be calculated as:

Resolution of ADC Input Voltage Voltage Divider (1/12th input) Ratiometric Value (3.3V Vref) Read Ticks
8bit = 255 12000 mV 1000 mV 1000/3300

77

10bit = 1023 12000 mV 1000 mV 1000/3300 310
12bit = 4095 12000 mV 1000 mV 1000/3300 1240

However, there are voltage drops along the sensing line and tolerances with the components, so it is always best to calibrate the analog read for your application with a multimeter.

MPU Reads (FlexBench Only)

The analog input is implemented using a SPI-based chip on SPI0, CS1. The single-ended measurement range is 0-36V in 10bit resolution, with the ability for differential modes. Please keep in mind that SPI0 is also used by the MCU, so care must be taken to coordinate the different communication channels. The following python script shows reading of the ADC module channels.

Copy to Clipboard

MCU Read Range Adjustment (Advanced – FlexBench Only)

Using the dip switches on the FlexBench, the voltage dividers on MCU ADC 1-5 can be individually adjusted from the default 0-36V range to either a standard 0-5V range or a 4-20mA range. These options are intended for advanced users. Opening the FlexBench can cause damage, so please proceed with caution.

After removing power for the FlexBench and removing the rubber feet on the bottom of the FlexBench will reveal four M2.5 screws. Removing the screws will reveal the circuit board and dip switches. Each of ADC 1-5 have two switches to configure the measurement range. ADC1-4 switches are located near the power barrel jack (bottom-left corner), and the ADC5 switches are in the bottom-right corner. Each dip switch is labeled with the “ON” setting, and has a marking next to the switch with the functions matching the following table:

10K-Short OFF 10K-Short ON
330-GND OFF 0-36V (default) 0-6V (5V sensors)
330-GND ON 0-15mA (not recommended) 0-20mA (current output sensors)

This feature is only available on older models (FlexCase S or FlexBench 1.1) and is only necessary if you plan to measure negative voltages in your project. Incorrectly connected wires can cause permanent damage to the FlexCase.

Each analog input is equipped with a pullup switch that shifts the measurable voltage range, allowing negative voltages to be read. In this example, the ground voltage will be read with the switch disabled and enabled, by adding the provided prototyping wires to your FlexCase wire harness.

You must remove the secondary lock from the back of the C2 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).

Use the prototyping wires to connect C2-G1 (secondary ground) to C2-K3 (Analog Input 1):

Add the following blocks to the ADC.slx model:

  • Read on ADC1_SE8 (PTB13)
  • Extract lower half
  • Data store and write for a new variable gndread
  • Write of 0 to the PTC9 pin, which is the pullup switch for Analog input 1

If you are using FreeMASTER to view the variables, ensure the storage class of gndread is volatile. If you are using CAN, you can add the variable to the packing of the CAN message.

Re-build and flash the model to the FlexCase. The analog input should read zero, which corresponds to the ground voltage.

Now, write a 1 to the PTC9 digital output, and re-flash the model. If you are using the provided 12V supply, the analog input should now be reading approximately 500. At 12v, the voltage range is shifted by approximately -5V, so a reading of 0 corresponds to -5V, and a reading of 500 corresponds to a reading of 0V.