電子工作99 – 4個のタイマー付き、USB扇風機用の5段階速度コントローラーの製作

Electronics Project 99 – Making 5-Step Speed Controller with 4 Timers for USB Fans

 

 

概要   Introduction

   前の電子工作98では、扇風機の回転速度を4段階に変えられたが、今回は5段目を加え、しかも、その中で回転がON/OFFを繰返すようにした。更に、新たに12F629(2)を加えてタイマー機能を持たせた。すなわち、タイマーはAlways ON (常時ON)、30min、2hour、5hour (それぞれ、30分、2時間、5時間後にOFFになる)の4個から選択出来る。これで、大分市販の大型扇風機のコントロール機能に似て来た。暑い夏に寝床で頭上から吊るして使おうと思っている

 

In this Electronics Project 99, a 4-step timer function using another 12F629 (2) was added to that of the previous E.Project 98, so you can choose one out of the four time modes at one time - Always ON, 30 min, 2 hour and 5 hour, by rotating the left-hand Rotary SW (Refer to Photo showing Side view of Plastic box). If you change the time mode from A to B while A is functioning, B starts counting from zero. When 30-min, 2-hour or 5-hour time mode is up and thereby stopping the fan, for restarting it, press Reset button. The timer restarts with the same time mode. The timer based on 12F629 (2) controls the supply of 5V current from USB Power source to the terminals of the right-hand Rotary SW and to 12F629 (1) through Photomos relay TLP241A (max 2A). In addition, a new position 5 was created on the Rotary SW of 12F629 (1), at which the fan rotates intermittently, that is, it rotates for 56 seconds and then stops for 25 seconds (this repetitive pattern is changeable in the program).

I am planning to use this 4-inch USB fan and its control system, especially using the newly created Position 5 of Rotary SW, for cooling my face and head when I am sleeping on my back during the hot and humid summer time in Tokyo.

 

 

The following part has already been described in Introduction of Electronics Project 98 – I will include this for later reference.


The 4-step speed controller prepared this time is used for controlling the rotational speed of USB fans (DC5V) with a diameter of 14 - 15 cm that consume about 300mA. For the purpose, the controller uses a 12F629, a mosfet transistor and a rotary switch (2 pole 6 positions). The control of the rotational speed of fan is based on changing PWM (Pulse Width Modulation) values, which are produced by using a command (software PWM) of PicBasic Pro. If the 12 pins of the rotary switch are connected as shown in Circuit Diagram, 5V power is supplied to 12F629 only when Pole 1 is in one of 4 positions CT1 - CT4 but no power is supplied to 12F629 when Pole 1 is in one of the two remaining positions (which are not connected). As Pole 1 and Pole 2 are connected to the same shaft and move together, when the position of Pole 1 is CT1, the position of Pole 2 is PCT1. Similarly, CT2 corresponds to PCT2, and so forth. In the program below, in the command 'PWM Pin, duty, cycle’, duty is duty ratio, determining the magnitude of power output supplying to fan motor. The duty ratios (255, 248, 235, 220) are used in the individual switch positions, where 255 corresponds a duty ratio of 100%, 248 to 97%, 235 to 92% and 220 to 88%. The larger the duty ratio, the more power is supplied to fan motor. Therefore, the position CT1 produces the highest rotational speed, followed by CT2, CT3 and CT4, in that order. These duty-ratio values were decided by trial and error while observing the airflow from the fan. I experienced a problem that the fan did not start to rotate at the positions of CT3 and CT4. This problem was solved with the addition of an extra routine in the program, namely, PWM with a larger duty ratio 248/97% is applied for 100ms for those two switch positions, enabling the fan to start at both CT3 and CT4 positions.

 


回路図   Circuit Diagram

  今回は、前回のものに12F629(2)を加えることによってUSB扇風機の電源を一定時間後にOFFにするタイマー機能を実現した。タイマーの時間はソフト的に作成し、GP0(ピン7)からフォトモスリレー(電子リレー)で下のロータリースイッチ端子(PCT1―PCT5)に送る電流をON/OFFして機能させる。一方、ロータリースイッチ端子CT5とPCT5の組合せは新たに追加されたもので、間欠タイマー(ON/OFFを繰返す)になっている。ONとOFFの時間プログラムの中で自由に決められる。


 

    今回製作した装置: 前回の装置にタイマー機能を追加した。12F629(2)とフォトモスリレー(写真中央左側)の2個のICがその役目を担う。このフォトモスリレーTLP241Aは2Aまでの電流を流せる。空中配線がちょっと多いが、素人ぽくって良いのでは?

Controller circuit with newly added timer function packed in plastic box

 

プラスチックボックスの横面: 左側はタイマーツマミでAlways ON(常時接続)、30min、2h、5hと4個の時間が選べる。時間が来ると電流の供給がOFFになる。右側のものは前回のように、1−4は回転速度が最大から最小に対応し、5ON/OFFは新たに加えたもので回転が間欠的にON/OFFするモード(大体56秒間回転し、25秒間停止の繰り返し)である。タイマーの時間が来て扇風機が止まった時は、Resetスイッチを押して再起動させる。ある時間モード、例えば30minで動作している時に、ツマミを他の2hや5hに変えた場合、それぞれの時間モードで0からカウントが始まる。6の位置に回すと12F629へ電源供給は停止し、LEDも消える。右端から2番目のものは電源SW。

Side view of Plastic box. You can see two Rotary SWs, Power SW and Reset SW. The left Rotary SW (Timer) has Always ON, 30min, 2hour and 5hour time modes, while the right Rotary SW (Speed) has 1 (fastest) to 4 (slowest) as well as the newly added 5 (On/OFF intermittent time mode). When time is up, press Reset button to restart the same time mode. You can change the time mode from A to B while A is counting down, enabling B to start counting up from zero.

 

装置をUSB扇風機と組合せて使ってみているところ

Controller driving a USB fan

 

ロータリーSWの位置USB扇風機に消費される電流の関係

Relationship between Position of Rotary SW and Current Consumption by System

ロータリーSWの位置

Position of Rotary SW

消費電流

Current consumption

(mA)

1

310-320

2

240

3

190

4

170

 5*

140(ON)-30(OFF)

* 間欠モード   intermittent mode

 

結果&コメント

1)     新たに加えたタイマーが正常に4段階で機能することが確認された。

2)     回転速度コントローラーに扇風機の回転がON/OFFを繰返す間欠モードを新たに加えた。

3)     今回の回路にUSB扇風機(4インチのノーブランド、秋葉原で¥300―500で出回っている)を接続して、各ツマミ位置でのシステム全体の電流消費を測ったものを上の表に示す。プログラムに細工を加えたお陰で、ツマミ位置5の低電流でも確実に扇風機は起動する。

4)     寝にくい夏の夜に、保冷剤枕とこのUSB扇風機を寝床で頭上に吊るして顔や頭部を冷やせば効果抜群、快適に熱帯夜も乗り切れるだろう。

5)     USB扇風機とUSB ACアダプタを除いた費用は大体1000円ほど。

6)     テフロン被覆単線の宮中配線が見事だが?工夫すればもっときれいに仕上がるかも。

7)     フォトモスリレーTLP241Aの容量は2Aなので、一回り大きいUSB扇風機(1480円とかで売っている)もそのまま接続出来そう。

8)     ワイヤレス方式も面白そう。

9)     今回も、ハードとソフトの両方で脳トレをさせて貰った、謝謝!

 

 

プログラム   Program

USB扇風機のDCモーターの回転をPWM(Pulse Width Modulation パルス幅変調)というテクニックを使って制御することにした。幸いPicBasic Proには、専用のコマンドがあり、これを使うといとも簡単にパルス幅変調が出来てしまう。PWM Pin, Duty, CycleとゆうコマンドのPinは出力するピン、DutyはDuty比のことで出力パワーの大きさを、そして、Cycleは何Cycle数出力するかを決める係数で、PICが4MHzで動作している場合1Cycleは5msなので、例えば、200(cycles)を入れると5msX200/sec=1000ms/secとパルスが繰り返し1秒間出力されることになる?。なお、今回使った回転速度に関係するDuty比の値(255、248、235、220,、190)は風量を観察しながら試行錯誤方式で決めた回転速度が遅い方から3接点の各位置で、停止から電源SWを入れると扇風機が回転しないことがあり、この問題を解決する為に100msという短い時間PWMのパルス幅を狭くして電流量を一時的に増やすようにしているこれで確実に回転するようになった。つまり、プログラム中に、この部分n=n+1、If n=1 Then Gosub Startup、PWM GPIO.5,235,100、n=n+1 を追加して目的を達した。

 

前回と比べて違うことは、ON/OFFを繰返す間欠モード(ロータリーSWの5/ON/OFF)をプログラムに加えたこと。PWM30tから始まる7行で、その中のIf n=120 Then Gosub Tempstop でTempstopというサブルーチンに飛んで30秒間(実測では25秒間ほど)扇風機に一時停止をさせている。

'***********************************************

‘For 12F629 (1)

'USBFanSpeedControllerB.bas  2017.6.28 works!

'Using 12F629 and PicBasic Pro V2.50A

'Internal 4MHz clock used

'***********************************************

'Pin 1: Vdd(3V)

'Pin 8: Vss(GND)

'Pin 7: GPIO.0 - CT4 Input

'Pin 6: GPIO.1 - CT3 Input

'Pin 5: GPIO.2 - CT2 Input

'Pin 3: GPIO.4 - CT1 Input    CT=Contact of Rotary Switch

'Pin 4: GPIO.3 – CT5 Input

'Pin 2: GPIO.5 - Drive Mosfet

'***********************************************

CMCON=7  'Comparator off

CT1input var GPIO.4

CT2input var GPIO.2

CT3input var GPIO.1

CT4input var GPIO.0

CT5input var GPIO.3

MosfetDrive var GPIO.5

TRISIO=%011111

n var byte

m var byte

 

n=0

m=0

 

Loop:

If CT1input=0 Then Goto PWM100

IF CT2input=0 Then Goto PWM75

IF CT3input=0 Then Goto PWM50

IF CT4input=0 Then Goto PWM30

IF CT5input=0 Then Goto PWM30t

Goto Loop

 

PWM100:

PWM GPIO.5,255,100

Goto Loop

 

PWM75:

PWM GPIO.5,248,100

Goto Loop

 

PWM50:   'For easier startup rotation of fan

n=n+1

If n=1 Then Gosub Startup

PWM GPIO.5,235,100

n=n+1

Goto Loop

 

PWM30:  'For easier startup rotation of fan

n=n+1

IF n=1 Then Gosub Startup

PWM GPIO.5,220,100

n=n+1

Goto Loop

 

PWM30t:  'For easier startup rotation of fan

n=n+1

IF n=1 Then Gosub Startup

PWM GPIO.5,190,100

n=n+1

If n=120 Then Gosub Tempstop  'should be less than 125, otherwise does not stop

Goto Loop

 

Startup:   'Allowing 'GPIO.5,248,100' rotation for 100 ms  起動を助けるためのサブルーチン

PWM GPIO.5,248,100

Pause 100  '0.1 sec

Return

 

Tempstop:     'Subroutine to stop the rotation of fan for 30 seconds temporarily 30秒間一時的に停止するサブルーチン

PWM GPIO.5,10,100

Pause 30000  '30 sec

Gosub Startup

Return

 

End

'*****End of Program******

'Note:

'melabs U2 Programmer's configurations for 12F629 (1):

'Oscillator - INTOSC, WDTE - Enable, PWRTE - Disable, MCLR - Input Pin, BODEN - Enable, CD - Disable, CDP - Disable

'***************************************************************************************************

 

これは新たに加えたタイマー用のプログラム。あまり正確さは必要ないので、プログラム中で待ち時間を作って各タイマー時間にした。時間が来たら12F629(1)や付随するロータリーSWへの電流を遮断して扇風機を止める。Resetボタンを押すと、今までのタイマー時間で再起動し、扇風機も回転を始める。あるタイマー時間で動作している時に、ツマミを回して別のタイマー時間を選択した場合、そのタイマー時間がゼロからカウントを始める。Always ONでは常時電流の供給が続く。

'***********************************************

 

‘For 12F629 (2)

'USBFanTimerPlus.bas   2017.6.27  worked!

'30-min, 2-hour and 5-hour timer for USB fans

'Program for 12F629 using PicBasic Pro V2.50A

'Internal 4MHz clock used

'*********Pin connections*********

'Pin1: Vdd(5V)

'Pin8: Vss(GND)

'Pin4(GP3): Reset (MCLR)

'Pin7(GP0): To Driving Photo Relay

'Pin2(GP5): To SP1 (always ON)

'Pin3(GP4): To SP2 (30-min timer)

'Pin5(GP2): To SP3 (2-hour timer)

'Pin6(GP1): To SP4 (5-hour timer)

'*********Program*********

CMCON=7  'Comparator off

TRISIO=%111110

PRelay var GPIO.0

SP1 var GPIO.5

SP2 var GPIO.4

SP3 var GPIO.2

SP4 var GPIO.1

 

m var word

n var byte

 

PRelay=0

 

Top:

IF SP1=0 Then Goto AlwaysON

IF SP2=0 Then Goto Timer30min

IF SP3=0 Then Goto Timer2hour

IF SP4=0 Then Goto Timer5hour

Goto Top

 

AlwaysON:   'Always Timer ON 常時接続ルーチン 

High PRelay

IF SP2=0 Then Goto Timer30min

IF SP3=0 Then Goto Timer2hour

IF SP4=0 Then Goto Timer5hour

Goto AlwaysON

 

Timer30min:   '30-min Timer '30分タイマールーチン

High PRelay

For n=1 to 6     '30 minutes

For m=1 to 3600  '5 minutes

Pause 100  '0.1 sec

IF SP1=0 Then Goto AlwaysON

IF SP3=0 Then Goto Timer2hour

IF SP4=0 Then Goto Timer5hour

Next m

Next n

Low PRelay

Goto Finish

 

Timer2hour:   '2-hour Timer  2時間タイマールーチン

High PRelay   

For n=1 to 24  '2 hours 

For m=1 to 3600

Pause 100  '0.1 sec

IF SP1=0 Then Goto AlwaysON

IF SP2=0 Then Goto Timer30min

IF SP4=0 Then Goto Timer5hour

Next m

Next n

Low PRelay

Goto Finish

 

Timer5hour:   '5-hour Timer  5時間タイマールーチン

High PRelay

For n=1 to 60  '5 hours

For m=1 to 3600

Pause 100  '0.1 sec

IF SP1=0 Then Goto AlwaysON

IF SP2=0 Then Goto Timer30min

IF SP3=0 Then Goto Timer2hour

Next m

Next n

Low PRelay

Goto Finish

 

Finish:

Stop

End

'*****End of Program******

'Note:

'melabs U2 Programmer's configurations for 12F629 (2):

'Oscillator - INTOSC, WDTE - Enable, PWRTE - Disable, MCLR - Reset, BODEN - Enable, CD - Disable, CDP - Disable

 '***************************************************************************************************

 

 

修正プログラムの追加(2019.6.26)  Addition of a modified program (2019.6.26)

上記の‘For 12F629 (1)  USBFanSpeedControllerB.basでは、PWM50、PWM30 それにPWM30tの各モードで扇風機が動作している時、PWM30tで約55秒前後毎に切替え音とおぼしき「キキュー」という異音が出ることが分かった。気になる音である(特に就寝時)。これはカウンターに使っている「n」の最大値255(n var Byte)に達した時に出るものと考え、n var Byteをn var Wordに換えた。Wordの場合だと最大値は65535で、65535/255=257倍となり、今まで55秒に1回発生した異音が55X257=14135秒=14135/60=236分=236/60=3.93時間と、約4時間は異音が発生しなくなるはず。観察結果から、実際、長時間異音の発生が止まり、上手くいったようである。同時に、速度ロータリーSWを回転して速度を変えるとき、一瞬電源が切れて12F629(1)にResetがかかり、プログラムの設定部分から再度読み込みがなされているものと思われる。そのほか、PWM30tを一時的に30秒間停止させる機能は削除した(Tempstop)。

 

‘For 12F629 (1) 修正版 modified 2019.6.26

'USBFanSpeedControllerBm.bas  2017.6.28 works! 2019.6.26 modified works!

'Using 12F629 and PicBasic Pro V2.50A

'Internal 4MHz clock used

'***********************************************

'Pin 1: Vdd(3V)

'Pin 8: Vss(GND)

'Pin 7: GPIO.0 - CT4 Input

'Pin 6: GPIO.1 - CT3 Input

'Pin 5: GPIO.2 - CT2 Input

'Pin 3: GPIO.4 - CT1 Input    CT=Contact of Rotary Switch

'Pin 4: GPIO.3 - CT5 Input

'Pin 2: GPIO.5 - Drive Mosfet

'***********************************************

CMCON=7  'Comparator off

CT1input var GPIO.4

CT2input var GPIO.2

CT3input var GPIO.1

CT4input var GPIO.0

CT5input var GPIO.3

MosfetDrive var GPIO.5

TRISIO=%011111

 

n var Word  'Changed from Byte to Word for smoother rotation

 

n=0

 

Loop:

If CT1input=0 then goto PWM100

IF CT2input=0 Then goto PWM75

IF CT3input=0 Then goto PWM50

IF CT4input=0 then goto PWM30

IF CT5input=0 then goto PWM30t

goto Loop

 

PWM100:

PWM GPIO.5,255,100

goto Loop

 

PWM75:

PWM GPIO.5,248,100

goto Loop

 

PWM50: 'For easier startup rotation of fan

n=n+1

If n=1 then gosub Startup

PWM GPIO.5,235,100

n=n+1

goto Loop

 

PWM30:  'For easier startup rotation of fan

n=n+1

IF n=1 then gosub Startup

PWM GPIO.5,220,100

n=n+1

goto Loop

 

PWM30t:  'For easier startup rotation of fan

n=n+1

IF n=1 then gosub Startup

PWM GPIO.5,190,100

n=n+1

goto Loop

 

Startup:   'Allowing 'GPIO.5,248,100' rotation for 100 ms

PWM GPIO.5,248,100

Pause 100  '0.1 sec

Return

 

End

 

'*****End of Program******

'Note:

'melabs U2 Programmer's configurations for 12F629:

'Oscillator - INTOSC, WDTE - Enable, PWRTE - Disable, MCLR - Input Pin, BODEN - Enable, CD - Disable, CDP - Disable

 

 

Menu Pageへ戻る   (Return to Menu Page)

Topへ戻る   (Return to Top of Page)