circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

June 20065, Issue 191

Earth Field Magnetometer
Cypress PSoC High Integration Challenge 2004 Winner


SOFTWARE DETAILS

I wrote the application code in C language with the Cypress PSoC Designer 4.1 Service Pack 1. The C compiler doesn’t perform any optimization during compilation, but it uses a post-processor that carries out code compression and eliminates unused code. I ran into some difficulty with this approach, so I had to rewrite some sections of the code in assembly to save flash memory space.

When I first generated the module application files, the module code size was 2,024 bytes. That left only 24 bytes of the CY8C22213’s 2 KB of flash memory for user code! Clearly, something had to change. I looked at the linker map and saw that just over half the code was from the LCD and I2Cm modules. I ended up rewriting both of them and saving nearly 600 bytes.

Now that I had room for user code, it was time to start writing it. The API documentation was thorough enough to make the code development process easy. To simplify development, I started with the larger CY8C27443 microcontroller on the PSoC Invention Board. I then used it to download to the CY8C22213 after debugging and testing the code.

There still wasn’t enough room after everything was written, so I ended up rewriting the initialization code in boot.asm and the LoadConfig routines. I also noticed that almost half of the registers were being initialized to zero, but they were already reset to zero by a system reset. Commenting these out saved quite a bit of space. Unfortunately, there was no way to do this automatically; it had to be redone manually every time the Generate Application function was used. I had to avoid commenting out the code for the I/O port DriveMode registers because they weren’t set to zero at reset.

The final code weighs in with a whopping 6 free bytes of flash memory. It uses about 80% of the RAM. I used stackwalk.exe, which analyzes stack usage from the listing file. It showed a maximum stack size of 25 bytes. This still left enough space for comfort, making a stack overflow very unlikely.