GPT Driver dynamic period

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

dynfer
Posts: 2
Joined: Sun Aug 25, 2024 6:11 pm

GPT Driver dynamic period

Postby dynfer » Sun Aug 25, 2024 6:20 pm

Hello,

I'm currently having trouble to set dynamic periods foe the GPT timer. Im trying to capture a protocol similar to UART / LIN which js called Bean MPX in Toyota cars. The implementation would require me to trigger a half bit period once a interupt happens on both edges.

I've had some success with dynamically chaning the ARR and disabling ARPE, but resulted in increased delays between the iterations. The only semi decent way was PWM and manipulating the CCR register, but trying the same on the GPT driver in continous and setting the output/capture mode didnt help.

Advice would be greatly apreciated.

User avatar
Giovanni
Site Admin
Posts: 14486
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1088 times
Been thanked: 928 times
Contact:

Re: GPT Driver dynamic period

Postby Giovanni » Sun Aug 25, 2024 6:36 pm

Hi,

Changing period is not immediate, it is "taken" on the next ARR match, probably this is what you are experiencing. You should consider doing a custom driver if you find yourself manipulating registers directly.

Giovanni

dynfer
Posts: 2
Joined: Sun Aug 25, 2024 6:11 pm

Re: GPT Driver dynamic period

Postby dynfer » Sun Aug 25, 2024 8:35 pm

Thank You Giovanni.

One question regarding the PWM setup, I assume that pwmPeriodCallback and pwmEndCallback are each called at an 100uS interval, but which one of those is afected by the CCR[0] register? I want the handle_rx functions being called at 100uS and if neccessary I would adjust the CCR to trigger it at half (50uS)?

Code: Select all

static void pwmPeriodCallback(PWMDriver *pwmp) {
    (void)pwmp;

    palSetPad(GPIOB, 5U);
    BeanMPX::handle_rx(BeanMPX::getActiveObject());
    BeanMPX::handle_rx_ack(BeanMPX::getActiveObject());
}

static void pwmEndCallback(PWMDriver *pwmp) {
    (void)pwmp;
    palClearPad(GPIOB, 5U);
}

static const PWMConfig pwmcfg = {
    48000000,
    4800,
    pwmPeriodCallback,
    {
        {PWM_OUTPUT_ACTIVE_HIGH, pwmEndCallback},
        {PWM_OUTPUT_DISABLED, NULL},
        {PWM_OUTPUT_DISABLED, NULL},
        {PWM_OUTPUT_DISABLED, NULL}
    },
    0,
    0
};


pwmstart(&PWMD3, &pwmcfg);
pwmEnableChannel(&PWMD3, 0, 4800);

User avatar
Giovanni
Site Admin
Posts: 14486
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1088 times
Been thanked: 928 times
Contact:

Re: GPT Driver dynamic period

Postby Giovanni » Mon Aug 26, 2024 6:26 am

The periodic callback is just that, periodic.

The other callback is called on the deactivation front of a PWM channel, on CCR match.

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 12 guests