Making capacitance meter with mbed LPC1768

03 Aug 2016

Okay guys I am new to the mbed world , but I have fairly good knowledge in C/C++ and EE. I want to make the multimeter with LPC1768 uC.

So first I made a capacititance meter but I had problem with discharging the capacitor , I tried to add a BC547 BJT transistor to act as a switch and making PIN5 low when BJT is active so capacitor can discharge via resistor in connected to the emitter of BJT and to the GND. [url=https://postimg.org/image/wtlbac7nl/][img]https://s32.postimg.org/wtlbac7nl/capacitance_meter.jpg[/img][/url]

But capacitor would never fully discharge , so I googled and found out this thread https://developer.mbed.org/forum/electronics/topic/2783/

So basically copied the discharge solution from the link above and capacitormeter works up to some accuracy level.

But I am not really familiar with the DigitalInOut class , so if someone could provide me with some link with explanations what happens when each function is called and I don't mean on explanation of the functions like on this link , but what happens with the inner circuit of the uC: https://developer.mbed.org/handbook/DigitalInOut they are pretty clear.

When we call for example a function dischargePin.input() , what happens with inner circuit of a uC , I know each pin has a transistor and resistor built in , so when we declare a pin as an input it pulls pin into low impedance state making the current to flow into the pin, or the opposite for the dischargePin.output() if I am not mistaken?

So if anyone has some good link to provide on explaining digital I/O modes and uC behaviour or to explain in short here?

This is the code and the circuit: [code]

  1. include "mbed.h"

void discharge(void);

AnalogIn ain(p20); DigitalOut chargePin(p5); DigitalInOut dischargePin(p6);

Serial pc(USBTX, USBRX); Timer timer;

double averageCapacitance = 0; int i = 0; const double resistor = 99100; double timeConstant; double capacitance;

int main() {

while(1){

if( i == 10){ pc.printf("Average capacitance is %f uF\n\r", averageCapacitance/i); i = 0; } chargePin = 0; dischargePin.output(); dischargePin = 0; while(ain.read() > 0 ){}

timer.reset();

dischargePin.input(); dischargePin.mode(PullNone);

pc.printf("Capacitance meter\n\r");

char buttonPressed = pc.getc();

if(buttonPressed == '1'){

chargePin = 1; timer.start();

while(1){ if(ain.read() >= 0.63212){

timer.stop(); timeConstant = timer.read_us(); timer.reset(); capacitance = (timeConstant/ resistor); pc.printf("Capacitance: %f uF\n\r", capacitance); averageCapacitance += capacitance; i++; break; } } } } } void discharge(){

chargePin = 0; dischargePin.output(); dischargePin = 0; while(ain.read() > 0){} dischargePin = 0; pc.printf("Discharge has finished!\n\r"); } [/code]

[url=https://postimg.org/image/w07ec0xkn/][img]https://s31.postimg.org/52dhaacxn/capat_meter_2.jpg[/img][/url][url=https://postimage.org/]free pic[/url]

Also off topic I would like to know if there is option for mbed IDE to make curly braces highlighted when we select them with the mouse , because I get lost sometimes with this IDE.