電子工作56 – 99時間59分59秒まで設定できる4チャンネルタイマ付き音声メモの製作

 

概要

歳のせいか結構物忘れがひどくなってきた。外出時にやろうとした用事を出先で忘れる。手元に4チャンネルの長時間タイマとサウンドレコーダモジュール(音声録音再生モジュール)があったので組み合わせて電池で動くタイマ付き音声メモを製作してみることにした。4チャンネルあるので同じ録音した音声を4回違った時間に再生してくれる。これなら幾らなんでも忘れようがあるまい。

 

 

製作にあたって

1)     実際に実用になるかどうか検討するのが主目的。

2)     タイマとサウンドレコーダモジュールのインターフェースに12F629を使う。

3)     電池駆動なので割込みを使って非動作中はSleepさせ電流消費を出来るだけ下げる。

4)     勿論コンパイルにはPICBasic Pro を使う。

5)     電子工作19、28と37を参考にする。

 

使用した主要部品

1)     4チャンネルタイマ(正式名: 4カウントりんごタイマ): 99時間59分59秒までカウントアップとカウントダウンモードで設定可能である。カウントダウンモードでT1-T4の4つのチャンネルの各々を好きな時間に設定して時間がくるとピーピーと1分間ブザーが鳴る。例えば、T1−T4を1、2,3,4時間に設定し各々をスタートさせると各時間終了後に1分間づつブザーが鳴る。直径92−93mm、厚さ20mmとかなり大きい。LR44電池1個で待機時約1年持つという。昨年秋葉原のジャンクショップで100円で入手した。

2)     サウンドレコーダ(正式名: サウンドレコーダモジュールM20) 20秒間録音できる。小さい基板に回路が組込んであり別の基板に載った3個のボタン電池(LR54 1.5V X 3)で駆動する。外付けの録音ボタンを押しながら録音し、別の再生ボタンを押すと直径35mm、厚さ5mmのスピーカより再生される。ちょっと音量が不足気味。数年前秋葉原で900円で購入。

 

回路図と動作原理

  回路図を下に示す。まずタイマに改造が必要。裏ブタを明け、ブザーにつながる2本の線に+線(赤)とGND線(黒)を極性に注意してハンダ付けして外に出す。またブザー音をON/OFF出来るようにするため、ブザーにつながる2本の線のうちの1本を切り、その各々の両端に5cmほどの線をハンダ付けし外に出し内部ブザーON/OFF SWにつなぐ。この回路では、タイマからのブザー音を拾って12F629で処理し、ホトリレーを介してサウンドレコーダのスイッチを入れて音声を再生させる。タイマからのブザー音は12F629が読込めるようにコンデンサ2個と抵抗4本、それにトランジスタ1個で構成される回路(積分回路)で波形を整形させる(詳細は後述)。そしてGP0とGP1に導入させる。前者ではポートレベル変化割込み信号として、後者では入力パルス波形のレベル(H or L)検知に使われる。ホトリレーは内蔵のLEDが点灯した時、対面するPin4とPin6間の抵抗がメガWレベルから数Wに低下して導通し、サウンドレコーダの再生ボタンを押したと同じ状態になり録音済みの音声が再生される。携帯することを前提に電池を使った実験では3.0Vより確実に動作することが分かった。経済性を考え単4のNiMH充電池を4本使うこともできるが多少重くなる欠点がある。なお、タイマからブザー音が出ていない状態、すなわち12F629が待機状態(sleep時)の電流消費は0.01−0.02mAであった(ただし、プログラマで焼込む時のConfig,の設定に注意)。ブザー音を処理している時は1mA程度に上昇する。したがって単4電池でも十分長持ちすると考えられる。録音時間選択SWも加え10秒間と20秒間のいずれかを選択できるようにした。ここで入れた220Kが待機消費電流の低下に大変役だっている。

 )

 

Photo 1                                                 Photo 2

                            タイマの外観: T1-T4まで4つ独立に時間設定ができ、 内部: 左側のブザーを駆動する2線に+線とGND線をハンダ付けし

                            各々の最大設定時間は99時間59分59秒である     て外に出す。またブザーの1線を切って外に出しON/OFF SWとつなぐ

 

Photo 3

                                     実験中: 12F629が下方の中央に見える。右手に大きいタイマが見える。左手にはサウンド

レコーダモジュールがあり、録音、再生ボタン、マイク、スピーカー、本体基板、さらに

3個の電池が載った基板が見える。時間を設定し、スタートさせ、時間がくると録音さ

れたメッセージが再生される。ここでは電源に単4NiMH充電池を4本(4.8V)使用。

最下部の右手にあるのが録音時間選択SWである。

 

Photo 4

                                      実用機: ポリプロピレンふた付きボックス(15x10x6cm)に収納。単5x2で動作。サウンド

レコーダモジュールは基板の下にある。携帯にはちょっと嵩張るのと音量が小さいのが問題

(2011.5.23追加)

Working model: Packed in a plastic box (15x10x6cm), powered by two AAAA Mn batteries

Problems found are still too larege to carry and low sound level (newly added on 2011.5.23)

 

ブザー音の波形解析(T1の場合): ブザー音をどうやって12F629に読ませるか、の検討にはオシロによる波形解析が必須だった(電子工作28参照)。

 

(A)    次の図は上述の実験ボードで、タイマの時間を設定し、スタートさせた時に、タイマからの出力をオシロで測定したものである(10mFにつながる線とGNDの間)。左手から始まり無音部に相当する500msのパルス不在部、続いて有音部(ピーと音のする部分)に相当する500msのパルス群、これが1分間繰返し続く。

 

(B)    この図は上記で有音部に相当する500msのパルス群を拡大したものである。様々な形や大きさのパルスから構成されていることが分かる。これではとても12F629に読ませることが出来ない。 

(C)    下図はブザー(T1)の出力を積分回路に通して整形し12F629のGP0とGP1に導入されるパルス群を測定したものである。この場合スタートボタンを押してから3秒待ってブザーが鳴るように設定した。スタートボタンを押すとHレベルが一旦Lレベルに下がり約800msで元に戻る。最初に下がった点からブサー音に対応するH -> Lエッジまでの間が3秒間である。ブサー音の部分では先ず幅500msの谷部が現れ、次いで同じく幅500msのピーク部が続く。以下ブサーが鳴っている間、つまり1分間同じパターンを繰り返す。どうやら上図(B)のBuzzer beeping section (500ms)はこの波形の谷部に相当しているようだこのようにHとLレベルがはっきりしている場合は12F629中でのプログラムによる処理が容易に出来る

 

 

結果&コメント

1)     使用法

a)       録音ボタンを押しながらマイクに向かって話す(10秒間または20秒間)。 。

b)       PICの電源を入れる。

c)       録音時間選択SWで10秒間または20秒間を選ぶ。

d)       タイマ(カウントダウン)の時間を設定し(最大4個)、スタートボタンを押す。

これで時間が来ると録音した音声が10秒間録音で5回、20秒間録音で3回繰り返し再生される。

2)        99時間59分59秒、すなわち100/24=4.16日にもわたる長時間タイマとの組合せはいろいろな事に使えそうで何とも頼もしい。

3)        サウンドレコーダの音質と音量がいまいちなので手を加える必要あり。

4)        ブザー音をPICが読める様なきれいな波形にしてくれる積分回路は良く理解できないが素晴らしい役目を果す。

5)        10秒間録音・再生モードではブザー音(上図(C))の第4番目のパルス(ピーク部)でサウンドレコーダにSWが入り音声が流れ出し13秒間続く、これが5回繰り返えされる。この13秒間に関してだがプログラムでは3.0+0.5x5+0.1+10=15.6秒になるはず、不一致の理由は不明。

6)        大分減少したが、指でタイマの時間を設定したり、スタートさせる時に出るピーというクリック音に反応して録音済みの音声が時折再生される。

7)        ブザー音をPICに割込みをかけて読込ませる方法が分かったので今後はいろんなものに応用出来そう。例えば、タイマでデジカメのシャッターを切る、など。

8)       費用の高いものはサウンドレコーダモジュールM20の900円と長時間タイマ(新品なら1500円位から)、両者ともWeb上で出回っていた。

9)       (追加情報2011.6.29)  T2のブザー音にサウンドレコーダが反応しない不具合を発見した。調べてみたらT1−T4とも波長は同じだが波形パターンが互いに少しずつ違うことがオシロを使って分かった。最初、全て同じだと思っていた。そこでプログラムの1個所を修正し、正常に動作するようになったIf (Atotal=<3) Then Goto Voice

 

プログラム

  このプログラムは電子工作19、28と37を参考にして作成した。電池駆動になるので省電流が必須。割込みと@Sleepコマンドを使ってタイマ側から信号がない時は12F629を眠らせる。タイマより整形されたブザーの音パルス(上記のパルス(C))がGP0より読込まれ割込みがかかると '***Timer reading & Sound recorder control routine*** 以下のルーチンが実行される。先ずGP1で、枝分かれして来たブザーの音パルスが読込まれ、その時間の経過とともに変化するHまたはLレベルがチェックされる。間違いなくブザー音パルスと分かればGP2のH/Lレベルをチェックし、10秒間または20秒間GP5をONにして録音した音声を再生させる。プログラム中でAtotal=A1+A2+A3+A4+A5、If (Atotal=<2) Then Goto Voice とあるが、これは指でタイマの時間を設定したり、スタートさせる時に出るピーというクリック音に反応して録音済みの音声が再生されるのを出来るだけ防ごうと目的のためにある。1分間続くブザーの音パルスが出なくなると、GP1に加わる信号レベルはHの連続となるのでAtotal=<2には合わなくなるので(Atotal=5となる)、Goto SleepLoopによってプログラムの最初に戻りSleep状態に入る。

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

'VoiceMemo629C.bas - 2011.6.29 (modified from VoiceMemo629B.bas) works OK!

'It was found that T2 didn't work, so the program was slightly modofoed.

'Combination of 4-ch Timer and Sound Recorder Unit

'As @sleep is used, the current used will be very low.

'Interrupt function is used

'10 or 20 sec Recording Select SW introduced

'********Pin connection******************

'Pin 1: Vdd (3.0-4.5V) battery

'Pin 8: Vss (GND)

'Pin 4: /MCLR to Vdd & SW via 10K

'Pin 7: GPIO.0 - From 4-ch Timer for interrupt input

'Pin 6: GPIO.1 - From 4-ch Timer for data input

'Pin 5: GPIO.2 - Recording time select SW

'Pin 3: GPIO.4 - Not used

'Pin 2: GPIO.5 - Output to Photo relay driving Sound Recorder

'********Progran starts from here**********

TimerInterrupt var GPIO.0

TimerDataInput var GPIO.1

PhotoRelay var GPIO.5

RecordTSelect var GPIO.2 

I var byte 'Counter

A1 var bit

A2 var bit

A3 var bit

A4 var bit

A5 var bit

Atotal var byte

 

TRISIO=%001111   'GPIO.0 & 1 (Interrupt/TimerInput),GPIO.2 and GPIO.3 - inputs

CMCON=7        'Disable Comparators.

IOC.0=1          'Detect input level change at GP0 - Essentiall !!   以下が割込み設定の最重要部、ポートレベル変化に反応する

INTCON.3=1      'Enable the port input-level change interrupt

 

SleepLoop:

INTCON.0=0      'Clear GPIF

@Sleep          'Have a good sleep! - This is a key command   割込みの無い時このコマンドで省エネのsleep状態に入る

INTCON.0=0      'Clear GPIF

 

'***Timer reading & Sound recorder control routine***   割込みが入るとこれ以下のルーチンが実行される

PhotoRelay=0

I=0

Pause 3000 'Wait 3000 ms

If TimerDataInput=1 Then   'Check the H/L of waveshape 5 times as shown below  ここでGP1に入って来る時間で変わるパルスの波形のH/Lをチェックする

A1=1                       'when H  Hの時A1=1とする

Else

A1=0                       'when L  Lの時A1=0とする

Endif

Pause 500              'Wait 500ms  500ms待つ

 

If TimerDataInput=1 Then    'Repeat the similar process another 4 times  同じことを以下で4回繰り返す

times

A2=1

Else

A2=0

Endif

Pause 500

 

If TimerDataInput=1 Then

A3=1

Else

A3=0

Endif

Pause 500

 

If TimerDataInput=1 Then

A4=1

Else

A4=0

Endif

Pause 500

 

If TimerDataInput=1 Then

A5=1

Else

A5=0

Endif

Pause 500

 

Atotal=A1+A2+A3+A4+A5  'Totalize A1-A5  集計する

If (Atotal=<3) Then Goto Voice  'This is found to be appropriate. もしAtotalが3に等しいか、3以下ならVoiceに飛べ。この値は実験的に決めた。(T2鳴らないので2011.6.29修正 2−>3)

Goto SleepLoop                                'この部分は他のボタンを押した時に出るブザー音の影響を防ぐ目的で導入

 

Voice:       'For Sound recorder activation

If RecordTSelect=1 Then  '10 or 20 sec recording check?  ここで録音時間選択SWが10秒間または20秒間に設定されているかをチェック

Goto Rec10sec

Else

Goto Rec20sec

Endif

 

Rec10sec:  'For 10-sec select 10秒間に設定なら以下のルーチン実行

High PhotoRelay

Pause 100

Low PhotoRelay

Pause 10000  '10 sec

Goto  SleepLoop

 

Rec20sec:  'For 20-sec select 20秒間に設定なら以下のルーチン実行

High PhotoRelay

Pause 100

Low PhotoRelay

Pause 20000  '20 sec

Goto  SleepLoop

 

'****** End of program*******

 'Note:

   'melabs U2 Programmer's configurations for 12F629: 待機電流消費に関係するので以下の設定大切!

   'Oscillator - INTOSC; WDTE - Disable; Power-up Timer  - Enable

   'MCLR - Input Pin ; BODEN - Diable; CD - Disable; CDP - Disable.

 

 

20-sec Sound Recorder with 4-ch Timer which is presettable up to 99 hrs 59 mins 59 secs  (English version of the above Electronics Project 56 in Japanese)

  Getting older, I tend to forget things, especially when I go out to do things. So I decided to make a device that repeatedly speaks what to do at preset times using a 4-ch timer and a 20-sec sound recorder module, both of which I bought a couple years ago. For interfacing between those two, I used a 12F629. The device will be taken with me whenever I go out、so it must be portable or operated with batteries. E;lectronically to detect that a preset time expired in the timer, the signal from the internal buzzer of the timer needs to be picked up by 12F629. For that purpose, first two wires (red(+) and black(GND)) were soldered to the two points (to which two black wires are connected for the activation of the internal buzzer) on the timer’s circuit board and taken out of the timer case. Then, one (black) of these two wires (red and black) is connected to GND, while the other (red) is connected to the pulse shaping circuit comprising of a transistor, four resistors and two capacitors (integrating circuit?) and the resulting signal is led to GP0 and GP1 of 12F629. The signal to GP0 is used to cause a port level-change interrupt while the same signal applied to GP1 is used as H/L data. The data from GP1 is processed within 12F629 and is output as H pulse to turn on the LED of photo relay, closing the playback button of the sound recorder module. Because 12F629 sleeps when no buzzer pulses are arriving, the power consumption drops down to 0.01-0.02mA. On the other hand, when 12F629 is doing processing work, it consumes about 1 mA. Two AAA batteries (3.0V) are considered sufficient enough to operate the device for many days.

More about 4-ch Timer and Sound recorder module:

* 4-ch Timer (kind of kitchen timer, see the above Photo 1 and 2 Outside & Inside of Timer) – It has 4 independent timers, each of which can be set up to 99 hrs 59 mins 59 secs in either count up or down mode. When the preset time of any timer expires the internal buzzer beeps for 1 min. So if all four timers are preset at different times, the buzzer can beep four times, makings it possible for the device to replay the same message four times.

* Sound recorder module (See the above Photo 3 Under Experiment) – It can record up to 20 seconds by pressing Record button and replay the recorded sound by pressing Playback button. Three 1.5V coin batteries (LR54) are used.

 

Pulse 1

This shows a sequence of buzzer T1's beep pulses measured between the red(+) and black wires from Timer

(before entering the pulse shaping circuit) using oscillioscope.12F629 cannot read this kind of pulses.

 

Pulse 2

This shows the above pulses after passing through the pulse shaping circuit. When a timer is started. a sharp drop

in voltage occurs. After preset 3 seconds, the buzzer begins to beep for 1 minute, generating clear and periodic

pulses, which 12F629 can easily read, process and use for the activation of the sound recorder.

What have been found and comments

A)  Responding to the buzzer-beep pulses, the program works well. During 60 seconds when buzzer is beeping, the recorded sound is replayed 5 times in 10-sec recording time select mode and 3 times in 20-sec recording time select mode

B)      The main purposes I tried to achieve here is to test how to use the interrupt, change an irregular wave shape to PIC-readable clean one, establish a simple wave shape reading routine and lower the power consumption using the sleep mode.

C)      What were found in this project can be applied to various other purposes. This kind of timer and the sound recorder are available on web shops and cost about 1500 yen (as new) and 1000 yen, respectively.

D)      The working model was developed later (See Photo 4 in the above Japanese section). It needs to be further improved since it is still large to carry everyday and its sound level is not loud enough (added on 2011.5.23).

E)      (Later found 2011.6.29) The buzzer beep pulse patterns of T1 to T4 were found to be slightly different from one another. One line of the existing program was changed to correct the problem of no playback response to T2.

 

Program

Responding to the input (Pulse 2) to GP0 and GP1, this program picks up the level change (H ®L or L®H) at GP0 to cause an interrupt and reads the same pulse data into the main routine for necessary processing at GP1. As the device is operated with batteries, energy saving is very important. Therefore, the @sleep command is used for 12F629 to go to sleep (energy saving mode) while no buzzer pulses are arriving. Only an interrupt signal wakes up PIC from sleep. The program list to do all this is shown below;  If (Atotal=<2) Then Goto Voice -> If (Atotal=<3) Then Goto Voice

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

'VoiceMemo629C.bas - 2011.6.29 (modified from VoiceMemo629B.bas) works OK!

'It was found that T2 didn't work, so the program was slightly modofoed.

'Combination of 4-ch Timer and Sound Recorder Unit

'As @sleep is used, the current used will be very low.

'Interrupt function is used

'10 or 20 sec Recording Select SW introduced

'********Pin connection******************

'Pin 1: Vdd (3.0-4.5V) battery

'Pin 8: Vss (GND)

'Pin 4: /MCLR to Vdd & SW via 10K

'Pin 7: GPIO.0 - From 4-ch Timer for interrupt input

'Pin 6: GPIO.1 - From 4-ch Timer for data input

'Pin 5: GPIO.2 - Recording time select SW

'Pin 3: GPIO.4 - Not used

'Pin 2: GPIO.5 - Output to Photo relay driving Sound Recorder

'********Program starts from here**********

TimerInterrupt var GPIO.0

TimerDataInput var GPIO.1

PhotoRelay var GPIO.5

RecordTSelect var GPIO.2 

I var byte 'Counter

A1 var bit

A2 var bit

A3 var bit

A4 var bit

A5 var bit

Atotal var byte

 

TRISIO=%001111   'GPIO.0 & 1 (Interrupt/TimerInput),GPIO.2 and GPIO.3 - inputs

CMCON=7        'Disable Comparators.

IOC.0=1          'Detect input level change at GP0 - Essential !!

INTCON.3=1      'Enable the port input-level change interrupt

 

SleepLoop:

INTCON.0=0      'Clear GPIF

@Sleep          'Have a good sleep! - This is a key command

INTCON.0=0      'Clear GPIF

 

'***Timer reading & Sound recorder control routine***

PhotoRelay=0

I=0

Pause 3000 'Wait 3000 ms

If TimerDataInput=1 Then   'Check the H/L of waveshape 5 times as shown below

A1=1                       'when H

Else

A1=0                       'when L

Endif

Pause 500                'Wait 500ms

 

If TimerDataInput=1 Then  'Repeat the similar process another 4 times

A2=1

Else

A2=0

Endif

Pause 500

 

If TimerDataInput=1 Then

A3=1

Else

A3=0

Endif

Pause 500

 

If TimerDataInput=1 Then

A4=1

Else

A4=0

Endif

Pause 500

 

If TimerDataInput=1 Then

A5=1

Else

A5=0

Endif

Pause 500

 

Atotal=A1+A2+A3+A4+A5  'Totalize A1-A5 

If (Atotal=<3) Then Goto Voice  'This (Atotal=<3) is found appropriate to avoid the activation of sound recorder by the beeping of  key entries such as Start key.

Goto SleepLoop

 

Voice:       'For Sound recorder activation

If RecordTSelect=1 Then  '10 or 20 sec recording check?

Goto Rec10sec

Else

Goto Rec20sec

Endif

 

Rec10sec:  'For 10-sec select

High PhotoRelay

Pause 100

Low PhotoRelay

Pause 10000  '10 sec

Goto  SleepLoop

 

Rec20sec:  'For 20-sec select

High PhotoRelay

Pause 100

Low PhotoRelay

Pause 20000  '20 sec

Goto  SleepLoop

 

'****** End of program*******

 'Note:

   'melabs U2 Programmer's configurations for 12F629

   'Oscillator - INTOSC; WDTE - Disable; Power-up Timer  - Enable

   'MCLR - Input Pin ; BODEN - Disable; CD - Disable; CDP - Disable.

 

 

Menu Pageへ戻る

Topへ戻る