PWM issue

Question:

It would be difficult to run this code but maybe you could just look at it.

It simply PWMs a motor to make it go up and down. Whats weird is that a PWM of less than 130 works fine but if I PWM it above that, it locks up my h-bridge motor controller trying to make it go up and down at the same time. A green light on the H-bridge turns on for up and a red light turns on for down. Both lights come on when it locks up.

Maybe its something simple.

===========================================
void Output() //Turns motors on/off based on Gate Control Output
{

if(digitalRead(Maintenance_Switch)==1) //OFF
{
if(gate_control_output ==1)//on - gate goes up
{
if(Degrees <= (90))
{
analogWrite(Motor_Up_Control,130);
}

else
{
analogWrite(Motor_Up_Control,0);
}
}
else //gate_control_output)==0) //Off, gate goes down
{

if(Degrees >=(1))
{
analogWrite(Motor_Down_Control,130);
}

else
{
analogWrite(Motor_Down_Control,0);

}
}
}

}

If you can't read the posting rules why should any one read your code?

Use code tags or at least for, me go else where!

Or problem is simple you just don't red the instructions

Mark

I can't be sure because you haven't posted the full code and connections for your h-bridge.

But you aren't setting both PWMs in both branches. If Motor_Up_Control is set to 130, and later on you take the down branch, you haven't cleared Motor_Up_Control back to 0?

Please use code tags.

Read this before posting a programming question

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>

http://snippets-r-us.com/

What the experts are trying to tell you is, that they cant read your code unless you follow the forum rules.
As I can read read from your code, its most likely you have a problem with your motor direction control as soon as you reach a few bits more than half the full PWM setting of 255.

void Output() //Turns motors on/off based on Gate Control Output
{
  if (digitalRead(Maintenance_Switch) == 1) //OFF
  {
    if (gate_control_output == 1) //on - gate goes up
    {
      if (Degrees <= (90))
      {
        analogWrite(Motor_Up_Control, 130);
      }
      else
      {
        analogWrite(Motor_Up_Control, 0);
      }
    }
    else   //gate_control_output)==0) //Off, gate goes down
    {
      if (Degrees >= (1))
      {
        analogWrite(Motor_Down_Control, 130);
      }
      else
      {
        analogWrite(Motor_Down_Control, 0);
      }
    }
  }
}

holmes4:
If you can’t read the posting rules why should any one read your code?

Use code tags or at least for, me go else where!

Or problem is simple you just don’t red the instructions

Mark

What a lovely comment !
So friendly and exactly right in the heart of the idea of the worldwide Arduino Community.

As I have told you before Mark, try use a mature language and gain some respect.

Thanks Anders53,

We are all just trying to learn the system and work together. I appreciate your comment.

I understand, I could have done a better job.

Sid

We would have less of this bickering if new posters had the courtesy to read the forum posting guidelines before posting. The reason my response above was reasonably polite was I have to say it so many times a day that I have made a button on my Leonardo to do a “canned response”.

I notice the original post has not yet been modified, so the OP has chosen to ignore my request. I’ll repeat it:

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>