Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include "mbed.h"
  2. #include "light.h"
  3. #include "speed.h"
  4. #include "CAN_Receive.h"
  5. #include "CAN_Send.h"
  6. DigitalOut Motor_Precharge_Relay (D8);
  7. DigitalOut Motor_Contactor_Relay (D9);
  8. DigitalOut Array_Precharge_Relay (D10);
  9. DigitalOut Array_Contactor_Relay (D11);
  10. DigitalIn Array (D0);
  11. DigitalIn Motor (D1);
  12. void Array_Relay_ON ();
  13. void Array_Relay_OFF ();
  14. void Motor_Relay_ON ();
  15. void Motor_Relay_OFF ();
  16. int Motor_Switch_Position = 0; //0 = OFF, 1 = BPS/LV, 2 = Array, 3 = Motor
  17. int main()
  18. {
  19. Thread Can_R(CAN_Receive);
  20. wait(1);
  21. Thread CAN_S(CAN_Send);
  22. wait(2);
  23. Thread Indicators(lights);
  24. wait(3);
  25. Thread Speed(speed);
  26. while (1)
  27. {
  28. switch (Motor_Switch_Position) {
  29. case 0 :
  30. //pc.printf("case0\n");
  31. Array_Relay_OFF ();
  32. Array? Motor_Switch_Position = 0 : Motor_Switch_Position = 2;
  33. wait_ms(100);
  34. break;
  35. case 2 : //pc.printf("case2\n");
  36. Array_Relay_ON ();
  37. if (Motor == 0) Motor_Switch_Position = 3;
  38. if (Array == 0) Motor_Switch_Position = 4;
  39. if (Motor & Array) Motor_Switch_Position = 0;
  40. wait_ms(100);
  41. break;
  42. case 3 :
  43. //pc.printf("case3\n");
  44. Motor_Relay_ON ();
  45. Motor? Motor_Switch_Position = 4 : Motor_Switch_Position = 5;
  46. wait_ms(100);
  47. break;
  48. case 4 : Motor_Relay_OFF ();
  49. if (Motor == 0) Motor_Switch_Position = 3;
  50. if (Array & Motor) Motor_Switch_Position = 0;
  51. //pc.printf("case4\n");
  52. wait_ms(100);
  53. break;
  54. case 5 : if(Motor == 0)Motor_Switch_Position = 5;
  55. if((Motor == 1) & (Array == 0)) Motor_Switch_Position = 4;
  56. //pc.printf("case5\n");
  57. wait_ms(100);
  58. break;
  59. }
  60. }
  61. }
  62. void
  63. Motor_Relay_ON ()
  64. {
  65. Motor_Precharge_Relay = 1;
  66. wait (5);
  67. Motor_Contactor_Relay = 1;
  68. return;
  69. }
  70. void
  71. Motor_Relay_OFF ()
  72. {
  73. Motor_Contactor_Relay = 0;
  74. Motor_Precharge_Relay = 0;
  75. return;
  76. }
  77. void
  78. Array_Relay_ON ()
  79. {
  80. Array_Precharge_Relay = 1;
  81. wait (5);
  82. Array_Contactor_Relay = 1;
  83. return;
  84. }
  85. void
  86. Array_Relay_OFF ()
  87. {
  88. Array_Contactor_Relay = 0;
  89. Array_Precharge_Relay = 0;
  90. return;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement