2014-11-18 12:25:27 +01:00
|
|
|
/*
|
2015-12-08 01:13:35 +01:00
|
|
|
* Copyright (C) 2014-2016 Freie Universität Berlin
|
2014-11-18 12:25:27 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-12-08 01:13:35 +01:00
|
|
|
* @ingroup tests
|
2014-11-18 12:25:27 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Test case for the low-level DAC driver
|
|
|
|
*
|
|
|
|
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-09-03 21:36:13 +02:00
|
|
|
#include "xtimer.h"
|
2014-11-18 12:25:27 +01:00
|
|
|
#include "periph/dac.h"
|
|
|
|
|
|
|
|
|
2015-12-08 01:13:35 +01:00
|
|
|
#define DELAY (100U)
|
|
|
|
#define STEPS (1000U)
|
2014-11-18 12:25:27 +01:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2016-07-05 21:32:44 +02:00
|
|
|
xtimer_ticks32_t last = xtimer_now();
|
2015-12-08 01:13:35 +01:00
|
|
|
uint16_t val = 0;
|
|
|
|
uint16_t step = 0xffff / STEPS;
|
2014-11-18 12:25:27 +01:00
|
|
|
|
|
|
|
puts("\nRIOT DAC peripheral driver test\n");
|
2015-12-08 01:13:35 +01:00
|
|
|
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");
|
2014-11-18 12:25:27 +01:00
|
|
|
|
2015-12-08 01:13:35 +01:00
|
|
|
/* initialize all DAC lines */
|
2014-11-18 12:25:27 +01:00
|
|
|
for (int i = 0; i < DAC_NUMOF; i++) {
|
2015-12-08 01:13:35 +01:00
|
|
|
if (dac_init(DAC_LINE(i)) < 0) {
|
|
|
|
printf("Error initializing DAC_LINE(%i)\n", i);
|
2014-11-18 12:25:27 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
2015-12-08 01:13:35 +01:00
|
|
|
printf("Successfully initialized DAC_LINE(%i)\n", i);
|
2014-11-18 12:25:27 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-08 01:13:35 +01:00
|
|
|
puts("");
|
2014-11-18 12:25:27 +01:00
|
|
|
|
2015-12-08 01:13:35 +01:00
|
|
|
/* create saw tooth signal */
|
2014-11-18 12:25:27 +01:00
|
|
|
while (1) {
|
|
|
|
for (int i = 0; i < DAC_NUMOF; i++) {
|
2015-12-08 01:13:35 +01:00
|
|
|
dac_set(DAC_LINE(i), val);
|
2014-11-18 12:25:27 +01:00
|
|
|
}
|
2015-12-08 01:13:35 +01:00
|
|
|
val += step;
|
2016-07-07 16:15:33 +02:00
|
|
|
xtimer_periodic_wakeup(&last, DELAY);
|
2014-11-18 12:25:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|