Faking PWM using ON/OFF -> fan control

Hi there,

I'm controlling a set of 30 fans by sending an array of 30 on/off values to a chip (MM5450) which are triggered by people walking past the ultrasonic sensors. I would like to increase the strength as people get closer to it and slower decrease the power as they leave.

As I understand it the logic might be as follows:

  • If distance of left sensor is between 300 & 400 send ON every 10 cycles
  • If distance of left sensor is between 200 & 300 send ON every 5 cycles
  • If distance of left sensor is between 100 & 200 send ON every 3 cycles
  • If distance of left sensor is between 0 & 100 send ON every cycles

Could anyone point out what this would look like in programming language?
Can it be done is a less incremental/linear manner?

Thanks in advance,
Charles

CharlesDesign:
Can it be done is a less incremental/linear manner?

  cyclesPerOn = distance / 40;

The above will give you a less incremental transition but it's still very inear.

You have to have OFF signals as well to create PWM. When are they going to happen?

You could have a series of IF/ELSE statements like this

if (sensorVal > 300) {
   numCycles = 10;
}
else if (sensorVal > 200) {
   numCycles = 5;
}
else if (sensorVal > 100) {
   numCycles = 3;
}
else {
   numCycles = 0;
}

Do you want all the fans to run at the same speed?

...R

Thanks for your reply however how would numCycles be applied to turn the fans off & on every x frames?

For now I'm trying to get only the fans closest to the sensor in question. After this ideally I'd like to create a "wave" pattern.

CharlesDesign:
how would numCycles be applied to turn the fans off & on every x frames?

That was my first question to you in Reply #2

How do you think it might be done?

In any case, what do YOU mean by a "cycle"?

...R