L293D chip and PWM (for forward/backward)

Hi,
I've got an L293D, and I want to run 1 motor, the left one, in forward and reverse at a lower speed using PWM. I'm 100% sure I have got all the wires hooked up properly.

My setup is basically a 12v power supply between pin 8 of the chip to ground of the arduino. I have pin 2 and 7 (input) of the chip to pin 7 and 8 of the arduino. And the enable pin 1 of the chip to pin 9 (PWM) of the arduino. All 4 grounds of chip are grounded to arduino. Pin 16 (vss) is to 5v of arduino. And pin 3 and 6 (output) of chip connected to small dc motor.

I am using a basic code just to run the left motor by itself in forward and reverse which works perfect. I understand that its changing pin 7 and 8 on arduino from + to - and vise versa depending on which direction. Heres the code anyway:

const int Motor1Pin1 = 7;
const int Motor1Pin2 = 8;

void setup() {                
  pinMode(Motor1Pin1, OUTPUT);   
  pinMode(Motor1Pin2, OUTPUT);     
}


void loop() {
  GoForward();
  delay(2000);
  GoBackward();
  delay(2000);
        
}

void GoForward(){
  digitalWrite(Motor1Pin2, LOW);
  digitalWrite(Motor1Pin1, HIGH);
}

void GoBackward(){
  digitalWrite(Motor1Pin1, LOW);
  digitalWrite(Motor1Pin2, HIGH);
}

So my question is, how do I use this enable pin 1 for PWM? What happens to pins (input from chip) 7 and 8 on arduino when I want to use PWM? I have the enable pin 1 to pin 9 on the arduino. Could someone please tell me what part of the code would need to be changed if I want to run the left motor forward and then backward at say 150. Similar to the sketch above but using PWM.

I have tried experimenting with making an 'int' of pwmpin, setting it to output, and using analogWrite(pwmpin, 150); while having digitalWrite(motor1pin1, LOW), changing it from low to high, and the motor1pin1 to pin2 but I'm quite new to programming so I don't really know the way to go about it.

Once I have a basic code, it will help me understand it better because I can see it in front of me and then I can then study the layout of the sketch and experiment with it.

I have searched these forums and google of what I am after but cant find anything that explains well enough what happens to the input pins (as in are they high or low) and enable pin and the code to go with it.

Sorry for the long post and hope someone can help, thanks in advance.

Cheers!

Pin 16 (vss) is to 5v of arduino.

Isn't vss normally ground ?

The motor will not run, unless the enable pin is high ( logical one ). You set the direction by setting either one of the other two control pins high, and the other one to low. If you set the two control pins both high, or both low, you get non-powered "coasting" or "braking" behaviour.

Then you set the enable pin high to turn it on. Or put pwm on the enable pin to turn it partly on. If the enable pin is low, then it won't run.

Pin 16 ( Vss ) on the chip is 5V. It's OK. I don't know why they use this bogus terminology.

I kind of understand what you are saying, but even when I pull the enable pin out completely, the motor still runs. Having the 2 control pins set to 1 HIGH/1 LOW. I tried int pwm = 9 before void setup, then pinmode pwm output in setup (also digitalWrite pwm HIGH, not sure if this is the right spot to put it) and analogWrite pwm 150 in void loop before the other code. And I can still remove the enable pin and the motor still runs (with the control pins 1 HIGH/1 LOW). Do you have the correct part of code to put in to make the enable pin work?