help with soft pwm for motorized chair

I have this code that controls my motorized chair
and I don't know how to program
but I need a pwm with smooth rise and fall, so there are no jumps in the engines
someone help me please?

//usar defines nao gasta memoria RAM no armazenamento das
//constantes do programa.

#define portaH_1a 11
#define portaH_1b 10

#define portaH_2a 5
#define portaH_2b 6

#define potpin A0
#define potpin2 A3

int led = 3;

int val_pot_1;
int val_pot_2;

int pwm_1_a;
int pwm_1_b;

int pwm_2_a;
int pwm_2_b;

void setup()
{
Serial.begin(9600);

//seta os modos dos pinos
pinMode( portaH_1a, OUTPUT );
pinMode( portaH_2a, OUTPUT );
pinMode( portaH_1b, OUTPUT );
pinMode( potpin, INPUT );
pinMode( potpin2, INPUT );
pinMode( led, OUTPUT );
}

void loop()
{
//leitura do potenciometro
val_pot_1 = analogRead(potpin);
val_pot_2 = analogRead(potpin2);

//mapeamento para 0-511 pino A - 512-1023 pino B
pwm_1_a = map(val_pot_1, 0, 511, 255, 0);
pwm_1_b = map(val_pot_1, 512, 1023, 0, 255);

//mapeamento da ponte 2
pwm_2_a = map(val_pot_2, 0, 511, 255, 0);
pwm_2_b = map(val_pot_2, 512, 1023, 0, 255);

//proteçes
if (val_pot_1 > 511)
pwm_1_a = 0;
else
pwm_1_b = 0;

if (val_pot_2 > 511)
pwm_2_a = 0;
else
pwm_2_b = 0;

if (pwm_1_a > 5) //controle freio
{
digitalWrite(led, HIGH); //aciona freio
}
else if (pwm_1_b > 5) {
digitalWrite(led, HIGH);
}
else if (pwm_2_a > 5) {
digitalWrite(led, HIGH);
}
else if (pwm_2_b > 5) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW); //desliga freio
}

if ( pwm_1_a < 8) pwm_1_a = 0;
if ( pwm_2_a < 8) pwm_2_a = 0;
if ( pwm_1_b < 8) pwm_1_b = 0;
if ( pwm_2_b < 8) pwm_2_b = 0;

//Atualiza portas da ponte H1
analogWrite(portaH_1a, pwm_1_a);

analogWrite(portaH_1b, pwm_1_b);

//Atualiza portas da ponte H2
analogWrite(portaH_2a, pwm_2_a);

analogWrite(portaH_2b, pwm_2_b);

}

So, this is what happens when you don't use code tags:
nocodetags.jpg
It should look like this:

  if ( pwm_1_a < 8) pwm_1_a = 0;
  if ( pwm_2_a < 8) pwm_2_a = 0;
  if ( pwm_1_b < 8) pwm_1_b = 0;
  if ( pwm_2_b < 8) pwm_2_b = 0;

nocodetags.jpg

and I don't know how to program
but I need a pwm with smooth rise and fall, so there are no jumps in the engines
someone help me please?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.