Skip to content

bug when using normally closed switch for hard limits #60

@mstrens

Description

@mstrens

Hard limit switches are handled by interrupt.

By default GRBL uses normally open switches but the setup allows to invert the logic in order to use normally closed switches (with the parameter defined to invert limits).

Still the current version for stm32 has a bug in case of normally closed switches.
Currently the interrupts are only triggered on the falling edge. This is wrong for a normally closed switch.
It has to be triggered on the rising edge.

There is a pull request that propose to trigger on both edges but this generates another bug because interrupt is then triggered twice.

I thing that following change should be ok.
In file limit.c, there is a function void limits_init()
There is a line
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //Trigger mode, can be a falling edge trigger EXTI_Trigger_Falling, the rising edge triggered EXTI_Trigger_Rising, or any level (rising edge and falling edge trigger EXTI_Trigger_Rising_Falling)

It should be replaced by
if (bit_istrue(settings.flags, BITFLAG_INVERT_LIMIT_PINS )) { // for normally closed switches, we need to interrupt on the rising edge EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising ; //Trigger mode, can be a falling edge trigger EXTI_Trigger_Falling, the rising edge triggered EXTI_Trigger_Rising, or any level (rising edge and falling edge trigger EXTI_Trigger_Rising_Falling) } else { EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //Trigger mode, can be a falling edge trigger EXTI_Trigger_Falling, the rising edge triggered EXTI_Trigger_Rising, or any level (rising edge and falling edge trigger EXTI_Trigger_Rising_Falling) }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions