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.
Dependencies: MODSERIAL SDFileSystemSeth mbed
Fork of Opstellingbachelor_opdracht by
Diff: main.cpp
- Revision:
- 8:1326141017ea
- Parent:
- 7:9f9ea047975d
- Child:
- 9:d9ba61ce7a29
--- a/main.cpp Mon Oct 10 14:25:22 2016 +0000 +++ b/main.cpp Tue Oct 11 14:07:58 2016 +0000 @@ -8,17 +8,13 @@ //////////////////////////////////////////////////////////////////////////////// // Thermocouple pin declarations -DigitalOut SCK_1(D0); // sck pin of thermocouples -DigitalOut CS_1(D1); // chip select pin of thermocouples +DigitalOut SCK_1(PTD1); // sck pin of thermocouples +DigitalOut CS_1(PTE25); // chip select pin of thermocouples //DigitalIn pins[12]={D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13}; //thermocouples 1 - 12 select corresponding pin numbers mbed -DigitalIn pins[1]={D2}; //thermocouple 1 select corresponding pin numbers mbed - +DigitalIn pins[3]={D2, D3, D4}; //thermocouple select corresponding pin numbers mbed -float d; -//int16_t b[12] = { }; -int16_t b[1]; // Torque sensor AnalogIn fcs(PTB2); // force sensor output connected to analog 0 @@ -38,7 +34,7 @@ Ticker tick; const int baudrate = 115200; // baud rate -const float Ts = 0.1; // sample time (sec) +const float Ts = 0.25; // sample time (sec) const int led_on = 0; const int led_off = 1; @@ -82,15 +78,19 @@ //uses MAX31855 chip //see https://datasheets.maximintegrated.com/en/ds/MAX31855.pdf for documentation + + float d = 0; + int16_t b[3] = {0,0,0}; + CS_1 = 0; //Active-Low Chip Select. Set CS low to enable the serial interface. - wait_ms(70); //wait 70 ms for chip to be ready - + wait_us(0.2); + for (int i = 15; i >= 0; i--) { SCK_1 = 0; //set clock value to 0 - wait_ms(0.1); //wait for 100ns + wait_us(0.1); //wait for 100ns SCK_1 = 1; //then set clock high again - wait_ms(0.1); //wait for 100ns - for (int j = 0; j < 1; j++) { //read out bits for each thermocouple (0 to 11) + wait_us(0.1); //wait for 100ns + for (int j = 0; j < 3; j++) { //read out bits for each thermocouple (0 to 11) if (pins[j]) { b[j] |= (1 << i); //bitshift } @@ -99,16 +99,17 @@ CS_1 = 1; - for (int j = 0; j < 1; j++) { //for every thermocouple (starting from 0 to 11, so 12 in total) + for (int j = 0; j < 3; j++) { //for every thermocouple (starting from 0 to 11, so 12 in total) if (b[j] & 0x1) { //b[j] contains the bits that are received from every chip. if least significant bit is 1, then open circuit. b[j] = 20000; } else { b[j] &= 0xfffc; //if no fault then select 14 bit thermocouple data from bitstring d = b[j] / 16.0; } - fprintf(fp, "%.3f \n\r", d); - pc.printf("%.3f \n\r", d); + //fprintf(fp, "%.3f \n\r", d); + pc.printf("%.3f\t", d); } + pc.printf("\n\r"); //fprintf(fp, "\n\r"); return; @@ -118,7 +119,7 @@ { if(meas){ // alleen data uitlezen en opslaan als meas = 1 fcs_read = fcs.read(); // capture torque sensor data - fprintf(fp, "%.3f\t", fcs_read); // output data to file + //fprintf(fp, "%.3f\t", fcs_read); // output data to file pc.printf("%.3f\t", fcs_read); // output data to screen readTC(); // call function to read thermocouple data } @@ -135,7 +136,7 @@ pc.baud(baudrate); tick.attach(&fn1_activate,Ts); led_control(led_off,led_off,led_off); // start with LEDs off - + while (1) { if(fn1_go) { // statements to execute when go-flag is active fn1_go = 0;