[PR] ベビーシッター PSoC Designer5.0 beta 新しいユーザーモジュール SHADOWREGS::PSoC

PSoC Designer5.0 beta 新しいユーザーモジュール SHADOWREGS

Home > 2008-04 / PSoC > This Entry [com : 3][Tb : 0]

2008-04-25

psocshadowreg

ユーザーモジュールがいくつか追加されている。
Misc Digitalには
OneShot
PWD
SHADOWREGS

SHADOWREGSのデータシートを読んでいてピンときた。
あるポートのピンをpullUpにして1を出力しておくとプルアップ抵抗付きの入力ポートとして使える。
プルアップ抵抗を外付けする必要がないのでスイッチをつなぐのに便利・・なはずなんだけど同じポートの他のピンをビット操作するとスイッチが反応しなくなることがある。
以前相当悩まされたことがある。

SHADOWREGSを使うとこの問題から開放される(はず・・まだ試してないんですわ^^;;)

例えば
PRT0DR = 0x02;
とするところを

Port0_Data_Shade = 0x02;
PRT0DR = Port0_Data_Shade;
としておけばいいらしい。
また
PRT0DR ^= 0x01;

Port0_Data_Shade ^= 0x01;
PRT0DR = Port0_Data_Shade;
とするといいのだそうだ。

データシートから引用しておく。

Example
An application uses P0[0] as a sourcing LED output, and P0[1] as a pulled-up input for a normally open switch connected to ground. After setting the drive mode registers for port 0, the firmware initializes the LED to off and enables the input with the following C statement.

PRT0DR = 0x02;

Without a shadow, register, the firmware toggles the LED by the following C statement.


PRT0DR ^= 0x01;

On the initial LED toggle operation, the value read from PRT0DR is 0x00 if the switch is closed, and 0x02 if the switch is open. Performing the XOR operation to toggle the LED results in 0x01 (0x00 XOR 0x01) if the switch is closed but 0x03 (0x02 XOR 0x01) if the switch is open when the initial toggle occurs. Toggling the LED when the switch is closed causes P0[1] to be driven to 0V internally. When the switch is opened, the value read from PRT0DR is still 0x01 because the voltage on P0[1] is still 0V. The switch input has been inadvertently disabled.

The solution is to always manipulate the shadow register first, then copy the shadow register value into the port data register. The following C statements initialize the LED output and the switch input.

Port0_Data_Shade = 0x02;
PRT0DR = Port0_Data_Shade;

The following code toggles the LED without affecting the switch input

Port0_Data_Shade ^= 0x01;
PRT0DR = Port0_Data_Shade;

Comment

K.I : 2008-04-26(Sat) 01:55 URL edit
Designerのイメージが随分変ったみたいですね〜。
情報ありがとうございます。
個人的には、日本語に対応っていうのが結構嬉しかったり。
だみやん : 2008-04-28(Mon) 05:12 URL edit
はじめまして。
前からPSoC Express で作ったプロジェクトファイルをDesignerで開くと、SHADOWREGSがぞろぞろ出てきたりしていました。Expressでビルドするとき、レジスタを直接いじるための隠しモジュールだったんでしょうね。
いつから仕込まれていたのやら?
きのした : 2008-07-13(Sun) 07:38 URL edit
> 同じポートの他のピンをビット操作するとスイッチが反応しなくなることがある。
これ嵌りました。って自分の場合は、他のビットでActive-H(Pull−Down抵抗)のSW入力使った設計してしまって、SWとは無関係のところ、PRT0DR ^= 0x01 なんてことしたらSWがONになってしましました。
Post a Comment









管理者にだけ表示を許可

Trackback

http://edycube.blog2.fc2.com/tb.php/377-7d856b9c

迷走の果て・Tiny Objects | Page Top▲

New >>
久々にPSoC周波数カウンタ・デュアル
<< old
PSoC Designer5.0 beta