DC motor control with monitor weird monitor problem

A code to run two DC motors, That is nothing wrong when uploading. But there is problem at the monitor. Please tell me what I do wrong.
Here is code.

int val = 500;//forward speed
int VAL = 700;
int delaytime = 250;
int i;
void setup() 
{
    Serial.begin(9600); // setup serial 

 pinMode(7,OUTPUT);
 pinMode(8,OUTPUT);
 pinMode(9,OUTPUT);
 pinMode(10,OUTPUT);
 pinMode(11,OUTPUT);
 pinMode(12,OUTPUT);
}

void loop() 
{
  for( i=1; i<=10; i++)
{
  Serial.print("i=");
  Serial.println(i);
  digitalWrite(7,LOW);
  digitalWrite(8,HIGH);
  analogWrite(9,val);
 
  digitalWrite(10,LOW);
  digitalWrite(11,HIGH);
  analogWrite(12,VAL);

}
}

Here is the monitor shows,

i=1
ertion "duty <= pPwm->PWM_CH_NUM[ul_channel].PWM_CPRD" failed: file "../source/pwmc.c", line 272, function: PWMC_SetDutyCycle
Exiting with status 1.

What you describe as what the monitor shows has not been produced by your program as none of the text is included as a Print statement in the program.

To be honest it looks like a compiler error message from a different program.

You need to describe more fully what you do to reproduce the problem. You have not even told us what Arduino board you are using.

...R

int val = 500;

What are you trying to run this on?

Which Arduino board are you using ?
How are the motors connected to the Arduino ?
How are the motors powered ?
When and where exactly do you see the message ?

I use DUE to control DC motor. pin 9 and pin 12 are for speed control. the message is sent by monitor.

Are you missing an analogWriteResolution() ?

the message is sent by monitor.

When ?
At startup ?
Later ?
What values of i does it print ?

UKHeliBob:
When ?

After i = 1, so in loop()

I set wrong speed value. speed value should not be larger than 255. I forget about that. Thanks for everyone's answer.

int val = 500;//forward speed
int VAL = 700;

Above code should be changed into this code:

int val = 200;//forward speed
int VAL = 200;

Hi,
Does your code work now?
Have you checked how to use analogWrite and PWM on a DUE controller?

Thanks.. Tom.. :slight_smile:

I still have problem but the problem maybe related to hardware. It seems like the code should be worked. Yes, I check it and know that I set analogWrite() value much bigger than it should be.