I am trying to use PSoC 5LP to measure small capacitors (in the picoFarad range).
I'm not able to understand the reason why my code seems to be insensitive to the presence or not of a capacitor attached to the input pin P2.
Can anyone please help me to understand what's wrong with my code?
I think I did some mistakes in the way I changed the Drive Mode of the output pins P1, P3, P4 in the middle of the firmware, or maybe in the way I reset the Timer (to make it start counting in a precise instant inside the firmware).
I tried to exploit the Switching Capacitors algorithm illustrated in this Application Note from Microchip http://ww1.microchip.com/downloads/en/appnotes/01014a.pdf (in which a PIC microcontroller is used), to measure a small capacitance value Csen (22pF) by means of another capacitor Cint (of higher value, 10uF in this case) and eventually a resistor Rcal for calibration.
In order to apply this method I need to organize the firmware in different states and change dynamically the Drive Mode of the Digital Output Pins (from “Strong Drive” mode to “High Impedance” mode, and vice versa), while measuring the Time needed for the external capacitor Cint to charge up to an upper threshold VRH.
I used a Control Register to reset the Timer by firmware, and start measuring elapsed time) but the results are not even close to what I expected.
I tried to implement a state machine composed of 4 states, in which I changed the Drive Mode of output pins P1, P3, P4:
(Pin P2 is always set as “High Impedance Analog”):
.state = DISCHARGE: P1=0 P3=0 P4=0
.state = SWITCHING:
(quick transition) P1, P3, P4 = High Impedance
..substate= CHARGE P1 = 1 P3=hi-Z P4=hi-Z
(quich transition) P1, P3, P4 = High Impedance
..substate = SHARE P1 = hi-Z P3=hi-Z P4=0
.state = CALIBRATION: P1 = hi-Z P3=0 P4=0
.state = OUTPUT: P1=0 P3=0 P4=0
Here attached is my PSoC creator file, consisting of 2 projects:
- “SwitchedCapacitorTechnique”: this is the project in which I tried to replicate exactly the algorithm (except for the input pin parasitic capacitance Cpar, which I still need to evaluate) by using 4 different states: DISCHARGE, SWITCHING (consisting of 2 sub-states CHARGE and SHARE), CALIBRATION, OUTPUT.
- “SwitchedCapacitorTec_SIMPLER” project which is a simpler version of the algorithm, in which I only implement 3 states: DISCHARGE, SWITCHING (charge+share), OUTPUT (thus ignoring the Calibration of Cint value). With this project, I obtain a value k1 = 28 (thus resulting in a C sens = 415 nF instead of the 22pF I was expecting! And I obtain the same value even if I let Pin P2 as an open circuit, without any capacitor attached, thus there must be a HUGE mistake)
I am using:
- CY8CKIT-059 PSoC5LP Prototyping Kit
- Cint = 10 uF (external electrolitic capacitor)
- Csen = 22 pF (external ceramic capacitor) – to be measured by this project
- I consider Vdd = 5V since I am connecting the kit to my PC
During switching state:
- VRH = 3440mV (upper threshold)
- TSW = 5uSec (so the timer isr during switching state should occurr every 2.5usec)
During Calibration state: (not used in the “SwitchedCapacitorTec_SIMPLER” project)
VRL = 1250mV
TCLK = 0.5uF
Rcal = 2 kOhm (Pin P3 is NOT used in the “SwitchedCapacitorTec_SIMPLER” project)