Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:9a7f77850970
- Parent:
- 1:91d6b2ee7a2e
- Child:
- 3:5d91bfe4a79d
diff -r 91d6b2ee7a2e -r 9a7f77850970 main.cpp
--- a/main.cpp Sat Jan 21 07:37:48 2017 +0000
+++ b/main.cpp Sat Jan 28 01:35:08 2017 +0000
@@ -8,11 +8,18 @@
#define ON (1)
#define OFF (0)
-#define SAMPLING_RATE (1) /* A/D sampling rate (1kHz) */
-#define MAINCYCLE 200 /* [ms] */
+#define SAMPLING_RATE (0.01) /* A/D sampling rate (1kHz) */
+#define MAINCYCLE 20 /* [ms] */
#define DEBUG
+union u64_dataType_g
+{
+ double DData;
+ char CData[8];
+};
+
+
/*** Global Variable ***/
DigitalOut myled1(LED1); /* 起動確認用 */
DigitalOut myled2(LED2); /* 割り込み確認用 */
@@ -27,27 +34,20 @@
UINT32 g_adCnt;
+/* 変数定義 */
+uint32_t Fdiv;
+double InputData = 0;
+
+
/*** Functions ***/
-/* A/D変換割り込み */
-void ad_sampling(){
- static INT32 i = 0;
- /* 割り込み中点灯 */
- myled2 = 1;
- g_adCnt++;
- g_wave = wave_in.read() * 3.3; /*[V] */
- #ifdef DEBUG_
- i++;
- pc.printf("attach: %d,%d\r\n", i, g_adCnt);
- g_wave = i / 100 * 3.3;
- g_wave = g_adCnt * 3.3;
- if(i > 100) i = 0;
- #endif
- wait(0.01);
- /* A/D変換完了後送信 */
- g_sendFlg = 1;
- myled2 = 0;
-}
+/* 通信関数宣言 */
+void Communicaion(double data,int byte);
+void CommInit();
+double InputAnalgData();
+/* A/D変換割り込み宣言 */
+void ad_sampling();
+
INT32 main() {
@@ -56,6 +56,9 @@
DBL64 et = 0;
myled1 = 1;
+ /* 通信初期化 */
+ CommInit(); /* 初期化 */
+
/* A/D変換対タイマ割り込み開始 */
myled2 = 1;
/* Start interval timer */
@@ -75,10 +78,12 @@
if(g_sendFlg == 1) {
/* データ送信 */
i++;
- #ifdef DEBUG
- pc.printf("cnt: %d, ad cnt: %d, wave: %f\r\n", i, g_adCnt, g_wave);
+ #ifdef DEBUG_
+ pc.printf("cnt: %d, ad cnt: %d, wave: %f\r\n", i, g_adCnt, InputData);
+ /* InputData = InputData + 0.1; */
#endif
-
+
+ Communicaion(InputData,1);
/* フラグリセット */
g_sendFlg = 0;
}
@@ -89,3 +94,72 @@
Thread::wait((uint32_t)(MAINCYCLE - (et - st)));
}
}
+
+/* A/D変換割り込み */
+void ad_sampling(){
+ static INT32 i = 0;
+ /* 割り込み中点灯 */
+ myled2 = 1;
+ g_adCnt++;
+ InputData = InputAnalgData(); /*[V] */
+ #ifdef DEBUG_
+ i++;
+ pc.printf("attach: %d,%d\r\n", i, InputData);
+ g_wave = i / 100 * 3.3;
+ g_wave = g_adCnt * 3.3;
+ if(i > 100) i = 0;
+ #endif
+ /* wait(0.01); */
+ /* A/D変換完了後送信 */
+ g_sendFlg = 1;
+ myled2 = 0;
+}
+
+
+void CommInit() /* 通信初期化 */
+{
+ Fdiv = SystemCoreClock / (4 * 16 * 9600); // 9600bps
+}
+
+void Communicaion(double data,int byte)
+{
+
+ int i;
+ u64_dataType_g sendData;
+ sendData.DData = data;
+
+
+ LPC_PINCON->PINSEL0 &= ~(3 << 4);
+ LPC_PINCON->PINSEL0 |= (1 << 4); // TXD0 (01)
+
+ LPC_SC->PCLKSEL0 &= ~(3 << 6); // PCLK_UART0 ck/4 (00)
+ LPC_SC->PCONP |= (1 << 3); // PCUART0
+
+ LPC_UART0->LCR |= (1 << 7); // enable access DLAB
+ LPC_UART0->DLL = Fdiv & 0xff;
+ LPC_UART0->DLM = (Fdiv >> 8) & 0xff;
+ LPC_UART0->LCR &= ~(1 << 7); // disable access DLAB
+
+ LPC_UART0->LCR |= (3 << 0); // 8bit
+ LPC_UART0->FCR = (7 << 0); // RX1char(00), FIFO reset
+ LPC_UART0->IER = (1 << 0); // RBR
+
+ for(i=0;i<8;i++)
+ {
+ LPC_UART0->THR =sendData.CData[i];
+ }
+
+
+ NVIC_EnableIRQ(UART0_IRQn);
+
+}
+
+double InputAnalgData() /* A/D 読み取り */
+{
+ double Result = 0;
+
+ Result = (double)wave_in.read()*10*3.3;
+
+ return Result;
+}
+