PWM conflict? One DC servo, one PWM fan motor

Hello all,

I am using an Arduino Nano (Chinese clone)
A 25kg 180 degree 3 wire DC hobby servo
PWM board to control car fan blower motor.
(2) DS18B20 temperature sensors

In my project, which is modified and added code from an original project by member HWHARDSOFT,
I am using a Nextion 7" touch screen with an Arduino Nano clone and 16 channel relay board to control car HVAC functions. All of the relay and temperature read functions work correctly.

PIN 9 of the Arduino is connected to the input on the PWM board for the blower motor control. (This works correctly and in the code you can see is using the timer1 library.)
PIN 10 of the arduino is connected to the 180 degree DC hobby servo to control the angle of the shaft.
Both the PWM blower motor board and DC hobby servo both have separate power supplies and also separate power supplies from the Arduino. (none currently share power)

The software libraries included are OneWire, timer1, and Servo.

All of the project functionality works correctly, until any change to the fan speed is selected, then the hobby servo for the temperature mix flap ceases to function at all until the Arduino is disconnected from power and reset. Both of the PWM functions work correctly individually.

In the reading I have done, it appears that the servo library also uses the timer1 library.
To note, when selection on, off, or a change of speed for the fan blower motor, the servo for the temperature mix flap (Which is on a different defined pin) moves.
My goal is to determine how to separate these from interfering with each other and to have both PWM functions work in harmony, without disrupting the other.

I am not well versed in multiple PWM outputs at the same time and this is the first project I have worked with of such, so there may be something obvious in my code. To note *** The original project code already had the PWM and timer1 pieces listed for the fan / blower speed controls. All I have added that seems to be of issue, is the separate temp mix flap servo code.

Thanks in advance for your time, thoughts and suggestions. Code is attached.

HVAC_ATMEGA328_6-12.ino (14.3 KB)

As a note, it appears timer1 library controls both pins 9 and 10. I will test moving servo to another pwm pin. If this is not successful, I may explore testing alternative libraries to replace the default Arduino servo library for controlling the servo.

Use of the Servo library prevents the use of analogWrite() PWM on pins 9 and 10. So you need to move the fan to another pin not the servo. Servos do not need hardware PWM enabled pins so you should be able leave that on pin 10.

Steve

There are some other servo libraries using other timers I think. The standard Servo library uses timer1
because it is 16 bit and gives the most flexible timing control (which is why it can drive upto 12
servos at once). If you are not driving 12 servos at once a different servo library may be fine.

Steve,

Thanks for the info on that.

As opposed to modding the original code with the use of the FAN on PIN 9 and timer1, etc...

I just moved the servo I was using to PIN3 that was open, set it up as a digital output and used digitalWrite with a delay microseconds, in conjunction with writing the PIN HIGH, then LOW afterwards as in the code below. Not pretty, but serves the purpose and does what I need it to do.

//temp flap servo control
void servo_control() {
if (set_in_left < 70) {
//set temp mix flap to position for max cooling
digitalWrite(SERVO_PIN,HIGH);
delayMicroseconds(2000); //close to 180 degrees shaft angle
digitalWrite(SERVO_PIN,LOW);

} else if (set_in_left > 70) {
digitalWrite(SERVO_PIN,HIGH);
delayMicroseconds(542); //close to zero degrees shaft angle
digitalWrite(SERVO_PIN,LOW);

As an update on this, I found my last attempt failed, as timer1 within the code for the fan speed seemed to be the issue. I have since removed the timer1 library and used analogWrite with values for each of the pwm fan speeds. I believe this will free up timer1 for use with the servo.h library, however the digital Write with specific delays set, appears to operate the servo just as well.
In the process, I somehow bricked my cheapo nano clone with a couple of wires that managed to short.
An Arduino Uno is on order. I was also growing tired or the random usb connectivity issues with the clone not being recognized.
I'll endeavor to persevere once the new board arrives in a few days.
Thanks guys for all of your suggestions and support!
Henry