5. Build & Debug

Here we will guide you through debugging this labs project and will provide details on how to verify the working of the project.

5.1 Edit the source

First we need to open the main source file, located:
[Project]src<project_name>.c
Extern a declaration to the QE generated sample application and make a call to the application.

extern void qe_touch_main(void);
qe_touch_main();

This is shown below.

Second lets add some code which illuminates the on-board LED when a proximity event is detected.
Copy the code below and copy it into the file we generated earlier located at:
[Project]qe_genqe_touch_sample.c
The code should go at line 67 where the TODO: statement exists.

CCS0 = (button_status > 0UL) ? 2U : 0U;

The code above toggle the current controlled IO registers to sink 5mA producing a magenta LED.
Code insertion shown below:

5.2 Build the project

To build the project please [Right-Click] the project and click Build Project.

5.3 Hardware

Before debugging the project, please ensure headers are fitted to the header H1 in positions 1-2 (VBATT-VDD) & 4-5 (VDD_RL78 - VDD).
Finally connect the E2-Lite - the user does not need to connect batteries for this lab as we will supply the board via the debugger.

5.4 Debugging the project

To start a debug session please select the project by clicking on it and click the debug icon along the menu bar.

Finally Click the run icon, first it will run to main, click the run icon again and the project will start running.

5.5 Trigger the LED [optional]

Now as your hand approaches the proximity electrode the LED should light up.
When the hand is retracted the LED should then turn off.

5.6 Start Monitoring (Emulator)

Now onto the second major function of the QE tools.
The monitoring function allows us to configure the middleware in many ways - the following steps will show us a plethora of those ways.
First Navigate back to the CapTouch Workflow, either by the tab or using the
Renesas ViewsRenesas QECapTouch Workflow (QE)
method outlined earlier.

5.7 Enable Monitoring

Navigate to Start Monitoring (Emulator) within 4.Monitoring and select Show Views

Now perform the following (you may need to expand the windows as shown in the .gif):

  1. In the CapTouch Board Monitor (QE) view select Enable Monitoring
  2. In the CapTouch Status Chart (QE) view select Sync a selection
  3. In the CapTouch Parameters (QE) view select Sync a selection
.
5.8 Change the threshold

Now we are going to change the threshold, the threshold is the value it which indicates a touch.

This is where fine tuning the sensitivity distance in a proximity application occurs.
Or when tuning touch pressure occurs in a touch application.
To change this value, do the following:

  1. Navigate to Threshold in the CapTouch Parameters (QE) view
  2. Reduce the Threshold value by approximately a third (i.e., 500 becomes 350)
  3. Click the Write value to the target board button
  4. Notice how in the CapTouch Status Chart (QE) view the threshold (green line) reduces
  5. Now approach the board with your hand and notice how the sensing distance has increased
5.9 Change the positive noise filter cycle counts

Now we are going to change the positive noise filter cycle count value.
This value represents the number of consecutive touches before propagating a touch event.
The negative cycle count is the opposite i.e., the number of consecutive no-touches before propagating a no-touch event.

This is where fine tuning the filters starts.
To change this value, do the following:

  1. Navigate to Positive Noise Filter Cycle value in the CapTouch Parameters (QE) view
  2. Change the Positive Noise Filter Cycle value to 100
  3. Click the Write value to the target board button
  4. Before apporaching the board with our hand ensure the CapTouch Board Monitor (QE) view is showing Button 00
  5. Now approach the board with your hand and notice how the touch event does not occur immediatley
  6. Note: the touch event can be seen as a hand on top of Button00 in the CapTouch Board Monitor (QE) view
  7. Change the Positive Noise Filter Cycle value to 3
  8. Click the Write value to the target board button
  9. Note: this is just to reset the value so we can evaluate the other parameters in later steps.
5.10 Change the drift correction

To understand the drift correction value one must understand the reference value. The reference value is the baseline value or the resting value with minimal external disturbance - i.e., the svalue when the system is in idle state.
The threshold applies to this value - so if your reference value is 1500 counts and your threshold value is 500 counts, then your threshold lies at 1500 + 500 = 2000 counts.
Now the reference value may be subject to change due to many external factors such as temperature or humidity.
Therefore the middleware provides a mechanism, that after a settabel number of counts, the reference value is updated according to the latest value measured under no-touch conditions. Thus providing envirnmental compensation.
To see this in action, please perform the following:

  1. Navigate to Drift Correction in the CapTouch Parameters (QE) view
  2. Change the Drift Correction value to 25
  3. Click the Write value to the target board button
  4. Now slowly approach the board with your hand and notice how the reference value (blue line) and threshold value (green line) move to accomodate this
  5. Change the Drift Correction value back to 255
  6. Click the Write value to the target board button
  7. Note: this is just to reset the value so we can evaluate the other parameters in later steps.
5.11 Change the long touch cancel

The long touch cancel value is how many consecutive touches are detected before cancelling the touch event. On cancelling the touch event the reference value is immediately shifted up to the count value measured when long touch cancel is triggered.
To see this in action, please perform the following:

  1. Navigate to Long Touch Cancel Cycle in the CapTouch Parameters (QE) view
  2. Change the Long Touch Cancel Cycle value to 100
  3. Click the Write value to the target board button
  4. Now approach the board with your hand to engage a touch and keep your hand still
  5. Keep your hand there and notice how the touch is eventually stopped detection and the reference value (blue line) shifts up
  6. Change the Long Touch Cancel Cycle value back to 0
  7. Click the Write value to the target board button
5.12 Output parameters file

Now simply click the Output Parameter Files button in the CapTouch Parameters (QE) view.
This saves the current set of parameters to the file [Project]qe_genqe_touch_config.c.

5.13 Summary

In this lab you have gone through the process for creating a capacitive touch application from scratch.
The principles outlined here abstracted from hardware can be used on any RL78G2x based device.