Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heartbeat feature #32

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tfrog-motordriver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ include $(AT91LIB)/boards/$(BOARD)/board.mak
BIN = bin
OBJ = obj

# 1: Enabling heartbeat feature, otherwise 0
HEARTBEAT = 1

#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
Expand All @@ -94,9 +97,9 @@ INCLUDES += -I$(AT91LIB)/memories
FIRMINFO ?=

CFLAGS = -Wall -mlong-calls $(FIRMINFO) #-ffunction-sections
CFLAGS += $(CPUSPEC) $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL)
CFLAGS += $(CPUSPEC) $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) -DHEARTBEAT=$(HEARTBEAT)
CFLAGS2 = -Wall -mlong-calls $(FIRMINFO) #-ffunction-sections
CFLAGS2 += $(CPUSPEC) -O0 $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL)
CFLAGS2 += $(CPUSPEC) -O0 $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) -DHEARTBEAT=$(HEARTBEAT)
ASFLAGS = $(CPUSPEC) -O0 $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
LDFLAGS = $(CPUSPEC) -O0 -nostartfiles -Wl,--gc-sections -L$(COMPILER_PREFIX)/lib

Expand Down
12 changes: 10 additions & 2 deletions tfrog-motordriver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ int main()

// Enable watchdog
printf("Watchdog init\n\r");
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDRSTEN | 0xFF00FF; // 1s
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDRSTEN | 0x7d007d0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding, watchdog count clock is 32.768kHz divided by 128 = 256 Hz. (datasheet 15. Watchdog Timer (WDT))
0x7d0 means 7.8 seconds?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's my bad. will revert it back.

AT91C_BASE_WDTC->WDTC_WDCR = 1 | 0xA5000000;

LED_off(0);
Expand Down Expand Up @@ -655,7 +655,8 @@ int main()
// Driver loop
while (1)
{
AT91C_BASE_WDTC->WDTC_WDCR = 1 | 0xA5000000;
if (!HEARTBEAT)
AT91C_BASE_WDTC->WDTC_WDCR = 1 | 0xA5000000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The watchdog timer should be reset automatically before entering servo_level > SERVO_LEVEL_STOP.
Otherwise, the device periodically resets its-self including USB connection which is not good behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's continuously checked in timer0_vel_calc(), right?
so, you mean, it's better to switch servo_level to STOP if heartbeat doesn't arrive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the power on, servo_level goes SERVO_LEVEL_STOP until PC (yp-spur) starts communicating with the device and changes control mode to SERVO_LEVEL_TORQUE or SERVO_LEVEL_VELOCITY.

If watchdog time is not cleared automatically on SERVO_LEVEL_STOP, the device triggers reset for every watchdog duration.
This resets USB connection and make PC difficult to start the communication.

so, you mean, it's better to switch servo_level to STOP if heartbeat doesn't arrive?

That's not what I would like to say in the previous comment.
But It is sounds also good to make the device always under control. (Everything is uncontrollable during reset.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, I'm gonna stop the motor from the power cycle via a I/O pin. According to the hardware team, a corresponded pin has not been decided yet.


if (err_chk++ % 20 == 0)
{
Expand Down Expand Up @@ -826,6 +827,7 @@ int main()
if (DBGU_IsRxReady())
{
buf[nbuf] = DBGU_GetChar();

if (buf[nbuf] == '\n' || buf[nbuf] == '\r')
{
buf[nbuf] = 0;
Expand Down Expand Up @@ -860,6 +862,12 @@ int main()
USART_WriteBuffer(AT91C_BASE_US0, &buf[1], nbuf - 1);
}
break;
case 't':
{
if (HEARTBEAT)
AT91C_BASE_WDTC->WDTC_WDCR = 1 | 0xA5000000;
}
break;
}
nbuf = 0;
}
Expand Down