After removing a lot of delays, i have still been unable to fix the PWM output. It is getting interrupted by something.
The problem could be anywhere. I modified the AFMotor library to use analog pins with the motor shield. The only other wires to the shield are PWM pin 5 and 5v + GND.
LCD Keypad shield is using LiquidCrystal lcd(10, 12, 6, 7, 8, 9); Motor shield is using pin 5 for PWM, 4 analog pins (15-18 or analog 1-4, CLK, ENABLE, DATA, LATCH) Temp sensor is using digital pin 2
Using a test sketch and the same AFMotor library, the motor runs fine at speed 50, but speed even as high as 196 in the dodgy sketch will not run the fan. The fan seems to be pulsating backwards and forwards, even after making forward the only possible option in the library, as well as 50 being minimum possible speed.
The library was tested after all modifications, with a minimal test sketch, and worked every time at speeds 50 and 255.
I would appreciate any advice.