Learn how Asynchronous Scheduling Works in C2000 MCUs | Getting Started with C2000 Microcontroller Blockset, Part 8
From the series: Getting Started with C2000 Microcontroller Blockset
Learn how to achieve asynchronous scheduling using hardware interrupts in TI C2000™ MCUs using C2000 Microcontroller Blockset. This step-by-step guide shows how to configure ADC interrupts and observe how scheduling works with the ADC interrupt service routine triggering a function call subsystem in Simulink®.
Published: 13 Jan 2025
Welcome to another video on hardware interrupt. In this video, let's try to create a simple example with a hardware interrupt block and see how the scheduling happens when an interrupt occurs. The hardware setup for this example would be jumper wires are connected between a 3.3 pin and the pin 70 on the launchpad, F28379D.
The pin 70 corresponds to the channel 1 of the ADC module A. And power the launchpad with the help of an USB cable. Having set up the hardware, let's start creating the model. For that, open a blank Simulink model and go to the configuration parameters by pressing Control-E and go to the Hardware Implementation tab to select the hardware board.
In my case, it's TI Delfino F28379D Launchpad and click on OK. Now, your model is configured for your launchpad. After doing that, let's start adding the blocks.
First, let me add a C28x Hardware Interrupt block. So for an interrupt block, there must be a source and an interrupt service routine. For the source, let me add an ADC block and let me add a scope to see the output of the ADC and let me add a function called subsystem.
The function call subsystem acts like an interrupt service routine when connected to an interrupt block. And the blocks inside the subsystem gets executed whenever an interrupt occurs. With that said, let's configure each block.
Double clicking on it opens the block parameter. And let me select the ADC module and the input channel, IN1. Let me check on post interrupt on the end of conversion trigger so that it triggers an interrupt after every conversion. And let the sample time be 0.001. I'll be explaining the block parameters of ADC in detail in another session.
For now, leave other parameters to default and click on OK. So I have configured this ADC block for the channel, IN1. And I have directly connected the 3.3 pin to this ADC.
Moving on to the hardware interrupt block, let me click on Help, and this opens the C28x Hardware Interrupt documentation. Moving on to the PIE and CPU number for the F2837xD, let me find out the CPU number and PIE number for the ADC channel A1. So it's 1 and 1.
Let me enter the CPU number 1 and PIE number 1. For an interrupt, we must have priority higher than the priority of the base task. So any value less than 40 would do good for that. Let it be 30 for now.
Since I have only one interrupt, it isn't going to matter whether it is preemptable or non-preemptable. So I am putting 0 over here. And let me click on OK.
Moving on to the function call subsystem, let me delete these ports as I don't need any input outside the subsystem. And let me add a counter block here and a scope block.
Let the upper limit be 7. So this counter box count from 0 to 7 and then comes back to 0 and again starts counting. And during each function call, that is, for every time when the interrupt is being triggered, the account value gets incremented by 1.
Now, let me run the model in Monitor and Tune mode to see the results in scope. Let me now open the scope block that is connected to the ADC.
Since I have connected a 3.3 volt to the ADC input pin, and as it is a 12-bit ADC, you would be able to find the corresponding 12-bit value 4,095. And since it is a constant value, you see a straight line over here.
Now, let's go on to the function call subsystem, that is, the interrupt service routine. Let me open this code block. Let me zoom the time scale. As you could see, for each trigger from the ADC, the counter value gets incremented by 1. It counts up to 7 and then comes back to 0 and start counting again. And this happens on each interrupt trigger.
Hope you have now understood how to use an interrupt block, add a source block, and create an interrupt service routine for that particular interrupt. Moving on to the second topic in this video that is about scheduling, let me turn on the colors to see various sample rates that are available in this model. As you could see, there are some blocks that are highlighted in red color, which means that these blocks are running at a base rate. Since ADC is configured at a sample time of 0.001, you could see the same over here in the timing legend.
Moving on to the interrupt block, as I have mentioned, interrupt can be from multiple sources. Call can be from multiple different blocks. So it is shown under multi rate. Moving on to the function call subsystem, whenever an interrupt is being triggered, the function call subsystem gets executed. It does not happen periodically as in the case of ADC block.
So it is asynchronous. It is highlighted in purple color. And it is mentioned as synchronous in the timing legend. The key point here is that all the interrupts happen asynchronously.
As a recap, in this video, we have seen how to add and configure an interrupt block and add the associated blocks like source block and an interrupt service routine, that is, a function call subsystem block. And also we have seen how the scheduling happens during the event of an interrupt. Thanks for watching this video.