mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
e381317fbf
cpu, nrf5x_common: fix sign-compare in periph/flashpage drivers, periph_common: fix sign-compare in flashpage cpu, sam0_common: fix sign-compare error in periph/gpio cpu, cc2538: fix sign-compare in periph/timer cpu, sam3: fix sign-compare in periph/gpio cpu, stm32_common: fix sign-compare in periph/pwm cpu, stm32_common: fix sign-compare in periph/timer cpu, stm32_common: fix sign-compare in periph/flashpage cpu, nrf5x_common: fix sign-compare in radio/nrfmin cpu, samd21: fix sign-compare in periph/pwm cpu, ezr32wg: fix sign-compare in periph/gpio cpu, ezr32wg: fix sign-compare in periph/timer drivers, ethos: fix sign-compare sys, net: fix sign-compare cpu, atmega_common: fix sign-compare error cpu, msp430fxyz: fix sign-compare in periph/gpio boards, msb-430-common: fix sign-compare in board_init driver, cc2420: fix sign-compared sys/net: fix sign-compare in gnrc_tftp driver, pcd8544: fix sign-compare driver, pn532: fix sign-compare driver, sdcard_spi: fix sign-compare tests: fix sign_compare sys/net, lwmac: fix sign_compare pkg, lwip: fix sign-compare boards, waspmote: make CORECLOCK unsigned long to fix sign_compare error tests, sock_ip: fix sign compare tests, msg_avail: fix sign compare tests, sock_udp: fix sign compare boards: fix sign-compare for calliope and microbit matrix
80 lines
1.9 KiB
C
80 lines
1.9 KiB
C
/*
|
|
* Copyright (C) 2014-2015 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 details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup tests
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief Test for low-level PWM drivers
|
|
*
|
|
* This test initializes the given PWM device to run at 1KHz with a 1000 step
|
|
* resolution.
|
|
*
|
|
* The PWM is then continuously oscillating it's duty cycle between 0% to 100%
|
|
* every 1s on every channel.
|
|
*
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "xtimer.h"
|
|
#include "timex.h"
|
|
#include "periph/pwm.h"
|
|
|
|
#define INTERVAL (10LU * US_PER_MS) /* 10 ms */
|
|
#define STEP (10)
|
|
|
|
#define MODE PWM_LEFT
|
|
#define FREQU (1000U)
|
|
#define STEPS (1000U)
|
|
|
|
|
|
int main(void)
|
|
{
|
|
int state = 0;
|
|
int step = STEP;
|
|
xtimer_ticks32_t last_wakeup = xtimer_now();
|
|
|
|
puts("\nRIOT PWM test");
|
|
puts("Connect an LED or scope to PWM pins to see something\n");
|
|
|
|
printf("Available PWM devices: %i\n", PWM_NUMOF);
|
|
for (unsigned 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_%u\n", i);
|
|
return 1;
|
|
}
|
|
else {
|
|
printf("Initialized PWM_%u @ %" PRIu32 "Hz\n", i, real_f);
|
|
}
|
|
}
|
|
|
|
puts("\nLetting the PWM pins oscillate now...");
|
|
while (1) {
|
|
for (unsigned 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);
|
|
}
|
|
}
|
|
|
|
state += step;
|
|
if (state <= 0 || state >= (int)STEPS) {
|
|
step = -step;
|
|
}
|
|
|
|
xtimer_periodic_wakeup(&last_wakeup, INTERVAL);
|
|
}
|
|
|
|
return 0;
|
|
}
|