How to make a digital DC Ammeter with PIC16F73 micro-controller and Seven Segment display

Published by MKDas on

Lets make an Ammeter. Yes, in this article we are going to make an Ammeter for DC circuits. After reading this article you’ll be able to make one for yourself too. I hope it will help you a lot. So keep reading…

Disclaimer: Electricity is always dangerous. Skill required to work with electricity. Do work with your own risk. Author will not be responsible for any misuse or harmful act. This website contents is also copyright protected. Anything copied and directly posted in your website and claiming it as yours is prohibited and nonsensical. Author published all the articles as opensource to help you making your project and learning purpose only. Learn and make one for yourself. If need any help feel free to ask the author. Author will be helpful to you. Thanks.

What is an Ammeter?

An ammeter is a measuring instrument used to measure the current in a circuit. Electric currents are measured in amperes, hence the name. Instruments used to measure smaller currents, in the milliampere or microcomputer range, are designated as milliammeters or microammeters. _Wiki.

Simply it is an Ampere meter. Like our voltmeter, it can be both analog or digital type.

An analog ammeter

Although it is very common to find an analog ammeter, here we are going to make our own digital Ammeter.

Working mechanism of a digital Ammeter:

Keep in mind that, we can not use current reading directly in any circuit or components. All we need to convert the current signal into voltage signal first then we can use that signal for any purpose.

In Ampere meters a shunt resistance is used. When current flows through that shunt resistance, a voltage is generated across that shunt resistance according to the equation, V=IR.

So, if we can measure that voltage across the shunt resistor, we can easily find the current reading. I’ve published an article on this, you should check that first. ‘DC Current measuremenhttps://labprojectsbd.com/2020/05/09/dc-current-measurement-using-shunt-resistor-and-op-amp-circuit/t using Shunt resistor and Op-Amp Circuit‘.

Sensing circuit:

For DC ammeter, we can use shunt resistor if the current rating is low. Depending on the position of this shunt resistor, sensing circuit will be different.

Configuration 1: Low side shunt resistor based sensing circuit
Configuration 2: High side shunt resistor based sensing circuit

In both of the cases, the load current will be:

I = Op-Amp Output/(Gain x Rshunt)

We can use any configuration from these two in our Ammeter. All we need to do is sensing the output voltage of Op-Amp and print that on display.

Ammeter circuit diagram with Low side shunt resistor:

Circuit diagram with low side shunt resistor

Coding with mikroC pro for PIC for Low side shunt resistor based Ammeter:

/*******************************************************************************
* Program for "DC Ammeter with PIC16F73"                                       *
* Program written by_ Engr. Mithun K. Das                                      *
* MCU:PIC16F73; X-Tal:8MHz; mikroC pro for PIC v7.6.0                          *
* Date:09-05-2020                                                              *
*******************************************************************************/
char segment_array[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};//cmmon cathode_non dot

sbit digit0 at RC0_bit;
sbit digit1 at RC1_bit;
sbit digit2 at RC2_bit;
sbit digit3 at RC3_bit;

char digits[5];
void display_7segment(int number)
{
   digits[3]=number/1000u;
   digits[2]=(number/100u)%10u;
   digits[1]=(number/10u)%10u;
   digits[0]=(number/1u)%10u;
}

void InitTimer0()
{
  OPTION_REG     = 0x85;
  TMR0           = 100;
  INTCON         = 0xA0;
}

int position=0;
void Interrupt() iv 0x0004 ics ICS_AUTO
{
  if (TMR0IF_bit)
  {
    TMR0IF_bit   = 0;
    TMR0         = 100;

    digit0 = 1;
    digit1 = 1;
    digit2 = 1;
    digit3 = 1;
    if(position>3)position=0;

    if(position==2)PORTB = segment_array[digits[position]]+128; //dot point
    else PORTB = segment_array[digits[position]];

    if(position==3)
    {
        digit0 = 0;
        digit1 = 1;
        digit2 = 1;
        digit3 = 1;
    }
    else if(position==2)
    {
        digit0 = 1;
        digit1 = 0;
        digit2 = 1;
        digit3 = 1;
    }
    else if(position==1)
    {
        digit0 = 1;
        digit1 = 1;
        digit2 = 0;
        digit3 = 1;
    }
    else if(position==0)
    {
        digit0 = 1;
        digit1 = 1;
        digit2 = 1;
        digit3 = 0;
    }
    position++;
  }
}



unsigned long adc_rd0=0;
unsigned int dc_amps=0;
int k=0;
void main()
{
 TRISA=0xFF;//all in
 TRISB=0x00;//all output
 TRISC=0x00;//all output
 PORTB=0x00;
 PORTC=0x00;//clear ports
 ADCON1=0x00;//all analog in
 InitTimer0();//5ms timer
 while(1)
 {
      ADCON0 = 0b00000001;//select AN0
      adc_rd0 = 0;//clear data
      for(k=0;k<10;k++)
      {
         adc_rd0+=ADC_Read(0)*1.7857;
         Delay_ms(10);
      }
      adc_rd0/=10;
      dc_amps = adc_rd0;

      display_7segment(dc_amps);
 }
}//

Here, we used our previous voltmeter code and modified it a little bit to make our DC Ammeter. You can check my other article as the basic.

How to make a DC voltmeter using 7-segment & PIC16F73‘.

Test result with low side shunt resistor:

Test result with Low side shunt resistor

Ammeter circuit diagram with High side shunt resistor:

High side shunt resistor based ammeter circuit diagram

Coding with mikroC pro for PIC for High side shunt resistor based Ammeter:

/*******************************************************************************
* Program for "DC Ammeter with PIC16F73"                                       *
* Program written by_ Engr. Mithun K. Das                                      *
* MCU:PIC16F73; X-Tal:8MHz; mikroC pro for PIC v7.6.0                          *
* Date:09-05-2020                                                              *
*******************************************************************************/
char segment_array[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};//cmmon cathode_non dot

sbit digit0 at RC0_bit;
sbit digit1 at RC1_bit;
sbit digit2 at RC2_bit;
sbit digit3 at RC3_bit;

char digits[5];
void display_7segment(int number)
{
   digits[3]=number/1000u;
   digits[2]=(number/100u)%10u;
   digits[1]=(number/10u)%10u;
   digits[0]=(number/1u)%10u;
}

void InitTimer0()
{
  OPTION_REG     = 0x85;
  TMR0           = 100;
  INTCON         = 0xA0;
}

int position=0;
void Interrupt() iv 0x0004 ics ICS_AUTO
{
  if (TMR0IF_bit)
  {
    TMR0IF_bit   = 0;
    TMR0         = 100;

    digit0 = 1;
    digit1 = 1;
    digit2 = 1;
    digit3 = 1;
    if(position>3)position=0;

    if(position==2)PORTB = segment_array[digits[position]]+128; //dot point
    else PORTB = segment_array[digits[position]];

    if(position==3)
    {
        digit0 = 0;
        digit1 = 1;
        digit2 = 1;
        digit3 = 1;
    }
    else if(position==2)
    {
        digit0 = 1;
        digit1 = 0;
        digit2 = 1;
        digit3 = 1;
    }
    else if(position==1)
    {
        digit0 = 1;
        digit1 = 1;
        digit2 = 0;
        digit3 = 1;
    }
    else if(position==0)
    {
        digit0 = 1;
        digit1 = 1;
        digit2 = 1;
        digit3 = 0;
    }
    position++;
  }
}



unsigned long adc_rd0=0;
unsigned int dc_amps=0;
int k=0;
void main()
{
 TRISA=0xFF;//all in
 TRISB=0x00;//all output
 TRISC=0x00;//all output
 PORTB=0x00;
 PORTC=0x00;//clear ports
 ADCON1=0x00;//all analog in
 InitTimer0();//5ms timer
 while(1)
 {
      ADCON0 = 0b00000001;//select AN0
      adc_rd0 = 0;//clear data
      for(k=0;k<10;k++)
      {
         adc_rd0+=ADC_Read(0)*0.8884;
         Delay_ms(10);
      }
      adc_rd0/=10;
      dc_amps = adc_rd0;

      display_7segment(dc_amps);
 }
}//

Test result with High side shunt resistor based Ammeter:

Test result with High side shunt resistor

Summarizing:

We have seen two types of shunt resistor based DC ammeter design. Now, you can be able to make any one for you as per your requirement. In two types, code is almost same. Just the value of constant is different as the gain is different in two types of circuits. If you need to measure higher current, use suitable shunt resistor then design the Op-Amp circuit.

Shunt resistor selection is very important in this circuit. You should not loss too much power across the shunt resistor. Otherwise, it will burn and will affect the total current flow.

Tips: Sometimes, you can use the PCB truck as a shunt resistor. In that case, design the op-amp circuit then gradually increase the gain. Once you start getting good output, set the gain in suitable range. After that, simply use the coding.

I hope, you have enjoyed this article and this article will be very helpful to you. Now make one ammeter for yourself and share your experience here in the comments section. If you need any help, let me know that. Thank you, Enjoy!


MKDas

Mithun K. Das; B.Sc. in EEE from KUET. Blog: https://labprojectsbd.com

2 Comments

Abhinav · September 20, 2020 at 6:51 am

What is the maximum Ampere it can show??

    Mithun K. Das · September 20, 2020 at 7:15 am

    You can get different ranges using this concept. If you understand the concept, then design as you need.

Leave a Reply

Your email address will not be published. Required fields are marked *