2014-08-07 15:19:46 +02:00
|
|
|
/*
|
2015-10-21 12:38:21 +02:00
|
|
|
* Copyright (C) 2014-2015 Freie Universität Berlin
|
2014-08-07 15:19:46 +02:00
|
|
|
*
|
2015-10-21 12:38:21 +02: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.
|
2014-08-07 15:19:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Test for low-level PWM drivers
|
|
|
|
*
|
2015-10-21 12:38:21 +02:00
|
|
|
* This test initializes the given PWM device to run at 1KHz with a 1000 step
|
|
|
|
* resolution.
|
2014-08-07 15:19:46 +02:00
|
|
|
*
|
2015-10-21 12:38:21 +02:00
|
|
|
* The PWM is then continuously oscillating it's duty cycle between 0% to 100%
|
|
|
|
* every 1s on every channel.
|
2014-08-07 15:19:46 +02:00
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-09-03 21:36:13 +02:00
|
|
|
#include "xtimer.h"
|
2014-08-07 15:19:46 +02:00
|
|
|
#include "periph/pwm.h"
|
|
|
|
|
2015-10-21 12:38:21 +02:00
|
|
|
#define INTERVAL (10000U)
|
2014-08-07 15:19:46 +02:00
|
|
|
#define STEP (10)
|
|
|
|
|
|
|
|
#define MODE PWM_LEFT
|
|
|
|
#define FREQU (1000U)
|
|
|
|
#define STEPS (1000U)
|
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
int state = 0;
|
|
|
|
int step = STEP;
|
2015-10-21 12:38:21 +02:00
|
|
|
uint32_t last_wakeup = xtimer_now();
|
2014-08-07 15:19:46 +02:00
|
|
|
|
|
|
|
puts("\nRIOT PWM test");
|
2015-10-21 12:38:21 +02:00
|
|
|
puts("Connect an LED or scope to PWM pins to see something\n");
|
2014-08-07 15:19:46 +02:00
|
|
|
|
2015-10-21 12:38:21 +02:00
|
|
|
printf("Available PWM devices: %i\n", PWM_NUMOF);
|
|
|
|
for (int i = 0; i < PWM_NUMOF; i++) {
|
|
|
|
uint32_t real_f = pwm_init(PWM_DEV(i), MODE, FREQU, STEPS);
|
|
|
|
if (real_f == 0) {
|
|
|
|
printf("Error initializing PWM_%i\n", i);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("Initialized PWM_%i @ %" PRIu32 "Hz\n", i, real_f);
|
|
|
|
}
|
2014-08-07 15:19:46 +02:00
|
|
|
}
|
|
|
|
|
2015-10-21 12:38:21 +02:00
|
|
|
puts("\nLetting the PWM pins oscillate now...");
|
2014-08-07 15:19:46 +02:00
|
|
|
while (1) {
|
2015-10-21 12:38:21 +02:00
|
|
|
for (int i = 0; i < PWM_NUMOF; i++) {
|
|
|
|
for (uint8_t chan = 0; chan < pwm_channels(PWM_DEV(i)); chan++) {
|
|
|
|
pwm_set(PWM_DEV(i), chan, state);
|
|
|
|
}
|
2014-08-07 15:19:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
state += step;
|
|
|
|
if (state <= 0 || state >= STEPS) {
|
|
|
|
step = -step;
|
|
|
|
}
|
|
|
|
|
2015-10-21 12:38:21 +02:00
|
|
|
xtimer_usleep_until(&last_wakeup, INTERVAL);
|
2014-08-07 15:19:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|