TS-7250-V3 TS-9700

From Technologic Systems Manuals
Revision as of 14:41, 4 March 2020 by Mark (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
TS-9700
TS-9700.jpg
Product Page
8-bit IO

The TS-9700 provides 8 channels of 12-bit ADC which support 0-2.5V, 0-10V, or 0-20mA. Optionally this board can include 4x 0-5V DAC channels.

Refer to the TS-9700 manual for register / hardware documentation.

This example assumes addr 0x160 selected by having JP1/2/3 removed.

The TS-9700 identifies as 0x97:

pc104_peekpoke io 8 0x161

The TS-9700 is accessed in userspace with this sample C code.

#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <unistd.h>

#include "pc104.h"
#define TS9700_BASE 0x160

void ts9700_set_dac(uint8_t channel, uint16_t val)
{
	assert(channel <= 3);
	assert(val <= 0xFFF);
	pc104_io_8_write(TS9700_BASE + 0x4, val & 0xff);
	pc104_io_8_write(TS9700_BASE + 0x5, (channel << 6) | (val >> 8));

	while((~pc104_io_8_read(TS9700_BASE + 0x6)) & (1 << 7)){
		usleep(10); /* Wait until the DAC is ready */
	}
}

uint16_t ts9700_single_sample(uint8_t channel)
{
	uint16_t sample;

	assert (channel < 8);
	pc104_io_8_write(TS9700_BASE, channel | (1 << 4));
	while((~pc104_io_8_read(TS9700_BASE)) & (1 << 7)){
		usleep(9); /* Wait until the sample is ready */
	}
	sample = pc104_io_8_read(TS9700_BASE + 0x2);
	sample |= ((uint16_t)pc104_io_8_read(TS9700_BASE + 0x3) << 8);
	return sample;
}

int main(int argc, char **argv)
{
	int i;

	pc104_init();

	/* Verify the TS-9700 is detected */
	if(pc104_io_8_read(TS9700_BASE + 0x1) != 0x97) {
		fprintf(stderr, "TS-9700 not detected");
		return 1;
	}

	for (i = 0; i < 8; i++)
		printf("chan%d=0x%X\n", i, ts9700_single_sample(i));

	ts9700_set_dac(0, 0); // Set channel 0 to 0V
	ts9700_set_dac(1, 4095); // Set to 5V (max)
	ts9700_set_dac(2, 2048); // Set to 2.5V
	ts9700_set_dac(3, 819); // Set to ~1V

	return 0;
}

Compile this on the unit with:

gcc ts9700.c tspc104.c -o ts9700