How to Work with ADCs on C2000 MCUs | Getting Started with C2000 Microcontroller Blockset, Part 10
From the series: Getting Started with C2000 Microcontroller Blockset
Follow this step-by-step guide video on how to design a model in Simulink® using the analog input ports on a TI C2000™ MCU F28379D LaunchPad™ hardware board using C2000 Microcontoller Blockset. Details on how the ADC module available in C28x C2000 MCUs works are discussed.
Published: 13 Jan 2025
Welcome to another interesting video in this series. Have you ever wondered how the tire pressure monitoring system or the temperature sensor in your AC or thermostat works? The one thing that is behind all these devices is none other than the analog to digital converter.
The analog to digital converter bridges between the physical world and the digital world. The ADC measures physical parameters, like temperature, pressure, altitude, touch, in terms of voltage and converts them into digital values of zeros and ones, which the microcontroller further process it.
In today's video, we are going to see about the ADC present on the F28379D Launchpad. To begin, let me double click on the canvas and type in ADC and select the ADC block under the family F2837xD from C2000 Microcontroller Blockset. Double clicking on it opens the block parameter.
Before getting started with the block parameters, let me quickly explain the key specification and architecture of the ADC. There are four analog to digital converter present in the launchpad, ADC_A, B, C, and D. Since each modules are identical to each other, let's take a look into any one of the module.
Let's get started with the key specification. The ADC operates with a reference voltage of 3.3 volt. The resolution for the ADC for the single-ended input is 12-bit. And for the differential input is 16-bit.
ADC takes some amount of time to convert the analog value into a digital value. And the conversion time for 12-bit mode is 10.5 ADC clock cycle. And for 16-bit mode, it is 29.5 ADC clock cycle.
So what is ADC clock cycle? The microcontroller runs at a clock frequency of 200 megahertz. And each peripheral runs at its own peripheral clock by deriving from this 200 megahertz. The min-max range of the ADC clock is 5 to 15 megahertz.
Moving on to the next specification, which is about the sampling rate, the maximum sampling rate for 12-bit mode is 3.5 megasamples per second and for 16-bit mode is 1.1 megasamples per second. Since there are four modules, so 3.5 into 4 is 14 megasamples per second is the maximum throughput for 12-bit mode. And 4.4 megasamples per second is the maximum throughput for 16-bit mode.
This wraps up the key specifications of ADC. Now, let's move on to the architecture. Each ADC module has a single sample and hold circuit and a SAR type-- that is the Successive Approximation Register type converter. There are 16 input channels starting from IN0 to IN15. And these input channels are given to the channel select.
In single-ended input, only one channel is being selected by the channel select. And this channel is measured against the ground voltage by the sample and hold circuit and then given to the converter, whereas, in case of differential input, a pair of channels are being selected by the channel select. And the difference of the signal is measured by the sample and hold circuit, which is given to the converter. In most cases, differential input would be super useful, which is used to eliminate noise and other electromagnetic interferences.
With this said, let's get back to the block parameters. And the first parameter is about selecting the ADC module. And you can choose one among the four modules.
Having selected the ADC module, the next parameter is the ADC resolution. You can either choose 12-bit for single-ended input or 16-bit resolution for differential input. When you choose a 12-bit resolution and click on the input channel, you would be able to select one among the 16 available input channels, that is, when you select 16-bit resolution, you'd be able to select a pair of conversion channels.
With these parameter set and leaving other parameters to default and by clicking on OK, you should be able to see the converted digital output using a scope or a display. The converted output would be ranging from 0 to 4,095, in case of single-ended input. Or it would be in the range of 0 to 65,535, in case of differential input.
Before looking at the next parameter, SOC trigger number, let us see more about the ADC's functionality. The ADC can perform a sequential conversion or simultaneous conversion. In sequential conversion, the input channels are converted sequentially. Since there is only one sample and hold circuit, a simultaneous conversion is not possible with the help of one module.
So for simultaneous conversion to happen, two or more modules are required. Here, input channel 2 of the ADC module A and the input channel 0 of the ADC Module B can be converted simultaneously, whereas the input channel 0 and the input channel 2 of the same module cannot be converted. Simultaneously. But I have explained this considering the single-ended input. And the same is applicable to the differential input as well.
With that said, let us see more about the sequential conversion and learn more about the scheduling. In sequential conversion, the scheduling is achieved through the SOC trigger number. And there are 16 SOC numbers starting from SOC0 SOC15.
These SOCs have the same priority and operate in a Round-robin fashion. And the Round-robin pointer initially points to SOC0. So the input channel configured for SOC0 would be converted first. And then the input channel configured for SOC1 would be converted. And it keeps continuing until the channel configured for SOC15 is being converted. And then it starts again with SOC0.
Moving on to the next parameter, which is the acquisition window duration, the ADC module has a sample and hold circuit and a converter circuit. The switch that is present in the sample and hold circuit is used to acquire the input signal. And this switching frequency can be controlled with the help of a 9-bit register value.
Depending upon the characteristic of your input signal, you can configure this switching frequency with the help of the formula that is given. But the minimum acquisition window duration should be 75 nanoseconds for 12-bit and 320 nanoseconds for 16-bit, this for a default SYSCLCKOUT of 200, that is, 5 nanoseconds.
The minimum ACQPS, that is, the acquisition window, would be 14 for 12-bit and 63 for 16-bit. But the default value is 15. Though the default value works best for most of the application, you can still fine tune the acquisition window duration, considering the input signals source impedance. Coming back to the block parameters, so you can enter any value ranging from 0 to 511, in this acquisition window dialog box.
Moving on to the next parameter, which is the SOC trigger source-- the ADC module requires a trigger to start the conversion. And the trigger can be from multiple sources. It can be either software triggered, or it can be through other peripherals like PWM, ADC, and external interrupt.
When the module is configured for software trigger, the conversion happens immediately, whereas, in case of other peripherals, like PWM, ADC, and external interrupt, these peripherals generate an interrupt on occurrence of an event. And this interrupt is used as a trigger to start the conversion of the selected input channel.
So here in the SOC trigger source, since timer 0 is used for scheduling and the support for timer 1 and timer 2 is not available in Simulink as of now, leaving the timer interrupt, other trigger sources like trigger via software or external interrupt or trigger via any of the ePWM modules can be used.
Upon receiving a trigger, the SOC makes sure that the specified input channel is being sampled at the specified acquisition window duration. And there are 16 such SOC config register sets. Say, for example, for the module A, if SOC0 is configured for input channel 1, ePWM as the trigger source, and 80 nanosecond as the acquisition window duration-- and similarly, SOC15 is configured for input channel 0, external interrupt as the trigger source, and 90 nanoseconds as the acquisition window duration.
And if the ADC module A receives the ePWM trigger and the external interrupt at the same time, then input channel 1, which is configured for SOC0, would be converted first. And then, the input channel 0, which is configured for SOC15, would be converted.
And this is all about SOC. So to summarize, SOC is not only used for scheduling, but it is a configuration register set which is used to configure the input channel, select acquisition window duration, and the trigger source. This is all about the scheduling in the sequential conversion.
Now, let's move on to the simultaneous conversion. In simultaneous conversion, as I had said previously, there must be two or more modules for a simultaneous conversion to happen. And to start the conversion simultaneously, there must be a common trigger source.
In order to have a synchronous conversion, you can set the same acquisition window duration in both the modules. And that's about the simultaneous conversion.
Moving on to the next parameter, which is ADC interrupt, an interrupt can be generated at the end of every conversion, which can, again, be used as a trigger to start the conversion. By default, no interrupt is generated. And you can select ADC interrupt 1 or ADC interrupt 2. Let me choose ADC interrupt 1 for now. So this parameter is dependent on this post interrupt at the end of conversion trigger. So let me check that.
Moving on to the next parameter, which is the sample time, that is the block sample time. For every 0.001 second, the block updates the output. Moving on to the next parameter, which is the data type, the converted digital output can be stored in the following data type. And you can choose any data type from double to 32-bit unsigned integer.
Moving on to the next parameter, which is the interrupt selection, so when you check on this post interrupt at end of conversion trigger, you'd be able to find this interrupt selection. And apart from the two interrupt which can be used as a trigger to start the conversion, there are two more interrupts available which can be used to solve the interrupt service routine. So if I am choosing the same ADC interrupt 1 over here, again, I can use the same interrupt to trigger the conversion as well as to serve another interrupt service routine.
And again, this parameter is dependent on next parameter which is ADC interrupt 1 in continuous mode. When I check on this, microcontroller doesn't wait for any acknowledgment after executing the interrupt service routine. It keeps serving the interrupt service routine. Let me click on OK. And this is all about the ADC's block parameter.
But there are two places where the ADC can be configured. One is the block parameter, which we have seen now. And the other one is at configuration parameters. By pressing Control-E, you can open the configuration parameters. And by selecting the hardware board to F28379D Launchpad, in the Hardware implementation tab, you'd be able to find target hardware resources for this particular launchpad.
Since there are four ADC modules, you would be able to find a separate tab for each module. And since all the modules are identical, you would be able to find all the parameters identical to. And for this module, global parameters of the peripherals can be configured over here.
Moving on to the first parameter, which is the CPU core select, by default, it is auto. The Simulink automatically decides which CPU to control this particular ADC module. And mostly, it would be the processing unit that is selected over here. But you can directly specify whether you want to control the ADC module by CPU1 or CPU2, by selecting over here.
Moving on to the next parameter, which is the ADC clock prescaler, I have mentioned in the previous video that the launchpad has a clock frequency of 200 megahertz. And you can see that in this clocking. And the achievable size clock out in megahertz is 200.
Since each peripheral runs at its own clock, you can change the peripheral clock by selecting the desired prescaler so that the ADC clock lies in the range of 5 to 15 megahertz. By default, it is SYSCLKOUT by 5, which is 200 divided by 540.
And moving on to the next parameter, which is the offset, if you give 0 volt in the input side, you must be able to see 0 volt in the output 2. But if the ADC gives a 1 volt in the output, then there is an offset. And you have to calibrate that by providing minus 1 in this offset.
You can either specify an offset value, or you can load the OFFTRIM register's value, where the OFFTRIM holds the factory-calibrated error correction value. And this offset value is loaded every time during the booting of the microcontroller.
The next parameter is the interrupt pulse control. And here you have two options. One is the late interrupt pulse. And the other one is the early interrupt pulse. Late interrupt pulse is interrupt that is generated after end of conversion, whereas the early interrupt pulse is the interrupt generated at the start of conversion. That is once the signal is sampled.
Moving on to the next parameter, which is SOC priority-- so all SOCs have equal priority. And they operate in a Round-robin fashion. And this is the default one. But you can change the priority of the SOC by selecting the range of SOCs over here. Say if I choose SOC0 to 2, then any block configured with SCO0, 1, or 2 would be converted first than the blocks configured with any other SOCs.
Moving on to the next parameter, which is ADCExternalSOC Input X-BAR, here all the GPIO pins are connected to the INPUT5 crossbar. You can go to the input crossbar and under INPUT5 pin assignment, you can mention the GPIO pin.
Say, for example, if I mention the pin 45 and click on Apply, you'd be able to see that an external interrupt can be triggered via this GPIO pin 45. And this is all about the ADC's configuration parameters. Similarly, you can configure these parameters for other modules too.
To summarize, in this video, we saw about the ADC's key specification architecture functionality along with the ADC's block parameter and configuration parameter for F28379D Launchpad from Simulink C2000 Microcontroller Blockset. Thanks for watching this video.