How to Configure C28x Hardware Interrupts on C2000 MCUs | Getting Started with C2000 Microcontroller Blockset, Part 7
From the series: Getting Started with C2000 Microcontroller Blockset
Learn how to configure and use the C28x Hardware Interrupt block from C2000™ Microcontroller Blockset in Simulink®. Learn about CPU numbers, PIE numbers, task priority management, and the implementation of preemptive multitasking in C2000 MCUs and how they can be configured from the Simulink environment.
Published: 13 Jan 2025
Welcome to the video on hardware interrupt. In the previous video, we saw what an hardware interrupt is. In this video, let's see how to configure the hardware interrupt block.
To begin, go to the Library Browser. And under C2000 Microcontroller Blockset, expanding on Scheduling, you would be able to find the C28x Hardware Interrupt block. Drag in and bring in to the canvas.
Before getting started, let me quickly explain the interrupt architecture. As you know, the Delfino Launchpad has two cores, that is, CPU1 and CPU2. And each CPU has 14 interrupt lines called CPU interrupt lines, out of which the two interrupt lines are directly connected to the timer 1 module and timer 2 module.
The remaining 12 interrupt lines comes out of a peripheral interrupt expansion module. This module is responsible for the CPU handling large number of interrupts. Let's see how this module works.
So this module has 12 peripheral interrupt expansion group from which the 12 interrupt line comes out. And each group, again, has 16 peripheral interrupt expansion lines. Since there are 12 such group and each having 16 peripheral interrupt expansion lines, these 16 lines are multiplexed into each of the 12 CPU interrupt lines.
Doing a quick math, 16 into 12 is 192. So there are 192 peripheral interrupts that are being supported by CPU. And there are two such cores. Before wrapping up the architecture, I just want to state two key points over here. One is that for each interrupt there is an associated peripheral interrupt line number and the CPU interrupt line number.
And the second key point is that the peripheral interrupt number varies from 1 to 16, and the CPU number varies from 1 to 12, leaving out 13 and 14 because Simulink C2000 Microcontroller Blockset does not support for timer 1 and timer 2, as of now. But that's it. Let's look into the block parameter of hardware interrupt.
Double clicking on it opens the block parameter. And there are parameters like CPU interrupt number, PIE interrupt, Simulink task priority, and preemption flags. So the CPU interrupt number and PIE interrupt number together constitute for a single interrupt.
To get the values of these parameters, you can click on Help to open the documentation of C28x Hardware Interrupt. Scrolling down and under the table header PIE and CPU interrupt number for F2837xD, you'll be able to find the CPU and PIE number for the corresponding interrupt.
Let me have the block parameter by side. So if you want to configure the interrupt block for an ADC interrupt for the channel A1, you have to enter CPU number 1 over here and PIE number 1 over here. In the previous video, I have said interrupts can be from multiple sources. So if you want to configure the same block to trigger interrupt from multiple sources, you can enter the CPU number and PIE number in a vector format.
Say, for example, you have already configured it for ADC channel A1, and if you want to configure for an ePWM interrupt, ePWM1 interrupt, in that case, the CPU number is 3 and PIE number is 1. And you would be entering over here, in this way, CPU number 3 and PIE number 1 but in a vector format.
Now this block is configured for two interrupts. One is ADC interrupt, and the other is ePWM interrupt. Moving on to the next parameter, Simulink task priority, in one of the GPIO video, I have explained about the base rate. Base rate is the maximum rate at which you make the microcontroller to run your task.
And there is no point in making the microcontroller to run at a faster rate without having any task at that particular rate. So make sure that you always have a task running at a base rate. And how to do that I have explained in the previous GPIO video. Please see the video if you haven't seen that video yet.
So the base rate has a priority of 40. Any value less than 40 makes the task a higher priority. So if you want to stop executing the main task and start executing the interrupt service routine, then the priority must obviously be high.
To make the priority high, you have to enter a value less than 40. Lower the value, higher is the priority. That is the concept. Here, it is 30 and 26. So CPU number 1, PIE number 1, corresponds to the ADC interrupt. And that has a priority value of 30.
Similarly, CPU number 3 and PIE number 1 corresponds to ePWM interrupt that has a priority value of 26. Comparing 30 and 26, 26 is a lower value. That is, ePWM interrupt has a higher priority when compared to ADC interrupt.
This is all about Simulink task priority. Moving on to the next parameter, preemption flag. Preemptable means interruptible. Non-preemptable means non-interruptible. When I put one over here for the ADC interrupt, it means that ADC interrupt can again be interrupted by a higher priority task. It is like a nested interrupt, interrupt within an interrupt.
Here, ePWM has a higher priority than ADC interrupt. So when an ADC interrupt service routine is being executed and an ePWM interrupt arrives, in that case, it suspends the execution of the ADC interrupt and start executing the ePWM's interrupt service routine. And once the interrupt service routine of an ePWM has been executed, it returned back and continues execution of the ADC's interrupt service routine.
To avoid interruption, you can enter the value 0 so that higher priority task does not interrupt the current execution of the interrupt service routine. And it waits till the ADC interrupt service routine is being executed to start execution of the PWM interrupt service routine. And this is all about preemption.
To move on to the final parameter, that is, enable simulation input, you can simply check on here. And when you click on OK you'd be able to see the input port for this block so that you can connect an input and output blocks and run a quick simulation to check the functionality of this hardware interrupt block. That's all about the block parameters of hardware interrupt. Thanks for watching this video.