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:
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.
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) |