TSoC CY8C4146LQI-S433 基板 アナログ出力 3軸加速度センサ KXR94-2050 サンプル

Tip / ログイン to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

少し前に、たまにはアナログのセンサも良いかなと 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.

IMG_3661_S.jpg

回路図

003-schematic2.JPG

002-schematic1.JPG

ピン配置 / pin assign

004-pin-assign.JPG

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

000-TeraTerm-Log.JPG

Serial Plot log

001-Serial-Plot.JPG

moto

0 件の賞賛
1 返信
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

本サンプルは CQ出版 インターフェース 2019年9月号に

2019年9月号 | Interface – CQ出版

ふえる今どきセンサNote

第19回 意外と便利なアナログ出力3軸加速度センサ

として掲載されました。

I contributed this sample project to a Japanese technical magazine

"Interface" Sep/2019 edition.

moto

0 件の賞賛