pwm.c

Discussions relating to development and use of the OpenServo software/firmware.

Moderators: jharvey, Secondary Admin, Admins

Post Reply
m_kanter
Posts: 31
Joined: Wed Apr 19, 2006 4:14 pm

pwm.c

Post by m_kanter » Tue Aug 25, 2009 1:21 pm

Hello,

in the pwm.c there is a comment line like this "the pwm should not changed to b-mode or brake without an proper delay"

Why is this delay needed, since delay for the h-bridge control is included above the comment?

Is this related to the rotation of the motor?

Best Regards,
Marcel

kbb
Posts: 180
Joined: Fri Jun 01, 2007 1:47 am

Re: pwm.c

Post by kbb » Tue Aug 25, 2009 5:27 pm

m_kanter wrote:Hello,

in the pwm.c there is a comment line like this "the pwm should not changed to b-mode or brake without an proper delay"

Why is this delay needed, since delay for the h-bridge control is included above the comment?

Is this related to the rotation of the motor?
The statement that follows turns off “b-modeâ€￾, the comment is merely a reminder that b-mode should not be re-enabled (which is done elsewhere) without a sufficient delay to allow the H-bridge time to change state. Ditto for “brakingâ€￾. The enabling/disabling of a-mode/b-mode is what controls the motor direction.

Kevin.

m_kanter
Posts: 31
Joined: Wed Apr 19, 2006 4:14 pm

Post by m_kanter » Wed Aug 26, 2009 6:54 am

Mmh. That's strange. Look into the code and the command is within the reconfiguration if-statement and says not to switch to the other modes:

static void pwm_dir_a(uint8_t pwm_duty)
{
// Do we need to reconfigure PWM output for direction A?
if (!pwm_a)
{ // Yes...
// NOTE: The PWM driven state of the H-bridge should not be switched to b-mode or braking
// without a suffient delay.
}
}


The delay within the switching is handled above the comment.

So why is this comment there?

kbb
Posts: 180
Joined: Fri Jun 01, 2007 1:47 am

Post by kbb » Wed Aug 26, 2009 7:46 am

m_kanter wrote:Mmh. That's strange. Look into the code and the command is within the reconfiguration if-statement and says not to switch to the other modes:

static void pwm_dir_a(uint8_t pwm_duty)
{
// Do we need to reconfigure PWM output for direction A?
if (!pwm_a)
{ // Yes...
// NOTE: The PWM driven state of the H-bridge should not be switched to b-mode or braking
// without a suffient delay.
}
}


The delay within the switching is handled above the comment.

So why is this comment there?
There are two functions: the one you are quoting, pwm_dir_a, to switch off “b-modeâ€￾ (if it is on) and switch on “a-modeâ€￾. But there is another, pwm_dir_b, which does the reverse: switches off “a-modeâ€￾ (if it is on) and switches on “b-modeâ€￾.

Both contain the delay that is needed between switching off one mode and a switching on the other.

Both contain the comment that appears as a reminder that there must be a delay between mode switching.

The delay is important as it prevents “brownoutsâ€￾ and stress on the MOSFETs that are used to implement the H-bridge. The stress on the MOSFETs can cause them to heat up (more so than they would normally do) and could potentially lead to damage.

Thus I felt the need to add that comment as a reminder at the point where a particular mode had finally been switched off. In pwm_dir_a for example, you will see that “b-modeâ€￾ has been switched off, and “a-modeâ€￾ switched on. The comment is there to remind the reader that there must be a delay before reversing this. And in pwm_dir_b it is the other way around. If the comment is confusing it could be moved, changed or deleted.

An in-line delay has been used because of the way the original code was written.

Kevin.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests