Close

Markus firmware customization

A project log for Transistor Tester

based on design from svn://mikrocontroller.net/transistortester/

K.C. LeeK.C. Lee 05/12/2018 at 19:350 Comments

This branch have the necessary hooks for changing ADC.   These changes let me set aside the more flexible PC3-PC5 as spares.

config.h

/* test pin with 2.5V reference and relay */
#define TP_REF           ((1<<MUX2)|(1<<MUX1))
/* test pin with 4:1 voltage divider */
#define TP_BAT           ((1<<MUX2)|(1<<MUX1)|(1<<MUX0))

I made some changes to the source code to divide the 16MHz to 8MHz using the clock divider to reduce power consumption. 

In main() in main.c:

  #ifdef CPU_DIV    CLKPR = (1<<CLKPCE);
  CLKPR = CPU_DIV;
  #endif  /* set up MCU */

config.h:

/* MCU clock */
#define CPU_DIV     (1<<CLKPS0)
#define CPU_FREQ    8000000             // Hardcoded because assembler won't do expression

Power consumption is around 50mA (idle) to 70mA.  So for a healthy NiMH battery, that's about 30+ hours of battery life.

ADC7 sense the battery voltage without a voltage divider and the MOSFET has no DC offset. Battery low/weak is set for NiMH type.

config.h:

/*
 *  Voltage divider for battery monitoring
 *  - BAT_R1: top resistor in Ohms
 *  - BAT_R2: bottom resistor in Ohms
 *  - for a direct measurement without a voltage divider set
 *    BAT_R1 to 0 and BAT_R1 to 1
 */

//#define BAT_R1           10000
//#define BAT_R2           3300

#define BAT_R1           0
#define BAT_R2           1

/*
 *  Voltage drop by reverse voltage protection diode and power management
 *  transistor (in mV):
 *  - Schottky diode about 200mV / PNP BJT about 100mV.
 *  - Get your DMM and measure the voltage drop!
 *  - Could be also used to compensate any offset by the voltage divider
 *    used to measure the battery voltage.
 */  

#define BAT_OFFSET       0

/*
 *  Battery weak voltage (in mV).
 *  - Tester warns if BAT_WEAK is reached.
 *  - Voltage drop (BAT_OUT) is considered in calculation.
 */

#define BAT_WEAK         1150

/*
 *  Battery low voltage (in mV).
 *  - Tester powers off if BAT_LOW is reached.
 *  - Voltage drop (BAT_OUT) is considered in calculation.
 */

#define BAT_LOW          1050

Discussions