[re-printed from PSoC Creator News and Information]
If you read my last post about Barc you will know that I was feeling pretty confident prior to the Embedded World show. All I needed to do was add some CapSense proximity loops (a.k.a. wires) to the robot, tune the CapSense sensors, and add a simple firmware state machine to move the robot based on which sensor notices a nearby hand. Simple!
And, for the most part it was. I fashioned a head for the dog from ABS plastic and taped in three loops of wire facing (pun intended) the front, left and right. I connected the wires to PSoC pins via the breadboard and got ready to finish the PSoC Creator project. Here are some pictures.
More alert readers will notice that the color of the PSoC kit has changed. More on that in a moment. Some will also see that programming the kit now requires me to feed the USB cable through the dog's mouth. Oops. That is pretty silly and, now I have done it about 600 times, I strongly advocate turning the kit around by 180 degrees. Unfortunately that would require me to rip off the breadboard and battery pack, which would make a nasty mess of the robot. I really do not want to do that… so I decided to live with it. And anyone who has tried measuring or tuning a sensitive electrical circuit like a proximity sensor will see that it is going to be tricky to get right with a big shielded cable running straight through the middle of the loop! I am, officially, a twit.
Then things got worse. My boss called. He never does that. So I knew it was likely bad news on the eve of Embedded World.
Me:
It was very reminiscent of the famous Office Space movie and the end result was weekend work for me. The good news is that I already had a handy PSoC 4 M-series prototyping kit - a pretty red one at that - and that changing the design in PSoC Creator took less time than it took to go another round with the soldering iron. In the time-honored tradition I swapped the kits and had the design working again in about an hour, then I told the boss I worked all weekend. It's a rule…
So, for the tuning, I added a CapSense component and an EZI2C to the project. The I2C is used as a bridge between the tuning software and the target. It can update the CapSense parameters live, which really helps you iterate to a solution. In the CapSense component I set up three proximity sensors, named FRONT, LEFT sand RIGHT, and selected manual tuning.
I also turned on filtering (in the Advanced tab) to remove as much noise as possible. This turned out to be really important at the show because the noise - probably from the very static-y carpet - was way higher than on my hardwood floors at home. I shall put the full list of CapSense edits in the project file, which I will post in a blog once I finish the whole project.
Here is the C code I wrote to run the tuner. In the I2C code I just tell it about a buffer (CapSense_dsRam) in the CapSense code and the tuner program uses this to communicate with the device. To avoid a lot of silliness - chasing a robot dog around the room - I did not start the PWM while I was tuning!
/* Start EZI2C component and prepare it for tuning */
EZI2C_Start();
EZI2C_EzI2CSetBuffer1(
sizeof( CapSense_dsRam ),
(uint8 *) &CapSense_dsRam );
CapSense_Start(); // Turn on CapSense
for(;;)
{
/* Start a scan and wait for it to complete */
CapSense_ScanAllWidgets();
while( CapSense_IsBusy() )
/* Busy loop */
}
CapSense_ProcessAllWidgets(); // Read all sensors and determine widget status
CapSense_RunTuner(); // Send data to tuner (I2C)
After building and programming I right-clicked the CapSense component and selected "Run Tuner". The tuner starts up and looks like this.
I start tuning in the graph view. CapSense uses a "raw count" value from its sensors and it is best to set the baseline value to 80% of maximum so there is room for the counts to go up (when a hand is close) and noise is minimized. You adjust the resolution and Modulation IDAC values to make that happen. Increasing the resolution improves the range of the sensor but also increases scan time (I do not care much in this application). Increasing the IDAC pulls the raw count value down to that 80% point.
Once I have that working I use the SNR Measurement tab. You just select the sensor and Acquire Noise. Then you put your hand by the sensor and Acquire Signal. It tells you the noise level and the SNR, which should be above 5.
I'm in good shape now. I set the Noise and negative Noise Thresholds to 5, which leaves a little wiggle room versus the measured value of 3. The Proximity threshold is 10, which is much closer to the noise than I would like, BUT I want maximum sensitivity and, if I do get some false readings it gives my dog a will of his own! I set the Touch Threshold to 100 which means that the sensor can register both proximity and, if I get really close, a touch. I might use that in the final project to change Barc's behavior in firmware.
As a sanity check I look at the Status graph, which shows the off / proximity / touch readings as I move my hand around the robot.
Once I have the settings I like I can send them To Project and quit the tuner. Back in PSoC Creator I open the parameter editor for CapSense and it lets me accept the edits from the tuner. Now, when I rebuild the program I have the tuned IDAC and threshold values for the left sensor.
I added a little code to the program, turned the PWM back on, and checked that my doggy reacts to my hand.
if( CapSense_IsWidgetActive( CapSense_RIGHT_WDGT_ID ) )
PWM_Speed_WriteCompare2( 40 );
else
PWM_Speed_WriteCompare2( 0 );
Here is a video of Barc sensing a hand near his face - did you notice that I actually video'd the left sensor instead of the right?
When I get back from vacation I will post my final Barc blog. I will complete the tuning of the other sensors and add a simple state machine to drive the motors and make him follow my hand. I will also include a bill of materials so you can re-create your own robot, with PSoC, for about $50.