1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-30 00:41:17 +01:00

tests/periph_dac: updated test for API changes

This commit is contained in:
Hauke Petersen 2015-12-08 01:13:35 +01:00
parent a1e3bb1bfc
commit 74bd800903
2 changed files with 23 additions and 77 deletions

View File

@ -3,20 +3,12 @@ About
This is a test application for a digital to analog converter (DAC).
This test application will initialize each configured DAC and one ADC (ADC_O)
device to sample with 10-bit accuracy. The ADC is only initialized if there is
one available on your board.
After initialization, values from 0 to 1000 are converted through the DACs in a
loop. Shortly after the digital to analog conversion of one number, the ADC_0
samples its input signal. The numbers that are given to the DACs and the
numbers that are sampled by the ADC were printed to the STDOUT.
This test application tries to initialize every available DAC line. If
successful, it will output a saw tooth pattern with a period of about 10Hz on
each of the available lines.
Usage
=====
a) Connect an oscilloscope to the DAC pins and look at the ten iteration signal levels
or
b) Connect the ADC input to the DAC outputs successively and compare if the sampled input value correlates with the printed output value at each DAC port.
Connect an oscilloscope to the DAC pins and look at the signal levels (you
should be able to clearly see the saw tooth signal in your scope)

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014-2016 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
@ -7,7 +7,7 @@
*/
/**
* @ingroup tests
* @ingroup tests
* @{
*
* @file
@ -21,88 +21,42 @@
#include <stdio.h>
#include "cpu.h"
#include "board.h"
#include "xtimer.h"
#include "periph/dac.h"
#include "periph/adc.h"
#if DAC_NUMOF < 1
#error "Please enable at least 1 DAC device to run this test"
#endif
#define RES DAC_RES_10BIT
#define ADC_RES ADC_RES_10BIT
#define DELAY (1000 * 1000U)
#define MAX_VALUE_STEPS 1000
static int values[DAC_NUMOF][DAC_MAX_CHANNELS];
#define DELAY (100U)
#define STEPS (1000U)
int main(void)
{
uint16_t write_value = 0;
int8_t status_dac_write;
uint32_t last = xtimer_now();
uint16_t val = 0;
uint16_t step = 0xffff / STEPS;
puts("\nRIOT DAC peripheral driver test\n");
puts("This test simply sets each available DAC channel about every 100ms\n\n");
puts("This test application produces a saw tooth signal on each available\n"
"DAC line. The period of the signal should be around 100ms\n");
/* initialize all DAC lines */
for (int i = 0; i < DAC_NUMOF; i++) {
/* initialize result vector */
for (int j = 0; j < DAC_MAX_CHANNELS; j++) {
values[i][j] = -1;
}
/* initialize DAC device */
printf("Initializing DAC_%i @ %i bit resolution", i, (6 + (2* RES)));
if (dac_init(i, RES) == 0) {
puts(" ...[ok]");
}
else {
puts(" ...[failed]");
if (dac_init(DAC_LINE(i)) < 0) {
printf("Error initializing DAC_LINE(%i)\n", i);
return 1;
}
#ifdef ADC_NUMOF
printf("Initializing ADC_LINE(0)");
if (adc_init(ADC_LINE(0)) == 0) {
puts(" ...[ok]");
}
else {
puts(" ...[failed]");
return 1;
printf("Successfully initialized DAC_LINE(%i)\n", i);
}
#endif
}
puts("\n");
puts("");
/* create saw tooth signal */
while (1) {
for (int i = 0; i < DAC_NUMOF; i++) {
for (int j = 0; j < DAC_MAX_CHANNELS; j++) {
/* Write values to DAC */
status_dac_write = dac_write(i, j, write_value);
if (status_dac_write < 0) {
printf("%i: Something went wrong writing DAC\n", status_dac_write);
return -1;
}
#ifdef ADC_NUMOF
/* Read values from ADC */
int sample = adc_sample(ADC_LINE(0), ADC_RES);
if (sample < 0) {
printf("%i: Something went wrong sampling ADC\n", sample);
return -1;
}
printf("Wrote %i Read %i using DAC %i Channel %i and ADC_0 Channel 0\n", write_value, sample, i, j);
#else
printf("Wrote %i to DAC %i Channel %i\n", write_value, i, j);
#endif
}
dac_set(DAC_LINE(i), val);
}
puts("\n");
write_value+=100;
if (write_value >= MAX_VALUE_STEPS) {
write_value = 0;
}
/* sleep a little while */
xtimer_usleep(DELAY);
val += step;
xtimer_usleep_until(&last, DELAY);
}
return 0;