How to Configure External Interrupts on C2000 MCUs | Getting Started with C2000 Microcontroller Blockset, Part 9
From the series: Getting Started with C2000 Microcontroller Blockset
Learn how to configure C28x hardware interrupts on TI C2000™ MCUs to act on external interrupts. This step-by-step guide shows you how to configure a GPIO pin on a C2000 MCU to service an interrupt service routine on the algorithm model running on a TI C2000 MCU using C2000 Microcontroller Blockset.
Published: 13 Jan 2025
In the previous videos of Hardware Interrupt, we saw what an hardware interrupt is and the block parameter of hardware interrupt for your F28379D launchpad from C2000 microcontroller block set in Simulink. In this video, let's put the hardware interrupt block into action.
Before adding in the blocks and start developing the model, let me press Control-E to configure this model for my hardware board. In this case, it's F28379D launchpad. Let me go to the Hardware Implementation tab and select Delfino F28379D Launchpad and click on OK.
Once you have your board selected, a new Hardware tab would be visible in your Simulink Toolstrip displaying the selected hardware board. Now your model is configured for your Delfino F28379D launchpad. Let me generate a sequence of pulses in one of the GPIO pin, say GPIO0. For that, let me add a pulse generator block and a digital output block.
Double-clicking on the pulse generator opens the block parameter. Let me set the Period to 2 and Pulse Width of 50% so that the generated pulse would be high for 1 second and low for the other 1 second, and a sequence of such pulses would be generated. Since I have connected pulse generator block to the digital output, which is configured for GPIO0, as you could see here, a sequence of pulses would be generated in this GPIO pin.
To view the generated pulses, let me connect the GPIO pin 0 to GPIO pin 1. So let me add a digital read block, and let me add a scope. Since I have an external wire that is connected between GPIO0 and GPIO1 I would be able to see the generated pulse in this scope. Let me configure this for GPIO1 and set the Sample Time to 0.001.
Now let me add a hardware interrupt block. Double-clicking on it opens the block parameter. Clicking on Help opens the documentation of the hardware interrupt. Scrolling down and under the table header of F2837xD the CPU number and PI number for the external interrupt 1 is 1 and 4 respectively, so let me enter the same. So CPU number is 1. PIE number is 4. Let me set the task priority number to 30. Any value less than 40 should do good. And since there is only one interrupt, it does not matter whether it is preemptable or nonpreemptable. So let me keep it nonpreemptable and click on OK.
Now let me add a function called subsystem. When connected to this hardware interrupt block, acts like an interrupt service routine. Let me delete these ports, and let me add a counter block. And let me use a scope to see the result. Double-clicking on this counter block opens the block parameter. Here, the counter counts from 0 to the value that is set in the upper limit. It is 7 here. And the count value increments by 1 every time whenever it receives an interrupt.
Since the updation of the counter block depends upon the hardware interrupt block, hence, the sample time is set to minus 1. Minus 1 means inherited. Usually, we used to set of sample time to a specific value and the block gets updated at that specified time, whereas in case of inherited sample time, the block value gets updated based on the block that is connected to. Here, it depends upon the hardware interrupt block. So let's keep it to minus 1 and click on OK.
Now let me go to the configuration parameter under Target Hardware Resources. Clicking on External Interrupt, you'd be able to see that external interrupt 1 is connected to the input for transfer. And you could see that no GPIO pin has been selected. Now navigating to the Input crossbar and under INPUT4, you can enter the GPIO pin number. Here, let me enter 1 and click on Apply.
Now you will be able to see the GPIO pin that is used for an external interrupt 1. And the external interrupt polarity is falling edge. Let me change it to rising edge so that an interrupt would be generated whenever the GPIO toggles from low to high. Let me click on OK.
Having set the Input crossbar, now let me run the model in the Monitor and Tune mode. Monitor and Tune enables you to tune the model parameters in real time. Whenever you change the parameter value in the model, the modified parameter values are communicated to the target hardware immediately.
And let us see how that is happening. First, let me click on the scope to see the generated pulses. You could see a pulse is generated for a period of 2 seconds and a pulse width of 50%. Let me close this and open the scope. Since, for every 2 seconds, the pulse toggles from low to high, for every 2 seconds, the count value gets incremented. And you could see the same here in this scope.
Now let me go to the pulse generator block and change the period to 4 seconds and click on OK. Here, in this scope, you are able to see that the pulse period is 4 seconds and the pulse stay low for the 2 seconds and stay high for the other 2 seconds with the same 50% pulse width.
Whenever I change the parameter here, it immediately gets reflected in my target hardware, and you could see the same result in the scope over here. And now, when I click on the scope that is connected to the counter block, you would be able to realize that the counter value also increments for every 4 seconds, as you could see it here. Let me stop the simulation.
Having learnt about the implementation of the hardware interrupt, this hardware interrupt is widely used in day-to-day applications, starting from TV remote control to critical application like airbag explosion in a car during an accident. Also, in three-phase motor, hardware interrupt plays a key role in synchronizing the ADC and PWM.
For a proper motor control, the knowledge about the current is essential. The current that is measured with the help of an ADC is used to control the duty cycle of the PWM signal. And at the end of every conversion of the analog current value, an interrupt is generated. And in the interrupt service routine, the duty cycle of the PWM is varied according to the current sensor, and the PWM triggers the start of conversion of the ADC at the mid of every PWM pulse. This makes sure that the current sensor is sampled properly at every instant.
Though there are multiple ways to make sure that the current is measured or sampled properly, using hardware interrupt and synchronizing the ADC and PWM is one of the easiest ways. Now you have got an idea how hardware interrupt is used in various applications and how to implement the same. This concludes the video on hardware interrupt. Thank you.