- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Although the prototype circuit uses PSOC5LP, the interrupt and bifurcation do not work well.Someone please point out.
There may be a problem with the C language description.
Interrupt is switch”SW " interrupt.
Depending on the interrupt, the branch mode is、0 → 1 → 2 → 3 → 4 → 5 → a loop that is 0.
CY_ISR(isr_1)
{
//100msec チャタリングキャンセル
CyDelay(100);
//割り込みクリア
SW_ClearInterrupt();
//繰り返しの設定
if(mode_sw>6)
//SWが押されたことを検知
switch(mode_sw)
{
//SWが0の時はモード0で現在の圧力値を表示
case 0:
LED_Driver_1_Write7SegNumberDec(avg * 100, 0, 4, LED_Driver_1_ZERO_PAD);
LED_Driver_1_PutDecimalPoint(1, 1);
break;
//SWが1の時はモード1で定格圧力値の1/2を表示かつUP、DOWNで上限値を設定
case 1:
LED_Driver_1_Write7SegNumberDec(avg * 100, 0, 4, LED_Driver_1_ZERO_PAD);
LED_Driver_1_PutDecimalPoint(1, 1);
LED_Driver_1_WriteString7Seg("1225",0);
break;
//SWが2の時はモード2で定格圧力値の1/2を表示かつUP、DOWNで下限値を設定、Photo Relay 1をON
case 2:
LED_Driver_1_Write7SegNumberDec(avg * 100, 0, 4, LED_Driver_1_ZERO_PAD);
LED_Driver_1_PutDecimalPoint(1, 1);
LED_Driver_1_WriteString7Seg("2225",0);
break;
//SWが3の時はモード3で定格圧力値の1/2を表示かつUP、DOWNで上限値を設定
case 3:
LED_Driver_1_Write7SegNumberDec(avg * 100, 0, 4, LED_Driver_1_ZERO_PAD);
LED_Driver_1_PutDecimalPoint(1, 1);
LED_Driver_1_WriteString7Seg("3225",0);
break;
//SWが4の時はモード4で定格圧力値の1/2を表示かつUP、DOWNで下限値を設定、Photo Relay 2をON
case 4:
LED_Driver_1_Write7SegNumberDec(avg * 100, 0, 4, LED_Driver_1_ZERO_PAD);
LED_Driver_1_PutDecimalPoint(1, 1);
LED_Driver_1_WriteString7Seg("4225",0);
break;
//SWが5の時はモード5で現在の圧力値を消灯(低消費モード)
case 5:
LED_Driver_1_Write7SegNumberDec(avg * 100, 0, 4, LED_Driver_1_ZERO_PAD);
LED_Driver_1_PutDecimalPoint(1, 1);
LED_Driver_1_WriteString7Seg("",0);
break;
//SWが6の時はモード0で現在の圧力値を表示
break;
}
SW_ClearInterrupt();
}
int main(void) {
CyGlobalIntEnable; /* Enable global interrupts */
isr_1_Start(); /* 割り込みコンポーネント・スタート */
int SW = SW_Read();
#include "stdio.h"
//ISR が割り込みであることの宣言
CY_ISR_PROTO(isr_1);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
鈴木様、
> 割り込みOKですね、レスポンス求めるなら1000msecを落とす方向で良いのかな。
はい、1000ms はADCの表示の滝を緩くすることが目的だったので
ステートマシンが動いていることが確認できた時点で不要かと思います。
もし差支えなければ、私の回答に Correct Answer のマークを付けていただけますと
コミュニティのポイントが上げられて嬉しいです。
ご不明の点が発生された場合、それぞれのテーマでスレッドを起こしていただけますと
他の方との情報共有の為にも良いかと思います。
以上申し上げた上で一点気付いた点をお知らせいたします。
現在、お使いのプロジェクトでは ADC は連続モード (Continuous)になっていますが
全体のタイミングを制御されるのであればSingle Sample にして
ループ毎に
ADC_DelSig_1_StartConvert()
と
ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT)
を呼んでから処理をした方が値が安定するかと思います。
ADCの設定及びトリガタイミングの変更を施したプロジェクトを添付します。
以上
田中 基夫
aka moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
So what you are thinking about is like this?
I tried with CY8CKIT-059 using UART and SW(P2[2])
Note to trigger Interrupt as Rising Edge, I needed to add a NOT between the input and the interrupt.
想定されているのは下記のような動作でしょうか?
CY8CKIT-059 で、UART を使用して、SW(P2[2]) を使ったスケレトンを作ってみました。
一点ハマったのは割込みの立ち上がりエッジを検出させるために
入力ピンと割込みの間に NOT ゲートを付ける必要がありました。
main.c
=============================
#include "project.h"
#include <stdio.h>
char str[128] ; /* print buffer */
void print(char *str)
{
UART_PutString(str) ;
}
volatile int mode_sw = 0 ;
volatile int SW_Pressed_Flag = 0 ;
CY_ISR(isr_1)
{
SW_INT_ClearPending();
SW_Pressed_Flag = 1 ;
}
void doStateMachin(void)
{
switch(mode_sw) {
case 0:
sprintf(str, "SW MODE = %d\r\n", mode_sw) ;
print(str) ;
mode_sw = 1 ;
break ;
case 1:
sprintf(str, "SW MODE = %d\r\n", mode_sw) ;
print(str) ;
mode_sw = 2 ;
break ;
case 2:
sprintf(str, "SW MODE = %d\r\n", mode_sw) ;
print(str) ;
mode_sw = 3 ;
break ;
case 3:
sprintf(str, "SW MODE = %d\r\n", mode_sw) ;
print(str) ;
mode_sw = 4 ;
break ;
case 4:
sprintf(str, "SW MODE = %d\r\n", mode_sw) ;
print(str) ;
mode_sw = 5 ;
break ;
case 5:
sprintf(str, "SW MODE = %d\r\n", mode_sw) ;
print(str) ;
mode_sw = 0 ;
break ;
default:
sprintf(str, "Unexpected SW MODE [%d]\r\n", mode_sw) ;
print(str) ;
break ;
}
}
int main(void)
{
int sw_value = 0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
SW_INT_ClearPending() ;
SW_INT_StartEx(isr_1) ;
UART_Start() ;
sprintf(str, "ISR Test Program (%s %s)\r\n", __DATE__, __TIME__) ;
print(str) ;
for(;;)
{
if (SW_Pressed_Flag) {
CyDelay(100) ; /* wait 100ms */
if (SW_Read() == 0x00) { /* SW is still pressed */
doStateMachin() ;
}
SW_Pressed_Flag = 0 ;
}
}
}
=============================
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mr. Tanaka,
Thank you for your advice and for creating the sample code for my PSOC5LP prototype board.
However, it is an inexplicable phenomenon.
When you build, the operation does not change even if I press SW while the 4-digit 7SEGMENT remains off.
Once the USB connector is disconnected and reconnected, the 7SEGMENT lights up at 00, but does not
respond to the SW switch.
The description was rewritten UART to UART_1 and isr_1 to SW_INT.
Inverter, it is not necessary to specifically declare in the C main()?
I think that it is truly a professional design, but it takes some time to understand for those who
have just started C language like me.
There are 3 warnings.There are no errors.
I will send it again, but why does the interrupt occur and the notation of 7SEGMENT does not change?
たなかさん、この度は私のPSOC5LP試作基板の件で、アドバイス、そしてサンプルコード作成して下さり、感謝申し上げます。
しかしながら、不可解現象です。ビルドすると4桁の7SEGMENTは消灯したままでSWを押しても動作は変わりません。
一度USBコネクタを外してから再度繋ぐと、7SEGMENTは00で点灯はしますが、SWスイッチには反応しません。
記述は、UARTをUART_1へ、isr_1をSW_INTに書き換えました。
インバーターは、Cmainで特に宣言する必要は無いですね?
たなかさんのは、さすがにプロフェッショナルな設計であると思いますが、私のようにC言語を始めたばかりの者には
少々理解に時間がかかります。
3箇所で警告が出ています。エラーはありません。
もう一度送らせて頂きますが、なぜ、割り込みが発生し、7SEGMENTの表記が変わらないのかです。
sprintf(str, "SW MODE = %d\r\n", mode_sw) ;の箇所は直接数字を入れれば良いのですか?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Suzuki-san,
Thank you for your message.
I studied the attached project.
I noticed a few things...
(1) About the LED
(2) Name of SW_INT
(3) SW pin config
(1) About the LED
According to the 5461AS datasheet, which I googled, the common pin is low-active and segment pins are high-active,
which is actually you commented in the schematic, too.
But the configuration of your LED_Driver_1 seems to be different
So I changed the set up as follow
(2) I use ISR as Interrupt service routine so I don't want to name a pin xxx_ISR,
so I use INT which stands for interrupt. Then I name my ISR as xxx_isr.
In this case I named the interrupt component as SW_INT, and I named the ISR as sw_isr.
(3) Although you used a dedicated interrupt output from the SW pin,
I could not make it work, probably it's my fault though.
So I changed the pin to a normal type and put a NOT gate and interrupt component.
So far, I could confirm that at least the state-machine is called and working as I expected.
As I don't have the 7SEG, I'd appreciate it if you let me the result (if 7SEG displays something)
Attached is my modified project of yours.
Best Regards,
8-Feb-2019
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
鈴木様、
時間を優先した為英文にて失礼しました。
お送りいただいたプロジェクトを拝見して
私が気になった点は3点です。
(1) LED ドライバの設定
(2) SW_INT という名称について
(3) SWピンの設定
(1) LED ドライバの設定
ググって拾ってきました 5461ASのデータシートによりますと
セグメントは正論理、コモンは負論理となっていますが、
お送りいただいたプロジェクトでの設定は逆になっていました。
とりあえず私が正しいと思う設定に変更してみました。
(2) SW_INT という名称について
通常 ISR というのは割込み処理ルーチンという意味で使用されるので
コンポーネントに ISR と付けることに抵抗があるため、私はInterrupt
コンポーネントには SW_INT という名称を付けて、プログラム中で
紐づけられている関数を sw_isr という名称にしています。
過去の経験から、コンポーネント名と関数名を同一にすると
色々と良くない事が起きた記憶があります。
(3) SWピンの設定
鈴木様はピンから直接割込みを発生する設定でお使いでしたが、
私は不勉強から、その設定で割込みを発生することが出来ませんでした。
その為、いつも使用している通常ピンをインバータ経由で Interrupt
コンポーネントに接続する方法に変更させていただきました。
とりあえず添付のプロジェクトにて、割込みが発生して
stateMachineが動いているところまでは確認できました。
7SEGについては、手元にハードウェアが無いので確認できませんでしたが
結果をお知らせいただけますと嬉しいです。
P.S. 私のサンプルではオデッセイさんから突っ込みのあった
ディレイは既に割込み関数から通常関数の方に移してあります。
以上
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Mr.Tanaka
Thank you for contacting us.
Thank you again for your hard work for this inexperienced person.
However, there was a mistake.
7SEGMENT is high on the common anode.
Each a-g, dot pin is active low at the cathode.
It was my notation mistake.
7segment is currently in lighting, but is unchanged even if I press the switch "SW"
I am monitored by TeraTerm, but it seems to have been turned into a character code for some reason.
Are there any corrections for the C source that I sent you earlier?
I wish an interrupt would have occurred.
Thanks!
Best Regards,
Tossiy
田中さん
ご連絡有り難う御座います。
この未熟な者の為に労して下さり、改めて有り難う御座います。
しかしながら、ミスが御座いました。
7SEGMENTはコモンがアノードでHIGHです。
各a~g、dot端子はカソードでアクティブlowです。
私の表記ミスでした。
7segmentは現在点灯中ですが、スイッチを押しても不変です。
TeraTermでモニターしておりますが、なぜかキャラクター・コードに化けてしまった感じです。
先ほど送りましたCソースは、何処か訂正箇所は御座いますか?
これで割り込みが発生すれば良いのですが。
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Suzuki-san,
鈴木様、
Have you tried the updated project I attached in my previous message?
Note: You need to re-configure LED_Driver_1's polarity though.
先のメッセージに添付させていただきましたプロジェクトは
お試しいただけたでしょうか?
その際、誤って変更してしまいました LED_Driver の極性は
正規のものに戻してください。
(1) About the TeraTerm log
Yes, with CY8CKIT-059 it happens all the time (^_^;
In this case, please try following
- Pause the debugger and use the Reset button to rewind the program.
- Then quit the TeraTerm once and restart, reconnect it.
- Start the program using Resume Execution Button.
In my environment, usually this fixed the corrupted TeraTerm display.
TeraTermの文字化けですが、CY8CKIT-059を使用していますと
頻繁に発生します。その場合、デバッガでプログラムをポーズ後に
リセットアイコンを使用してプログラムの実行を先頭に戻し、
TeraTerm を一度終了して、再度起動後接続し、
デバッガの実行を開始するという手順で、私の環境では
画面の状態を復帰することが出来ています。
(2) About the 7 Segments
Seeing your picture, I think the 7SEGs are displaying numbers "VERY FAST".
So how about put a CyDelay(1000) at the begin or end of the for (;;) { block ?
For example
for (;;) {
CyDelay(1000) ; // 1秒待ち
if (ADC_....
写真を拝見したところ、7SEGは何かを高速に表示しているのではないかと思いました。
試しに for ループの最初か最後に CyDelay(1000) 等を追加して動作を遅くして
どのような表示になるものかご確認いただけないでしょうか?
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
田中さん
お世話様です、鈴木です。
Design01_190208Aを解凍し、新しいprjで立ち上げてみましたが、SW押しても7SEGMENTの
表示は00.00のままです。
デバッグモードでは、Resume Execution Buttonを押して、表示はしておりますが、Reset押すと
消灯し、
int main(void)
{
でstopしています。TeraTermは文字化けがあるにせよ、停止していますから、割り込みは
働いているのかな?
7SEGMENTに表示が出せれば分かり易いのですね。
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
鈴木様、
TeraTerm の表示はまだ文字化けしたままでしょうか?
Debugger にてpause をして、TeraTerm を終了後に
再度 TeraTerm を起動し、ポート設定後に Debugger で resume を
させた場合、先の私のメッセージのような表示にはならないでしょうか?
また、CyDelay(1000) を入れている場合、ボタンは長めに押し続ける必要があります。
(2~3秒の感じでしょうか)
以上をお試しいただき SW MODE が 0~5 へ変化しているかご確認いただけないでしょうか?
以上
田中 / moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
田中さん
お世話様です。
割り込みOKですね、レスポンス求めるなら1000msecを落とす方向で良いのかな。
一段落しましたので、あとはMODEの表記にシフトしますが、
今回は大変御世話になりました。
懇切丁寧に教えて頂き、感謝です。
またトラブル起きた際にメンションするかもしれませんが、その際は宜しくお願いいたします。
嬉しいですね、本当に感謝!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
鈴木様、
> 割り込みOKですね、レスポンス求めるなら1000msecを落とす方向で良いのかな。
はい、1000ms はADCの表示の滝を緩くすることが目的だったので
ステートマシンが動いていることが確認できた時点で不要かと思います。
もし差支えなければ、私の回答に Correct Answer のマークを付けていただけますと
コミュニティのポイントが上げられて嬉しいです。
ご不明の点が発生された場合、それぞれのテーマでスレッドを起こしていただけますと
他の方との情報共有の為にも良いかと思います。
以上申し上げた上で一点気付いた点をお知らせいたします。
現在、お使いのプロジェクトでは ADC は連続モード (Continuous)になっていますが
全体のタイミングを制御されるのであればSingle Sample にして
ループ毎に
ADC_DelSig_1_StartConvert()
と
ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT)
を呼んでから処理をした方が値が安定するかと思います。
ADCの設定及びトリガタイミングの変更を施したプロジェクトを添付します。
以上
田中 基夫
aka moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
t.suzuki,
I noticed a 100 ms delay inside interrupt handler, which should not be there. Never use delays in the ISR routines.
For processing of the key pressed events there is ready to use component, which handles all underground work:
ButtonSw32: button switch debouncer component
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Odyssey
Thank you for your valuable advice.
Indeed, during the delay of CyDelay(100), interrupt processing was performed.
I'll take a closer look.
Cypress has an interesting module called button32.
I didn't know.
Thank you very much.
Best Regards,
Tossiy