Tirdad Sadri NejadAmir Kazemi
Published © GPL3+

Precision DIY voltage-current meter

Using ATtiny24's capable ADC, this probe can measure voltages from 1mV to 20V and currents from ~1mA to 2Amps with reasonable accuracy.

IntermediateFull instructions provided10 hours466
Precision DIY voltage-current meter

Things used in this project

Hardware components

ATtiny24A
Microchip ATtiny24A
×1
Slide Switch
Slide Switch
×1

Software apps and online services

PlatformIO IDE
PlatformIO IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

The whole project code

The whole platform.io project is provided in a zip file. The .hex file is available in "Attiny24_precision_meter\.pio\build\attiny24" subfolder

Schematics

The Schematic

Code

The main.cpp

C/C++
The project uses other libraries too but the C file is shown here
#include <avr/io.h>
#include <util/delay.h>
#include <stdbool.h>
#include <t7segment_sr.h>
#include <avr/interrupt.h>

#define EX_VREF   804UL // write the measured VREF in milli Volts
#define RES_DIV   232UL // write 10x the exact value of resistor divider. 232 means 23.2
#define SHUNT     125L  // write or tweak the shunt resistor value in milli ohms



uint16_t sample(uint8_t ad_mux_chn);
void adc_init(void);
uint16_t  sampling_interval, key_interval, vref, vin, iin;
extern volatile uint16_t milli_tick16;

//0 = VREF, 1 = VIN, 2 = IIN
uint8_t sample_mode = 0;
uint8_t display_mode = 0;


int main()
{
  CLKPR = 0b10000000;
  CLKPR = 0b00000010;
  DDRB  = 0xFF;
  DDRA    |= (1<<DDA4) | (1<<DDA5) | (1<<DDA7);
  PORTA   |= (1<<DDA6);
  TCCR0B  |= (1<<CS01);//divide by 8.
  TIMSK0  |= (1<<TOIE0);
  adc_init();
  sei();
  t7seg_write_int16(sample(0b000010));
  while(1)
  {
    if(milli_tick16 - sampling_interval > 200)
    {
      if(sample_mode == 0)  vref = (EX_VREF*4095L)/sample(2);
      else if(sample_mode == 1)  vin = ((uint32_t)vref*sample(1)*RES_DIV)/40950UL;
      else if(sample_mode == 2)  
      {
        uint16_t temp_var = sample(0b001011);
        if(temp_var < 4000)
        {
          iin = (((uint32_t)vref*sample(0b001011)*1000L)/(4095L*SHUNT*20))  - 1;
        }
        else
        {
          iin = (((uint32_t)vref*sample(0)*1000L)/(4095L*SHUNT)) - 1;
        }
      }
      sample_mode++;
      sample_mode %= 3;
      sampling_interval = milli_tick16;
    }
    
    if(milli_tick16 - key_interval > 250)
    {
      if(!(PINA & (1<<PINA6)))
      {
        display_mode++;
        display_mode %= 3;
        key_interval = milli_tick16;
      }
    }

    if(display_mode == 0)
    {
      if(vref < 10000) t7seg_write_int16(vref);
    }
    else if(display_mode == 1)
    {
      if(vin < 10000) 
      {
        t7seg_write_int16(vin);
        t7seg_set_dot_single(0,1);
      }
      else
      {
        t7seg_write_int16(vin/10);
        t7seg_set_dot_single(1,1);
      }
    }
    else if (display_mode == 2)
    {
      if(iin < 10000) t7seg_write_int16(iin);
      t7seg_set_dot_single(0,1);
    }
    else if (display_mode == 3)
    {
      
    }
    t7seg_looper();
  }
}

Credits

Tirdad Sadri Nejad
6 projects • 21 followers
AI masters degree student. a guitar player and an electronic hobbyist.
Contact
Amir Kazemi
4 projects • 3 followers
Material science engineering MSc nano material researcher
Contact

Comments

Please log in or sign up to comment.