a
Dependencies: mbed mcp3208 HeptaTemp
Revision 0:709d290281a1, committed 2022-06-14
- Comitter:
- goro56
- Date:
- Tue Jun 14 09:22:13 2022 +0000
- Commit message:
- a
Changed in this revision
diff -r 000000000000 -r 709d290281a1 HeptaTemp.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeptaTemp.lib Tue Jun 14 09:22:13 2022 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/HEPTA/code/HeptaTemp/#845cda80eaf0
diff -r 000000000000 -r 709d290281a1 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 14 09:22:13 2022 +0000 @@ -0,0 +1,71 @@ +#include "mbed.h" +SPI spi(p11,p12,p13); +DigitalOut cs(p14); +Serial pc(USBTX, USBRX); +int main(void) +{ + int bit = 8; + spi.format(bit,0); + spi.frequency(2000000); //VDD=5Vの場合は2MHz. + printf("\r\n"); + printf("Starting MCP3208\r\n"); + float Vref = 5.08; + while(1) + { + cs = 0; + uint8_t d0 = spi.write(0x06); + uint8_t d1 = spi.write(0x40); + uint8_t d2 = spi.write(0x00); + printf("%d,%d,%d \r\n",d0,d1,d2); + uint8_t d3 = d1 << 4; + uint16_t d = (d3 << 4) | d2; // 1文にまとめると uint16_t d = (d1 << 8) | d2; + //float volt = Vref * (float)d / 4096; + //float amp = Vref * (float)d / 4096; + //printf("d=%d volt=%5.2f\n\r", d, volt); + //printf("d=%d CDH_Amp =%f [A]\n\r", d, amp); + + //tem + + float R3; + float R4; + float R5; + float Pt; + float R_1; + float R_2; + //current + float I; + //voltage + float Vreft; + +//temperature coefficient + float ce; + //resistance + R3 = 110;//[Ω] + R4 = 1000;//[Ω] + R5 = 68000;//[Ω] + Pt = 100;//[Ω] + R_1 = 3;//[kΩ] + R_2 = 2;//[kΩ] + + //current + I = 0.001;//[A] + + //voltage + Vreft = 2.5;//[V] + + //Gain&Offset + float gain = -R5*I/R4; + float off = Vreft+I*R3; + + //temperature coefficient + ce = 0.003851; + + float volt = Vref*(float)d / 4096*(R_1 + R_2)/R_1; + float Rth = (volt-off)/gain+R3; + float temp = (Rth-Pt)/(ce*Pt); + printf("d=%d EPS_Temp =%f [℃]\n\r", d, temp); + + cs = 1; + wait(1.0); + } +} \ No newline at end of file
diff -r 000000000000 -r 709d290281a1 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jun 14 09:22:13 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
diff -r 000000000000 -r 709d290281a1 mcp3208.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcp3208.lib Tue Jun 14 09:22:13 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Kemp/code/mcp3208/#e7de500b1f2d