123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #include "ch.h"
- #include "hal.h"
- static void pwmpcb(PWMDriver *pwmp) {
- (void)pwmp;
- }
- static void pwmc1cb(PWMDriver *pwmp) {
- (void)pwmp;
- }
- static PWMConfig pwmcfg = {
- 10000,
- 10000,
- pwmpcb,
- {
- {PWM_OUTPUT_ACTIVE_HIGH, pwmc1cb},
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL}
- },
- 0,
- 0
- };
- icucnt_t last_width, last_period;
- static void icuwidthcb(ICUDriver *icup) {
- palSetLine(LINE_ARD_D13);
- last_width = icuGetWidthX(icup);
- }
- static void icuperiodcb(ICUDriver *icup) {
- palClearLine(LINE_ARD_D13);
- last_period = icuGetPeriodX(icup);
- }
- static void icuovfcb(ICUDriver *icup) {
- (void)icup;
- }
- static ICUConfig icucfg = {
- ICU_INPUT_ACTIVE_HIGH,
- 10000,
- icuwidthcb,
- icuperiodcb,
- icuovfcb,
- ICU_CHANNEL_1,
- 0
- };
- int main(void) {
-
- halInit();
- chSysInit();
-
- pwmStart(&PWMD1, &pwmcfg);
- pwmEnablePeriodicNotification(&PWMD1);
- palSetLineMode(LINE_ARD_D5, PAL_MODE_ALTERNATE(1));
-
- icuStart(&ICUD2, &icucfg);
- palSetLineMode(LINE_ARD_D9, PAL_MODE_ALTERNATE(1));
-
- palClearLine(LINE_ARD_D13);
- palSetLineMode(LINE_ARD_D13, PAL_MODE_OUTPUT_PUSHPULL);
- chThdSleepMilliseconds(1000);
-
- icuStartCapture(&ICUD2);
- icuEnableNotifications(&ICUD2);
-
- while (true) {
-
- pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500));
- pwmEnableChannelNotification(&PWMD1, 0);
- chThdSleepMilliseconds(5000);
-
- pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
- chThdSleepMilliseconds(5000);
-
- pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 2500));
- chThdSleepMilliseconds(5000);
-
- pwmChangePeriod(&PWMD1, 5000);
- chThdSleepMilliseconds(5000);
-
- pwmDisableChannel(&PWMD1, 0);
- }
- }
|