Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <stddef.h>
  3. #include <stdbool.h>
  4. #include <math.h>
  5.  
  6. /* Driver Header files */
  7. #include <ti/drivers/GPIO.h>
  8.  
  9. /* Example/Board Header files */
  10. #include "Board.h"
  11. #include <ti/drivers/UART.h>
  12. #include <ti/drivers/I2C.h>
  13.  
  14. long double BerekenTemp(long double Tdie,long double Vobj)
  15. {
  16. long double Tref = 298.15;
  17. long double a1 = 0.00175;
  18. long double a2 = -0.00001678;
  19. long double b0 = -0.0000294;
  20. long double b1 = -0.00000057;
  21. long double b2 = 0.00000000463;
  22. long double c2 = 13.4;
  23. long double s0 = 5*pow(10,-14); //calibratiefactor
  24.  
  25. long double Vobj2 = (double)Vobj*.00000015625;
  26. long double Tdie2 = (double)Tdie*.03125 + 273.15;
  27.  
  28. long double S = s0*(1+a1*(Tdie2 - Tref)+a2*pow((Tdie2 - Tref),2));
  29. long double Vos = b0 + b1*(Tdie2 - Tref) + b2*pow((Tdie2 - Tref),2);
  30. long double fObj = (Vobj2 - Vos) + c2*pow((Vobj2 - Vos),2);
  31. long double Tobj = pow(pow(Tdie2,4) + (fObj/S),.25);
  32. return Tobj - 273;
  33.  
  34. }
  35.  
  36. //// Calulate temperature from the TMP006 datasheet
  37. // long double calculateTemp(int Tdie, int Vobj)
  38. //{
  39. // long double Vobj2 = (double)Vobj*.00000015625;
  40. // long double Tdie2 = (double)Tdie*.03125 + 273.15;
  41. // long double S0 = 2.867*pow(10,-14); // Tommy's S0
  42. // //long double S0 = 6.033*pow(10,-14);
  43. // long double a1 = 1.70*pow(10,-3);
  44. // long double a2 = -2.0*pow(10,-5);
  45. // long double b0 = -2.57*pow(10,-5);
  46. // long double b1 = -9.48*pow(10,-8);
  47. // long double b2 = 2.26*pow(10,-10);
  48. // long double c2 = 0;
  49. // long double Tref = 298.15;
  50. // long double S = S0*(1+a1*(Tdie2 - Tref)+a2*pow((Tdie2 - Tref),2));
  51. // long double Vos = b0 + b1*(Tdie2 - Tref) + b2*pow((Tdie2 - Tref),2);
  52. // long double fObj = (Vobj2 - Vos) + c2*pow((Vobj2 - Vos),2);
  53. // long double Tobj = pow(pow(Tdie2,4) + (fObj/S),.25);
  54. // return (Tobj - 273.15);
  55. //}
  56.  
  57. /*
  58. * ============= mainThread ===============
  59. *
  60. * Dit is de 'main' functie van het project
  61. * Debugger is ingesteld om hier te te pauzeren
  62. * i.p.v. bij de originele main-functie
  63. *
  64. * Tips:
  65. * 1. Controleer de 'Linked Resources'
  66. * onder 'project properties' om
  67. * compilerproblemen te voorkomen
  68. *
  69. * 2. Gebruik 'Board.html' uit het project om
  70. * de pinnamen te zien van de driver
  71. *
  72. */
  73. void *mainThread(void *arg0)
  74. {
  75. GPIO_init();
  76.  
  77.  
  78. I2C_init();
  79. //opens i2c instance
  80. I2C_Handle i2cHandle;
  81. I2C_Params i2cParams;
  82. i2cHandle = I2C_open(Board_I2C0, NULL);
  83. if (i2cHandle == NULL) {
  84. // Error opening I2C
  85. while (1);
  86. }
  87.  
  88. //
  89. // //i2c transactie, reading from peripheral adress 0x41 (tempsensor), adress 0xFE ( manufacters id)
  90. // uint8_t readBuffer[2];
  91. // uint8_t writeBuffer[1] = 0xFE;
  92. // I2C_Transaction i2cTransaction;
  93. // i2cTransaction.slaveAddress = 0x41;//adres van de peripheral
  94. // i2cTransaction.writeBuf = writeBuffer; // adres van het register IN de peripheral dat uitgelezen moet worden
  95. // i2cTransaction.writeCount = 1; //het adres van het register IN de peripheral dat uitgelezen moet worden moet eerst naar de peripheral geschreven worden
  96. // i2cTransaction.readBuf = readBuffer;
  97. // i2cTransaction.readCount = 2;
  98. // bool status = I2C_transfer(i2cHandle, &i2cTransaction);
  99. // if (status == false) {
  100. // // Unsuccessful I2C transfer
  101. // }
  102.  
  103. //i2c transactie, reading from peripheral adress 0x41 (tempsensor)
  104. uint8_t readBufferTemp[2];
  105. uint8_t writeBufferTemp[1] = 0x01;
  106. I2C_Transaction i2cTransactionTemp;
  107. i2cTransactionTemp.slaveAddress = 0x41;//adres van de peripheral
  108. i2cTransactionTemp.writeBuf = writeBufferTemp; // adres van het register IN de peripheral dat uitgelezen moet worden
  109. i2cTransactionTemp.writeCount = 1; //het adres van het register IN de peripheral dat uitgelezen moet worden moet eerst naar de peripheral geschreven worden
  110. i2cTransactionTemp.readBuf = readBufferTemp;
  111. i2cTransactionTemp.readCount = 2;
  112. bool statusTemp = I2C_transfer(i2cHandle, &i2cTransactionTemp);
  113. if (statusTemp == false) {
  114. // Unsuccessful I2C transfer
  115. }
  116.  
  117. //i2c transactie, reading from peripheral adress 0x41 (tempsensor)
  118. uint8_t readBufferSpanning[2];
  119. uint8_t writeBufferSpanning[1] = 0x00;
  120. I2C_Transaction i2cTransactionSpanning;
  121. i2cTransactionSpanning.slaveAddress = 0x41;//adres van de peripheral
  122. i2cTransactionSpanning.writeBuf = writeBufferSpanning; // adres van het register IN de peripheral dat uitgelezen moet worden
  123. i2cTransactionSpanning.writeCount = 1; //het adres van het register IN de peripheral dat uitgelezen moet worden moet eerst naar de peripheral geschreven worden
  124. i2cTransactionSpanning.readBuf = readBufferSpanning;
  125. i2cTransactionSpanning.readCount = 2;
  126. bool statusSpanning = I2C_transfer(i2cHandle, &i2cTransactionSpanning);
  127. if (statusSpanning == false) {
  128. // Unsuccessful I2C transfer
  129. }
  130.  
  131.  
  132. int16_t SpanningWaarde = readBufferSpanning[1] | readBufferSpanning[0]<<8;
  133. int16_t TempWaarde = readBufferTemp[1] | readBufferTemp[0]<<8;
  134.  
  135. float SpanningVolt = SpanningWaarde*156.25*pow(10,-9);
  136. float TempCelsius = TempWaarde<<2;
  137. TempCelsius = TempCelsius/32;
  138.  
  139.  
  140.  
  141. float RealTempCelsius = BerekenTemp(SpanningVolt, TempCelsius);
  142.  
  143.  
  144. while(1);
  145.  
  146. //opens uart instance, reads byte and writes byte back in terminal
  147. char input;
  148. UART_Handle uart;
  149. UART_Params uartParams;
  150. // Initialize the UART driver.
  151. UART_init();
  152. // Create a UART with data processing off.
  153. UART_Params_init(&uartParams);
  154. uartParams.writeDataMode = UART_DATA_BINARY;
  155. uartParams.readDataMode = UART_DATA_BINARY;
  156. uartParams.readReturnMode = UART_RETURN_FULL;
  157. uartParams.readEcho = UART_ECHO_OFF;
  158. uartParams.baudRate = 115200;
  159. // Open an instance of the UART drivers
  160. uart = UART_open(Board_UART0, &uartParams);
  161.  
  162.  
  163. UART_write(uart, "hallo ik ben juul",17 );
  164.  
  165. if (uart == NULL) {
  166. // UART_open() failed
  167. while (1);
  168. }
  169.  
  170.  
  171. // Loop forever echoing
  172. while (1) {
  173. int vlag = UART_read(uart, &input, 1);
  174. if(vlag != 0)
  175. {
  176. GPIO_toggle(Board_GPIO_LED0);
  177. }
  178. UART_write(uart, &input, 1);
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement