MakerLab创客实验室 — Let's Make something.
现在注册
已注册用户请 登入
evesky large avatar
MakerLab创客实验室  ›  问题解答

马琳固件里的中断产生步进脉冲 WRITE()有懂得吗?

By evesky at 一年前 , 1572 次浏览

fastio.h
#define _WRITE_NC(IO, v) do { if (v) {DIO ## IO ## _WPORT |= MASK(DIO ## IO ## _PIN); } else {DIO ## IO ## _WPORT &= ~MASK(DIO ## IO ## _PIN); }; } while (0)

#define WRITE_C(IO, v) do { if (v) { \
CRITICAL_SECTION_START; \
{DIO ## IO ## _WPORT |= MASK(DIO ## IO ## _PIN); }\
CRITICAL_SECTION_END; \
}\
else {\
CRITICAL
SECTION_START; \
{DIO ## IO ## _WPORT &= ~MASK(DIO ## IO ## _PIN); }\
CRITICAL_SECTION_END; \
}\
}\
while (0)

#define WRITE(IO, v) do { if (&(DIO ## IO ## RPORT) >= (uint8_t *)0x100) {_WRITE_C(IO, v); } else {_WRITE_NC(IO, v); }; } while (0)
#define WRITE(IO, v) _WRITE(IO, v)
stepper.cpp
counter
x += current_block->steps_x;
if (counter_x > 0) {
WRITE(X
STEP_PIN, !INVERT_X_STEP_PIN);
counter_x -= current_block->step_event_count;
count_position[X_AXIS]+=count_direction[X_AXIS];
WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
}

步进电机不是脉冲控制嘛,它两个WRITE()函数中间几乎没有时间间隔,是如何产生脉冲的?WRITE()函数不懂,请大神指点下

10 回复
hy1066994565 medium avatar
#2 - 一年前
hy1066994565

同问啊,这个也一直弄不明白啊,@Andy

Andy medium avatar
#3 - 一年前
Andy

@hy1066994565 没错是脉冲,但是严格来说是上升沿,也就是一个高电平,马上拉低就可以被识别。
这里的WRITE就是一个改IO电平的函数而已,没什么神奇的,在脉冲中断函数中,WRITE(Pin,HIGH);然后又写了WRITE(Pin,LOW);所以就实现了脉冲

evesky medium avatar
#4 - 一年前
evesky

@Andy WRITE(Pin,HIGH);WRITE(Pin,LOW)这两个语句不会因为时间太短而不被识别吗? 还有就是 我把marlin的fastio.h和pins.h都加入到我的程序里了 为什么 我只要写WRITE();,程序就会报错呢

Andy medium avatar
#5 - 一年前
Andy

@evesky 会不会被识别要看步进电机驱动芯片的参数,大部分都可以识别。实在不行可能需要加些许延时。把错误信息发上来

evesky medium avatar
#6 - 一年前
evesky

@Andy
Arduino:1.7.4 (Windows 7), 板:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from sketch_aug07a_ISR.ino:2:0:


sketch_aug07a_ISR.ino: In function 'void __vector_17()':

fastio.h:45:36: error: 'DIOPUL_RPORT' was not declared in this scope

#define _WRITE(IO, v) do { if (&(DIO ## IO ## _RPORT) >= (uint8_t *)0x100) {_WRITE_C(IO, v); } else {_WRITE_NC(IO, v); }; } while (0)

^

fastio.h:68:23: note: in expansion of macro '_WRITE'

#define WRITE(IO, v) _WRITE(IO, v)

^

sketch_aug07a_ISR.ino:73:3: note: in expansion of macro 'WRITE'

fastio.h:33:42: error: 'CRITICAL_SECTION_START' was not declared in this scope

CRITICAL_SECTION_START; \

^

fastio.h:45:80: note: in expansion of macro '_WRITE_C'

#define _WRITE(IO, v) do { if (&(DIO ## IO ## _RPORT) >= (uint8_t *)0x100) {_WRITE_C(IO, v); } else {_WRITE_NC(IO, v); }; } while (0)

^

fastio.h:68:23: note: in expansion of macro '_WRITE'

#define WRITE(IO, v) _WRITE(IO, v)

^

sketch_aug07a_ISR.ino:73:3: note: in expansion of macro 'WRITE'

fastio.h:34:43: error: 'DIOPUL_WPORT