GPT Driver dynamic period

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

Moderator: RoccoMarco

Post Reply
dynfer
Posts: 14
Joined: Sun Aug 25, 2024 6:11 pm
Has thanked: 2 times
Been thanked: 5 times

GPT Driver dynamic period

Post by dynfer »

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: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPT Driver dynamic period

Post by Giovanni »

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: 14
Joined: Sun Aug 25, 2024 6:11 pm
Has thanked: 2 times
Been thanked: 5 times

Re: GPT Driver dynamic period

Post by dynfer »

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: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPT Driver dynamic period

Post by Giovanni »

The periodic callback is just that, periodic.

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

Giovanni
Post Reply