So i made this valentine twinkle board, using the mkl05z freescale mcu. The board is fairly simple with 20 LEDs, connected in pairs each pair having two LEDs reverse biased to each other. all pairs are then tied to a row driver. I use PORT B, PIN 0 for the row driver, and PINs 1 to 10 for the columns, each driving a pair of LEDs. then i have 5 lines connecting to the SWD debugger: 3V3(VCC), SWDIO, GND, RESET,CLK. These pins allow for powering the board as well as flashing the firmware.
I tried to use my usual opensource setup of GNUARM toolchain arm-none-eabi-gdb and OpenOCD but… I could not get OpenOCD to work with this one. I switched to the USBDM firmware on the FRDM-KL25Z board and installed USBDM Debug server.
I used Processor Expert to generate the code, added a few components, added a few custom sources here and there, and it worked (Not out of the box though but quite interesting learning process…).
First I had to use a circuit design and simulation suite to make a package for the micro-controller chip, I use Labcenter Electronics’ Proteus™ (ISIS package). This is a windows application that I run via Wine. Then I use this chip design package, with all the pins labelled properly and connect all the other components like LEDs and debug and power connectors. ISIS comes with a huge database of such component models as resistors, capacitors, LEDs and all the usual suspects of circuit design. I only have to make packages for special or newly acquired components.
Next is to net-list the design into a PCB(Printed Circuit Board) layout. this is provided in Proteus™ by the sister package ARES™. In fact there is a net-list to ARES button in ISIS™. Here I have to size my board roughly, create a border edge and then layout the components on the virtual space to organize the PCB look. after that I usually try auto-route, a feature that is supposed to help draw the netlisted wiring in the circuit for me, but it is almost always no the optimized routes. This is why computers won’t replace humans :). So I do the connections myself and the resulting layout looks like this:
Sometimes during the process you might want to just have a glimpse of the look the PCB will have when finished with all the components soldered. ARES provides this output render too:
I definitely have to program the micro-controller with a firmware that will do the twinkling of the LEDs. I decided to go Processor Expert way and keep things simple. This forms a standard simple process for time bound student projects. Having tackled tools Set up in other posts in this series (for Debugging with USBDM, check out this post), I will just highlight the main areas of the source that I edited after it was generated by Processor Expert, as well as a list of the Processor Expert components used.
The main Idea is to have an infinite loop in the main method that increments a counter, and resets every time it reaches the maximum value of brightness(64), then for every counter value, do a few things: Loop for the number of LEDs (in this case 20), Generate a random number and use it to create a 10% chance. for this 10% chance, set the state of the LED at the current loop value’s position to be in brightening state, compute and set the maximum brightness it can reach based on the random number. Otherwise, increment the current brightness level by one if the LED of current state is brightening, or decrease this value by one if its state is dimming, the mode being changed from brightening to dimming if the brightness level is equal to the maximum brightness value. On decreasing brightness to the value 2, set the LED state to off, and hence neither dimming nor brightening.
Then have a hardware timer (for the purposes of parallelism) increment a second count value, independent of the main method, and every time light all LEDs whose current brightness level is greater than the second counter value, resetting the counter when it reaches 64. This part of the code lights the LEDs using brightness values set in the main method. This is implemented in the events.c file in the Processor Expert project.