Saturday, 27 July 2013

Simple Digital Current Meter (DCM) using PIC microcontroller (Schematic + code + Proteus simulation)

This post would provide a working example of how to make a simple Current Meter (DCM) using 16bit PIC microcontroller and a series shunt resistance. We have very precise ammeter current measurement with a 10bit ADC and with a tolerance of ±10mA.

 You may download code and Proteus Simulation from the download section at the bottom of this post. I am using MPLAB X IDE, C30 Compiler and Proteus Simulation on v8.0. This code is written in C Language and will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by slightly changing the code.

 In this post I supposed that you know following things if not then please go through following posts before proceeding with this.

·         How to Blink an LED. (Click here)
·         How to interface an LCD. (Click here)
·         How to configure ADC module. (Click here)
·         Digital Voltmeter. (Click here)

The science behind measuring current is to add a known shunt resistance in the path from which current is flowing so the voltage drop on this shunt resistance is measured by ADC channel. By using Ohm’s Law we can find the current in particular path (As current is same in a loop). This shunt resistance is very small of some milliohms with higher wattage typically 1-10W depending upon particular application.

Proteus Simulation:

            In the following figure 1. I used a fix resistor (R4 = 10kΩ and R6 = 10kΩ) for 2.5V reference voltage for ADC. And a dummy variable resistor for simulating this circuit for various current measurements. A shunt resistance with a resistance of 100mΩ is used in series with the path in which we are going to measure current. I am using ADC channel AN1 for measurement of voltage drop across shunt resistance. I used LCD on PortB.

Figure 1. Schematic and Proteus Simulation.

In the following figure 2. Animation shows that when I increase/decrease resistance from variable resistor RV1 the current in the path changes as shown by a current probe named shunt resistance. And the value that is measured by current probe is same as that we measured through ADC and is displayed on LCD with a tolerance of ±10mA.

Figure 2. Animation of Proteus Simulation.


In the following figure 3. This is main function in which I first initialize LCD, then I configure ADC with Channel 1. And a loop which only calls a function named DisplayCurrent() which is responsible for displaying measured current flowing through shunt resistance on LCD.

Figure 3. main function.

In the following figure 4. We have DisplayCurrent() which has a string that is printed directly and a variables named “VoltageDrop” which has the voltage drop value across the shunt resistance. Then we have a “ShuntResistor” whose value is fixed for this design as 100mΩ you may change this according to your design requirement. A variable named “CurrentMeasured” has the value of current measured that is flowing through the shunt resistance. The formula for calculating current is simple we have one unknown variable according to Ohm’s law and that is current so “V = IR”.

Figure 4. Displaying measured current.

Now at this stage we measured the value of current flowing through a series shunt resistor. For displaying this value on LCD we have function named WriteLongAsFloatUptoFiveFigures(). This function will display variable “CurrentMeasured” by passing it as a parameter.

Reading Suggestions:


You can download Code (MPLAB X and C30 compiler) and Proteus (v8) Simulation. Click here

For all topics Click here.

That’s all for this post hope you will learn please comment if you have any questions for upcoming post please subscribe or follow.

All the text and graphics contained on this blog belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission. 

© Copyright 2013 IbrahimLabs. All rights reserved.

Getting started with Arduino coding. (A beginner’s quick guide)

Welcome to my first Arduino coding guide. This would take you to kickstart with Arduino boards. I would go through following things real...