When Jan Cumps introduced us to the PID library (link below) I said I'd have a go with it, since I had a TI evaluation board (an EK-TMC4C123GXL
with a Tiva TM4C123G on it), wanted to learn a bit about ARM coding, and thought that running a control system with a processor in the
loop sounded interesting and a bit of a challenge, but it's taken me a while to get started, what with the transistor blogging and everything.
MSP432 and TI-RTOS: PID Library Part 1 - Intro
First aim is to get the board doing something.
After a lot of messing around, I got Code Composer Studio installed and doing things, and found some example code to toggle
an IO pin.
Here's the guts of the program, which is a shameless copy of one of the examples I found except that I moved the ouput to PA2 (the pin
the example was toggling doesn't seem to be on the board I've got) and I dropped the delays (who needs delay when you do your
debugging with a scope).
//***************************************************************************** // // Toggle a GPIO. // //***************************************************************************** int main(void) { // // Enable the GPIO module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlDelay(1); // // Configure PA2 as an output. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2); // // Loop forever. // while(1) { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_PIN_2); ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, 0); } }
After I figured out how to get a release build rather than the debug one that it seems to default to (it's the hammer symbol
on the bar, in case it's not obvious - it wasn't obvious to me) and worked out that I needed to use a separate program, LM
Flash Programmer, to program the board, I was there.
Here's the waveform it generates.
Yikes, I'm now an ARM programmer (sort of). Don't know why it's so slow. Either the processor clock isn't set up right or the
library functions are slow and/or don't get optimised.
Next task is to puzzle out how to set up the PWM.
I've found some TI example code (reload_interrupt.c) that also runs an interrupt to change the on time in steps.
One snag is that the first time I tried it the interrupt didn't do anything - I just had a static PWM waveform without any
movement. After rereading the example source, I caught the warning note pointing out that the interrupt needed to appear in
the vector table and, after a bit of head scratching and puzzlement, realised that the table was in the startup_css.c file
that forms part of the project and then that the function address needed to be declared as an extern. Now it works.
(Stop laughing all you expert programmers or I'll make you design some hardware.)
The yellow trace is the PWM; period is 256 x 62.5nS, giving a frequency of 62.5kHz. The interrupt steps the on time in
increments of 16, from 16 to 192. The trace shows the accumulation.
The blue trace is an IO pin that goes high when it enters the interrupt and low at the end. That was to give me confidence in
the interrupt process and an idea of the time being used.
Part 2 will be the design and build of the hardware side of things.
Top Comments