Bukit Mertajam, Penang

AmpMeter using SK28A and 7-Segment Display

We wanted to demo the current going through a huge motor going through a super high ampere motor driver, 160 ampere to be exact. My task is to design and develop an ampere meter, showing the current!




Related Project


This tutorial will show you the interface of 50 Amp Current Sensor Breakout Board (BB-ACS756) with PIC18F2550. The analog voltage from the current sensor will be converted to Ampere and display by the seven segment.


BB-ACS756Breakout board for the fully integrated Hall Effect based linear current sensor ACS756. It provides economical and precise solutions for AC or DC current sensing in industrial, automotive, commercial, and communications systems. Typical applications include motor control, load detection and management, power supplies, and over current fault protection.

Seven Segment : Seven Segment! But why not just display the ampere reading on character LCD.  Normal character LCD has small font size, but seven segment has larger font size compared to the LCD. Some people may not able to read what is written on the LCD.  If you prefer bigger number size, the seven segment is for you.

The Interface 


  • Connect the hardware as above.
  • Do not forget to supply 12V to SK28A through its DC jack.
  • For the current sensing section, you can choose any battery and any load/motor as long as the current through the current sensor do not exceed 50A. 
  • Do take note that current sensor should be series in circuit.
  • Since we use seven segment display, the sensitivity in this programming are 1A and the maximun reading are 50A.
  • Note: The extra digit of seven segment is not use in this tutorial, it is use while we are dealing with 160A Motor Driver at Singapore Mini Maker Faire.

AmpMeter Mode Description


  • Once power on, make sure the power trough AmpMeter are 0A, load is not running or no load. Press SW1 to start the AmpMeter (set up 0A/center value of the current sensor) .


  • After pressing SW1 on SK28A, the AmpMeter will enter REALTIME mode.
  • Press SW1 to change the mode between REALTIME mode and MAXIMUM mode.
  • In REALTIME mode, the LED1 will turn OFF.
  • In MAXIMUM mode, the LED1 will turn ON.


Define of constant, do make sure the voltage VCC of your current sensor is written here. It can be 5V or as low as 4.9V depends on your sk28A board.

[code lang=”c” highlight=””]
#define Vref 4.95

Initialization of PIC18F2550

  • Input and Output initialize
  • Turn OFF comparator module
  • Turn ON ADC module
  • LCD initialize

[code lang=”c” highlight=””]
// I/O initialize Start
PORTA = 0;
PORTB = 0;
PORTC = 0;
TRISA = 0b00000001; //RA0 as input
TRISB = 0b00000001; //SW1 as input
TRISC = 0b00000000;
// I/O initialize End

//Comparator initialize start
CM0 = 1; //Turn off comparator
CM1 = 1;
CM2 = 1;
//Comparator initialize end

//ADC initialize start
VCFG1 = 0; //Vref VSS VDD
VCFG0 = 0;
PCFG0 = 0; //Set RA0 as anolog input
PCFG1 = 1;
PCFG2 = 1;
PCFG3 = 1;
CHS0 = 0; //AN0 selected
CHS1 = 0;
CHS2 = 0;
CHS3 = 0;
ADFM = 1; //Right justified result
ADCS0 = 1; //Fosc/16
ADCS1 = 0;
ADCS0 = 1;
ADON = 1; //ADC Module ON
//ADC initialize end


Find zero amp ADC value read by Microcontoller which is VCC/2. Theoritically it will be 1023/2 which is roughly 512 but my circuit give 508 (It should be system noise) . So this function is to capture  zero amp reading.

[code lang=”c” highlight=””]
//Find Center Value Start
lcd_putstr(“Ctr= “);
value = 0;
for(i = 0;i < 256;i++)
value = value + (float)adc_run();
value = value /256.0;
if(SW1==0) break;
centerValue = value;
//Find Center Value End

Selection between REALTIME mode and MAXIMUM mode. User can select REALTIME mode or MAXIMUM mode by pressing SW1.

  • REALTIME mode: Show real time current reading. LED attached to RB1 should OFF.
  • MAXIMUM mode: Show the maximum ampere reading through the current sensor. LED attached to RB1 should ON.

[code lang=”c” highlight=””]
if(SW1 == 0) //SW1 press
while(SW1 == 0); //Wait until SW1 release
if(selection == REALTIME)
selection = MAX;
LED = 1;
else if(selection == MAX)
selection = REALTIME;
LED = 0;

ADC part – Read the analog value from current sensor. 256 Sample of reading has been taken and averaging has been done in order to smooth out the reading at the seven segment display.

[code lang=”c” highlight=””]
value = 0;
for(i = 0;i < 256;i++)
value = value + (float)adc_run();
value = value /256.0;

Convert analog value to ampere. Then by using software, the ampere reading is converterd to bcd.

[code lang=”c” highlight=””]
if(value > centerValue)
valueans = value-centerValue;
valueans = (valueans * (Vref/1023.0)) / 0.04; //ADC value to change it to AMP
else if(value < centerValue) { valueans = centerValue-value; valueans = (valueans * (Vref/1023.0)) / 0.04; //ADC value to change it to AMP } else valueans = 0; if(valueans > maximum) maximum = valueans;
if(selection == REALTIME) bcd(3,valueans);
else if(selection == MAX) bcd(3,maximum);

Analog to Digital to Ampere

Current sensor, ACS756 give out analog voltage. At zero amp, ACS75 will output VCC/2 (ex: 5V/2 = 2.5V). The output voltage of ACS756 will increase 40mV per Ampere (sensitivity = 40mV/A).

CurrentSense (2)CurrentSense (2)

If current flow in this direction, at 1A the output voltage will be 2.5V+40mV and at 2A the output voltage will be 2.5V+ 80mV and so on.

CurrentSense (2) - Copy

If current flow in opposite direction, at 1A the output voltage will be 2.5V-40mV and at 2A the output voltage will be 2.5V- 80mV and so on.

In order to get the changes in analog reading from the middle value (VCC/2), the formula are:

[code lang=”c” highlight=””]
valueans = value-centerValue;


valueans = centerValue-value;

Then, the changes in analog reading will be converted into voltage.

[code lang=”c” highlight=””]
valueans = (valueans * (Vref/1023.0));

Then, the voltage value need to be devided with the sensitivity of ACS756 (40mV/A) in order to get the Ampere reading.

[code lang=”c” highlight=””]
valueans = (valueans * (Vref/1023.0)) / 0.04;

Full Source Code



Related Posts

Comments (1)

please help me to know something.how to mc’s pwm port disabaled?if you know anybody!

Leave a comment