Another demo that I saw while at the Freescale Tech Day was also pretty simple, but already moving a step beyond the traditional Arduino examples. It's just blinking a LED, but rather than the "brute force" approach of switching the pin then forcing a wait before switching it again (the algorithm in the classic Arduino "blink" example), this one is a bit smarter and uses a timer interrupt. Sure, you can use timers and interrupts on an AVR, but it's telling that this is considered an advanced feature.
I will say at this point, though, that I am becoming a bit concerned that the idea of "Processor Expert" might be missing something. It's obvious that the software understands pretty much everything about the abilities, configuration and use of Freescale's MCU chips, and provides property-style inspectors for every aspect, but it also seems to require users to know the ins and outs to a great level of detail in order to use it. Naively, I was hoping for something a bit more high level, perhaps with the ability to create, share, and use plugins for common tasks (driving a pin using a timer, reading or writing values using DMA, and so on) which gather together the required settings in one place.
Anyway, on to the steps to blink that LED.
I shall start from where I left off last time, with a LED attached to a named output pin, and the ability to switch it "manually" using the debugger.
Enable a function to toggle the I/O pin
- Double-click the BitIO component in the Components panel to open its Component Inspector
- Click the "Methods" tab to show the available methods
- Look down the list for "NegVal" and set it to "generate code"
- On the top "Project" menu, click "Generate Processor Expert Code"
Set up a repeating timer in Processor Expert
- In the Component Library find "TimerInt" and drag it to the Components list
- Double-click the new TimerInt component to open its inspector
- Click the "..." button to bring up the settings dialog and enter 500
- Click "OK" and see that the Interrupt Period is now set to 500ms
Use the timer to toggle the LED every half second
- Expand "Sources" in the Project Explorer panel
- Double-click Events.c to open it in the editor
- Look down for
- Add a a call to toggle the LED where it says "Write your code here ...":
- Save all your changes (Ctrl-S or click the "Floppy Disc" icon at the top left) and re-build the project using the "hammer" icon
Now you should be able to re-run the debugger. Clear any breakpoints and click the "play forward" icon to see the LED toggle every 500ms.