February 2016 Updates

October 2015 Updates

How To Use C++ With PSoC Creator

Ever wanted to write C++ for the PSoC 5 or 5LP chips in PSoC Creator?

Well, although PSoC Creator doesn’t natively support it, you can quite easily do a few ‘hacks’, and you’ll be writing in C++ in no time.

A new page “Using C++ With PSoC Creator“, under Programming->PSoC, explains the steps required to compile C++ code in Cypress’s PSoC Creator.

It covers the four main steps:

1) Compiling with G++ rather than GCC using custom compiler flags

psoc-creator-build-settings-command-line-custom-flags Adding custom command line flags in PSoC Creator to force GCC to use the C++ compiler.

2) Wrapping C code with guards

extern C{< C code goes here>}

3) Defining the operators new and delete (this is optional)

void* operator new(size_t size)

4) Prevent Exception Functionality

Preventing exception functionality to prevent linker errors such as “undefined reference to __gxx_personality_v0” and “undefined reference to __cxa_end_cleanup” (again, this is optional, and only applied if you want to use new and delete)

cplusplus-linker-error-undefined-reference-to-gxx-personality Add the custom compile flag "-fno-exceptions" to every .cpp file you want to compile in PSoC Creator to prevent the "undefined reference to __gxx_personality_v0" linker error.

The steps have pictures and code examples to help you through the process.

Checkout the page here.

Electric Skateboard Firmware Uploaded

The firmware has been made public and can be downloaded as a Mercurial repo on www.bitbucket.com from https://bitbucket.org/gbmhunter/electric-skateboard-firmware.

Note that this is quite a large repo, as it contains the most recent and old versions of code, which were for different platforms.

More information can be found on the Electric Skateboard Firmware page, under Electronics->Projects->Electric Skateboard.

PSoC And Xbee Module Fried On Electric Skateboard

The fried PSoC and Xbee module after I accidentally connected two circuits with grounds at a potential difference of over 30V. Purple sparks and smoke came from the PSoC, but I was surprised that the Xbee died too.

Luckily, I was able to recover one of the two spare (but used) PSoC’s that I had for the project. After one failed IR soldering attempt, I managed to get the spare to work the second time around by boosting the IR temperature up to 280C (its bang-bang controlled, so it’s not very accurate or good for the IC’s!), but miraculously the PSoC survived.

Again, luckily, my friend had a spare Xbee module lying around, and I had mounted them in header, so it was as easy as pull-out/push-in to replace. He also has a USB board that allows you to configure the Xbee’s, so I’m contemplating increasing the baud rate (to save power), and making the Xbee comms secure (so interference doesn’t throw you off the board).

Skateboard Motion Sensor And Alarm Prototype Working

The motion sensor and alarm is now working! This would of had to been the easiest part of the circuits to get working. Everything just worked, first time (so did the software, and big part due to the PSoC’s easy to use drag’n’drop hardware blocks and configurations tools.

 

I found this cool little motion sensor, the MS24 on Element14 for less than NZ$10. It’s heaps better than most tilt sensors since it is sensitive to motion in all orientations, unlike tilt sensors which tend to only change state at a specific angle from the horizontal.

The sensor is normally closed, but when a small amount of motion disturbs it, it momentarily goes into the open state. All you need is a resistor and capacitor to interface this into a microcontrollers interrupt pin. The combination of the resistor and capacitor control the sensitivity.

 

I made a simple BJT full-bridge to control a speaker (or peizo) at 12V from the microcontrollers PWM outputs (the PSoC allows you to configure one PWM module to have two outputs, each the inverse of the other, all in the GUI!).

For the prototype, the motion sensor triggers an interrupt on the micro, which then enables the PWM, changing the frequency every 500ms to create an alarm sound.

Here’s a little video showing how it works. Note that I had the motion sensor on maximum sensitivity (aka no capacitor), hence how a little table vibration sets it off, which is quite impressive!

Mercurial Ignore File For PSoC Creator

 


 

Click here for the mark-up for a mercurial ignore file to exclude the unecessary files in a PSoC Creator development environment. Added to the programming section.