- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- Permalink
- 印刷
- 不適切なコンテンツを報告
少し前に、たまにはアナログのセンサも良いかなと KXSC7-2050 が乗っている AE-KXSC7-2050 というモジュールを
秋月から買ってきてサンプルを書いていたのですが、いざ投稿しようという段になって調べてみると
このセンサーは既にディスコンになっている代物でした。 orz
While ago, I think it was before summer, again I was hunting for a new sensor.
This time I wanted to try some analog type sensor, so I got a module with KXSC7-2050
and wrote a sample program.
But just before submitting the project, it was found that the device was already EOL. (And I was SOL)
で、現役の奴はないの? と調べていたら同じく秋月で AE-KXR94-2050 というのがありましたので
ゲットしてきてサンプルを書いてみました。
So I tried to find some stayin'alive sensor and found a module with KXR94-2050.
And here is the sample program I wrote for it.
3軸加速度センサモジュール KXR94−2050: 半導体 秋月電子通商-電子部品・ネット通販
このモジュールはすでにローパスなどが組み込まれている為、ADCに接続してやるだけですぐに動かすことができました。
Since this module has low-pass, only connecting signals to ADC input made it work.
回路図
ピン配置 / pin assign
main.c
====================
#include "project.h"
#include "stdio.h"
char str[128] ; /* print buffer */
void print(char *str)
{
UART_UartPutString(str) ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
ADC_Start() ;
}
void splash(void)
{
sprintf(str, "KXR94 Test Program (%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
void measure(float *x, float *y, float *z)
{
int ix, iy, iz ;
ADC_StartConvert() ;
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) ;
ix = ADC_GetResult16(0) ;
iy = ADC_GetResult16(1) ;
iz = ADC_GetResult16(2) ;
*x = (float)(ix - 1000) / 400.0 ;
*y = (float)(iy - 1000) / 400.0 ;
*z = (float)(iz - 1000) / 400.0 ;
}
void print_float(float data)
{
char *format = "%d.%03d" ;
if (data < 0.0) {
data *= -1.0 ;
format = "-%d.%03d" ;
}
sprintf(str, format, (int)data, (int)(data * 1000) % 1000) ;
print(str) ;
}
void print_data(float x, float y, float z)
{
print_float(x) ;
print(", ") ;
print_float(y) ;
print(", ") ;
print_float(z) ;
print("\n") ;
}
int main(void)
{
float x, y, z ;
init_hardware() ;
splash() ;
print(" X, Y, Z\n") ;
for(;;)
{
measure(&x, &y, &z) ;
print_data(x, y, z) ;
CyDelay(100) ;
}
}
====================
TeraTerm log
Serial Plot log
moto
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- Permalink
- 印刷
- 不適切なコンテンツを報告
本サンプルは CQ出版 インターフェース 2019年9月号に
ふえる今どきセンサNote
第19回 意外と便利なアナログ出力3軸加速度センサ
として掲載されました。
I contributed this sample project to a Japanese technical magazine
"Interface" Sep/2019 edition.
moto