Getting Current Voltage Input (VIN) on TS-7250-V2

Here’s an example program our engineers might find useful. Jesse Off, our lead engineer, wrote this simple program to get the voltage input (Vin) on the 8 – 28 VDC power rail on the TS-7250-V2 (Rev. B only). Without going into too much detail about implementation of the SiLabs microcontroller, there is a register which is used to store various ADC values, including Vin. This example program basically polls this 19 byte register via I2C interface, accounts for the voltage divider (see TS-7250-V2 schematic), and spits out the Vin value. So, without further ado, here’s the code:


#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
    uint8_t data[19];
    uint16_t vin;
    float vinf;
    int fd, i;

    fd = open("/dev/i2c-1", O_RDWR);
    assert (fd != -1);
    if (ioctl(fd, 0x0706, 0x2a) < 0) {
        perror("MCU did not ACK 0x2a\n");
        return -1;

    bzero(data, 19);
    read(fd, data, 19);
    vin = (data[0]<<8)|data[1];
    vin = (vin*2500/1024); /* Convert to ADC mV (2500 mV ref, 10b ADC) */
    vinf = vin*(1./.0414); /* Voltage divider before uC: 4.14% */
    printf("vin_mv=%d\n", (uint16_t)vinf);

Compiling and Running

Once you’ve copied the source code over to the TS-7250-V2, you can use the preloaded gcc command to compile like this:

root@ts7250-496b63:~# gcc get_vin.c -o get_vin

Then, of course, run it! We have a 12 VDC power adapter plugged into the 8 – 28 VDC input, so we expect to see 12V reported as Vin.

root@ts7250-496b63:~# ./get_vin

Again, we hope you’ve found this example program to get Vin on the TS-7250-V2 helpful. Let us know if you have any suggestions to make it better.  Home

Author: Derek Hildreth

eBusiness Manager for Technologic Systems