I am struggling with combining some functions. Maybe when I write my "problem" out someone can help me setting me in the right direction.
I am trying to read a PWM signal from a RC receiver (servo). With my logic analyzer I have been finding out that the duration in ms (milliseconds) in the signal is telling me something about the position.
Then I was searching for some documentation and this article/blog
http://www.camelsoftware.com/2015/12/25/reading-pwm-signals-from-an-rc-receiver-with-arduino/
has been making me think porting this to ChibiOS and STM32L476RG.
So I get the concept and get the Arduino code. But I am struggling with interrupts in ChibiOS....
I also think I have to combine something with PWMDriver, PAL and Interrupts..... as I am using 18.2.0 (RT).
Who can help me out?
Help asked -- PAL-GPIO PWM and Interrupts
Moderators: RoccoMarco, barthess
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Help asked -- PAL-GPIO PWM and Interrupts
Hi,
You should look into the ICU driver, it measures a PWM signal using a timer returning period and duty cycle.
There are several PWM-ICU demos under ./testhal/stm32.
Moving this topic in the correct forum: STM32 support.
Giovanni
You should look into the ICU driver, it measures a PWM signal using a timer returning period and duty cycle.
There are several PWM-ICU demos under ./testhal/stm32.
Moving this topic in the correct forum: STM32 support.
Giovanni
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Help asked -- PAL-GPIO PWM and Interrupts
Hi,
Have you seen this article?
http://chibios.org/dokuwiki/doku.php?id ... interrupts
Note that in all device drivers you can find plenty examples of "real" ISRs and the enable code. In general, if you use HAL, there should not be the need to write ISRs, the drivers give you callbacks from ISRs that are normal functions.
Giovanni
Have you seen this article?
http://chibios.org/dokuwiki/doku.php?id ... interrupts
Note that in all device drivers you can find plenty examples of "real" ISRs and the enable code. In general, if you use HAL, there should not be the need to write ISRs, the drivers give you callbacks from ISRs that are normal functions.
Giovanni
Re: Help asked -- PAL-GPIO PWM and Interrupts
This code is working for me (maybe someone is helped by the post). The interrupts I still have to find out. How to use them ISR...
Code: Select all
#include "ch.h"
#include "hal.h"
#include "dspwm.h"
BaseSequentialStream *ichp;
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
icucnt_t last_width, last_period;
static void icuwidthcb(ICUDriver *icup) {
palSetLine(LINE_LED_GREEN);
last_width = icuGetWidthX(icup);
}
static void icuperiodcb(ICUDriver *icup) {
palClearLine(LINE_LED_GREEN);
last_period = icuGetPeriodX(icup);
}
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
static ICUConfig icucfg = {
ICU_INPUT_ACTIVE_HIGH,
10000, /* 10kHz ICU clock frequency. value: 10-15-19*/
icuwidthcb,
icuperiodcb,
NULL,
ICU_CHANNEL_1,
0
};
void initICUDs(BaseSequentialStream *chp)
{
palSetPadMode(stm32L476RGPwmPort1, stm32L476RGPwmPin1, PAL_MODE_ALTERNATE(1));
/*
* Starting the PWM driver 1.
*/
// pwmStart(&PWMD1, &pwmcfg); //TIMER 1!! PWMD9 = TIM9
chprintf(chp, "ICU started!\n");
ichp = chp;
icuStart(&ICUD3, &icucfg);
palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(2));
}
void readICU(BaseSequentialStream *chp)
{
icuStartCapture(&ICUD3);
icuEnableNotifications(&ICUD3);
chThdSleepMilliseconds(2000);
icuStopCapture(&ICUD3);
icuStop(&ICUD3);
//chprintf(chp, last_width);
chprintf(chp,"period: %d\r\n",last_period);
chprintf(chp,"width: %d\r\n",last_width);
chprintf(chp, "\n");
}
Who is online
Users browsing this forum: Bing [Bot] and 9 guests