diff --git a/Nose/.gitignore b/Nose/.gitignore new file mode 100644 index 0000000..539d235 --- /dev/null +++ b/Nose/.gitignore @@ -0,0 +1,3 @@ +.vscode +source/trash +pullreq-memo.txt \ No newline at end of file diff --git a/Nose/24thISE_nose.qproj b/Nose/24thISE_nose.qproj new file mode 100644 index 0000000..3ce7dbf Binary files /dev/null and b/Nose/24thISE_nose.qproj differ diff --git a/Nose/Nose.ino b/Nose/Nose.ino new file mode 100644 index 0000000..0af426b --- /dev/null +++ b/Nose/Nose.ino @@ -0,0 +1,139 @@ +#include +#include +#include +#include + +#define CAN_AVAIRABLE + +#define CAN0_CS 0 +#define CAN0_INT 1 +#define LED_YELLOW LED_BUILTIN +#define LED_BLUE PIN_LED_RXL + +#define SEALEVELPRESSURE_HPA (1013.25) + +Adafruit_BME280 bme; +MCP342X myADC; +CCP_MCP2515 CCP(CAN0_CS, CAN0_INT); //CAN + +const int clockFrequency = 400000; //I2C bus speed +bool timer100Hz = false; +bool sleep_sensors = false; +bool can_checkerflag = false; +struct repeating_timer st_timer; + +void setup() { + Serial.begin(1843200); + Wire.setSDA(6); + Wire.setSCL(7); + Wire.setClock(clockFrequency); + Wire.begin(); + bme.begin(0x76); + myADC.configure(MCP342X_MODE_CONTINUOUS | MCP342X_CHANNEL_1 | MCP342X_SIZE_18BIT | MCP342X_GAIN_1X); + add_repeating_timer_us(10000, TimerIsr, NULL, &st_timer); //100Hz +#ifdef CAN_AVAIRABLE + CCP.begin(); +#endif +} + +void loop() { + static int32_t result; + static float temperature; + static float barometic_pressure; + static char adc_bytes[3]; + static double voltage; + if (timer100Hz) { + timer100Hz = false; + if (!sleep_sensors) { + //差圧センサ関連 + myADC.startConversion(); + myADC.getResult(&result); + DevideBytes(&result, adc_bytes); + ConvertToVoltage(adc_bytes, &voltage); //3つのバイトを電圧に変換 + //BME280関連 + GetBME280Data(&temperature, &barometic_pressure); +//CAN送信 +#ifdef CAN_AVAIRABLE + CCP.uint32_to_device(CCP_nose_adc, voltage); + CCP.float_to_device(CCP_nose_temperature, temperature); + CCP.float_to_device(CCP_nose_barometic_pressure, barometic_pressure); + if (can_checkerflag) { + CCP.string_to_device(CCP_nose_status, "OK"); + can_checkerflag = false; + } +#endif + + //シリアル出力 + SerialPrintSensors(adc_bytes, temperature, barometic_pressure, voltage); + } + } +#ifdef CAN_AVAIRABLE + CCP.read_device(); + switch (CCP.id) { + case CCP_EMST_mesure: + if (CCP.str_match("STOP", 4)) { + sleep_sensors = true; + } else if (CCP.str_match("CLEAR", 5)) { + sleep_sensors = false; + } + break; + case CCP_nose_adc: + if (CCP.str_match("CHECK", 5)) { + can_checkerflag = true; + } + if (CCP.str_match("KILL", 4)) { + sleep_sensors = true; + } + break; + default: + break; + } +#endif +} + +void GetBME280Data(float* temperature, float* barometic_pressure) { + *temperature = bme.readTemperature(); + *barometic_pressure = bme.readPressure(); +} + +void DevideBytes(int32_t* _result, char* bytes) { + bytes[2] = static_cast(*_result & 0xFF);//(char)から変更.C-style castを使うとunsafeなコードになるので + bytes[1] = static_cast((*_result >> 8) & 0xFF); + bytes[0] = static_cast((*_result >> 16) & 0xFF); +} + +void ConvertToVoltage(char* bytes, double* voltage) { + double pga = 1; + double lsb = 2 * 2.048 / pow(2, 18); + + byte msb = (bytes[0] >> 6) & 0x01; + uint32_t outputcode = bytes[2] | (bytes[1] << 8) | ((bytes[0] * 0x01) << 16); + if (msb == 0x00) { //正の値 + *voltage = static_cast(outputcode)*lsb / pga; + } else { //負の値 + outputcode = ((~outputcode) & 0x01FFFF) + 1; //2の補数 + *voltage = -static_cast(outputcode)*lsb / pga; + } +} + +void SerialPrintSensors(char* adc_bytes, float temperature, float barometic_pressure, double voltage) { + // if(timer100Hz) Serial.println("overrun"); + Serial.print("time:"); + Serial.print(micros()); + Serial.print(",adc_bytes:"); + Serial.print(adc_bytes[0], HEX); + Serial.print(adc_bytes[1], HEX); + Serial.print(adc_bytes[2], HEX); + Serial.print(",temperature:"); + Serial.print(temperature, 10); + Serial.print(","); + Serial.print(",barometic_pressure:"); + Serial.print(barometic_pressure, 10); + Serial.print(",voltage:"); + Serial.println(voltage, 10); +} + +bool TimerIsr(struct repeating_timer* t) { + timer100Hz = true; + return true; +} \ No newline at end of file diff --git a/Nose/README.md b/Nose/README.md new file mode 100644 index 0000000..c624172 --- /dev/null +++ b/Nose/README.md @@ -0,0 +1,72 @@ +# ノーズ電装 + +## 概要 +- This component has role of sensoring airspeed,temperature and barometic pressure. +- This component communicates with the main electrical compnent via the CAN protocol. +## ハードウェア +### BOM +#### MCU +- Seeduino Xiao RP2040 + +#### Sensor +- AE-BME280 +- MPXV5050DP +#### ADC +- MCP3421 +#### CAN +- MCP25625 +#### Component +##### Capacitor +- [100uF16V 電解コン](https://akizukidenshi.com/catalog/g/gP-05002/) +- [100uF10V 3216](https://akizukidenshi.com/catalog/g/gP-15633/) +- [1uF25V 1608](https://akizukidenshi.com/catalog/g/gP-14526/) +- [0.01uF50V 1608](https://akizukidenshi.com/catalog/g/gP-13387/) +- [470pF50V 1608](https://akizukidenshi.com/catalog/g/gP-09268/) +##### Resisiter +- [100k 1/10W 1608](https://akizukidenshi.com/catalog/g/gR-11792/) +- [49.9k 1/10W 1608](https://akizukidenshi.com/catalog/g/gR-11804/) +- [4.7k 1/10W 1608](https://akizukidenshi.com/catalog/g/gR-14121/) + +### 回路 + + +### PCB + +## ソフトウェア +### 依存関係 +- Wire.h +- CCP.h + +## 基礎知識 + +### ベルヌーイの定理 + + +$$p_1+\frac{1}{2} \rho v_1^2+\rho g z_1=p_2+\frac{1}{2}\rho v_2^2+\rho g z_2=\mathrm{const.}$$ + +https://www.cradle.co.jp/glossary/ja_H/detail0038.html + +ここで空気密度$\rho$について考える.大気の標準組成は + +- $O_2=20.99$ % +- $N_2=78.04$ % +- $CO_2=0.03$ % +- $Ar=0.94$ % + +そこから求まる大気の分子量は +$$M=28.966[\mathrm{g/mol}]$$ +となる.気体の質量密度は, +$$\rho=M\frac{n}{V}=\frac{MP}{RT}$$ +ここで,$R=8.314[\mathrm{Nmmol^{-1}K^{-1}}]$,とすると, +$$\rho=\frac{28.966\times P}{8.314\times T}$$ +とわかる. + +http://sasaki.g1.xrea.com/powerpoint/vaporization-heat/03-Air-density.pdf + + + + + + + + diff --git a/Nose/images/PCB1.png b/Nose/images/PCB1.png new file mode 100644 index 0000000..e2ee715 Binary files /dev/null and b/Nose/images/PCB1.png differ diff --git a/Nose/images/PCB2.png b/Nose/images/PCB2.png new file mode 100644 index 0000000..133b77c Binary files /dev/null and b/Nose/images/PCB2.png differ diff --git a/Nose/images/basic_knowledge/image.png b/Nose/images/basic_knowledge/image.png new file mode 100644 index 0000000..535ce09 Binary files /dev/null and b/Nose/images/basic_knowledge/image.png differ diff --git a/Nose/images/circuit.png b/Nose/images/circuit.png new file mode 100644 index 0000000..4aed486 Binary files /dev/null and b/Nose/images/circuit.png differ diff --git a/Nose/quadcept_libraries/MCP3421.qcom b/Nose/quadcept_libraries/MCP3421.qcom new file mode 100644 index 0000000..7ceab60 Binary files /dev/null and b/Nose/quadcept_libraries/MCP3421.qcom differ diff --git a/Nose/quadcept_libraries/MCP3421A3T-E_CH.xml b/Nose/quadcept_libraries/MCP3421A3T-E_CH.xml new file mode 100644 index 0000000..5112518 --- /dev/null +++ b/Nose/quadcept_libraries/MCP3421A3T-E_CH.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Nose/quadcept_libraries/MPXVseries.qcom b/Nose/quadcept_libraries/MPXVseries.qcom new file mode 100644 index 0000000..3626e5c Binary files /dev/null and b/Nose/quadcept_libraries/MPXVseries.qcom differ diff --git a/Nose/quadcept_libraries/a.qcom b/Nose/quadcept_libraries/a.qcom new file mode 100644 index 0000000..78e425f Binary files /dev/null and b/Nose/quadcept_libraries/a.qcom differ diff --git a/Nose/quadcept_libraries/xiao_original.qcom b/Nose/quadcept_libraries/xiao_original.qcom new file mode 100644 index 0000000..4b23f96 Binary files /dev/null and b/Nose/quadcept_libraries/xiao_original.qcom differ diff --git a/Nose/rp2040reset/adafruit-circuitpython-raspberry_pi_pico-ja-8.2.9.uf2 b/Nose/rp2040reset/adafruit-circuitpython-raspberry_pi_pico-ja-8.2.9.uf2 new file mode 100644 index 0000000..fdcc9bf Binary files /dev/null and b/Nose/rp2040reset/adafruit-circuitpython-raspberry_pi_pico-ja-8.2.9.uf2 differ