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

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

By evesky at 一年前 , 1300 次浏览

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' was not declared in this scope

{DIO ## IO ## _WPORT |= MASK(DIO ## IO ## _PIN); }\

^

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'

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

fastio.h:34:72: error: 'DIOPUL_PIN' was not declared in this scope

{DIO ## IO ## _WPORT |= MASK(DIO ## IO ## _PIN); }\

^

fastio.h:17:26: note: in definition of macro 'MASK'

#define MASK(PIN) (1 << PIN)

^

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'

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

fastio.h:35:42: error: 'CRITICAL_SECTION_END' was not declared in this scope

CRITICAL_SECTION_END; \

^

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:38: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:39:43: error: 'DIOPUL_WPORT' was not declared in this scope

{DIO ## IO ## _WPORT &= ~MASK(DIO ## IO ## _PIN); }\

^

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'

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

fastio.h:39:73: error: 'DIOPUL_PIN' was not declared in this scope

{DIO ## IO ## _WPORT &= ~MASK(DIO ## IO ## _PIN); }\

^

fastio.h:17:26: note: in definition of macro 'MASK'

#define MASK(PIN) (1 << PIN)

^

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'

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

fastio.h:40:42: error: 'CRITICAL_SECTION_END' was not declared in this scope

CRITICAL_SECTION_END; \

^

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'

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

fastio.h:30:40: error: 'DIOPUL_WPORT' was not declared in this scope

#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)

^

fastio.h:45:105: note: in expansion of macro '_WRITE_NC'

#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:30:69: error: 'DIOPUL_PIN' was not declared in this scope

#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)

^

fastio.h:17:26: note: in definition of macro 'MASK'

#define MASK(PIN) (1 << PIN)

^

fastio.h:45:105: note: in expansion of macro '_WRITE_NC'

#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:30:97: error: 'DIOPUL_WPORT' was not declared in this scope

#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)

^

fastio.h:45:105: note: in expansion of macro '_WRITE_NC'

#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:30:127: error: 'DIOPUL_PIN' was not declared in this scope

#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)

^

fastio.h:17:26: note: in definition of macro 'MASK'

#define MASK(PIN) (1 << PIN)

^

fastio.h:45:105: note: in expansion of macro '_WRITE_NC'

#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'

编译有误。

报告将会包含更多的信息
"在编译时,输出详细信息"
在 文件>首选项 中启用

evesky medium avatar
#7 - 一年前
evesky

@Andy 我想把marlin里的步进电机控制 先移植出来控制一个步进电机,并且加上位置反馈,这样可行性大吗

Andy medium avatar
#8 - 一年前
Andy

@evesky 应该是少了一些依存文件吧,可以移植,但你需要先把各部分代码读懂才好

giveup medium avatar
#9 - 一年前
giveup

认真通读stepper.cpp比较好。需要熟悉AVR的时钟中断。

lovexingxing medium avatar
#10 - 12 个月前
lovexingxing

@evesky,请问您的这个问题解决了吗?还有speed_lookuptable_fast是怎么算出来的,该怎么用呢?先谢谢了