analog_input.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "at32f403a_407.h"
  2. #include "analog_input.h"
  3. #include "shift_reg.h"
  4. #include "utility.h"
  5. #include "FreeRTOS.h"
  6. #include "task.h"
  7. #include <stdio.h>
  8. uint8_t input_mux; // выход сдвигового регистра U1010 (управляет MUX 301, 401)
  9. // мультиплексоры отвечат за коммутацию аналоговых входов и АЦП
  10. //
  11. void ai_connect_channel_301(uint8_t ch)
  12. {
  13. input_mux &= 0x70;
  14. switch (ch)
  15. {
  16. case AN_INP_1: input_mux |= 0x03; break; // U301 Y3
  17. case AN_INP_2: input_mux |= 0x00; break; // U301 Y0
  18. case AN_INP_3: input_mux |= 0x05; break; // U301 Y5
  19. case AN_INP_4: input_mux |= 0x07; break; // U301 Y7
  20. case AN_INP_5: input_mux |= 0x06; break; // U301 Y6
  21. case AN_INP_6: input_mux |= 0x04; break; // U301 Y4
  22. case V_ISO_CL: input_mux |= 0x01; break; // U301 Y1
  23. case V_ISO : input_mux |= 0x02; break; // U301 Y2
  24. default: break;
  25. }
  26. printf("Analog input connect register: ");
  27. print_binary_byte(input_mux);
  28. printf("\r\n");
  29. }
  30. //
  31. void ai_connect_channel_401(uint8_t ch)
  32. {
  33. input_mux &= 0x07;
  34. switch (ch)
  35. {
  36. case AN_INP_7: input_mux |= (0x04 << 3); break; // U401 Y4
  37. case AN_INP_8: input_mux |= (0x06 << 3); break; // U401 Y6
  38. case AN_INP_9: input_mux |= (0x07 << 3); break; // U401 Y7
  39. case AN_INP_10:input_mux |= (0x05 << 3); break; // U401 Y5
  40. case AN_INP_11:input_mux |= (0x02 << 3); break; // U401 Y2
  41. case AN_INP_12:input_mux |= (0x01 << 3); break; // U401 Y1
  42. case CRNT_LIM_U_BFR_R: input_mux |= (0x00 << 3); break; // U401 Y0
  43. case CRNT_LIM_U_ABFR_R: input_mux |= (0x03 << 3); break; // U401 Y3
  44. default: break;
  45. }
  46. printf("Analog input connect register: ");
  47. print_binary_byte(input_mux);
  48. printf("\r\n");
  49. }
  50. //
  51. void ai_connect_test(void)
  52. {
  53. ai_connect_channel_301(AN_INP_1);
  54. ai_connect_channel_301(AN_INP_2);
  55. ai_connect_channel_301(AN_INP_3);
  56. ai_connect_channel_301(AN_INP_4);
  57. ai_connect_channel_301(AN_INP_5);
  58. ai_connect_channel_301(AN_INP_6);
  59. ai_connect_channel_301(V_ISO_CL);
  60. ai_connect_channel_301(V_ISO);
  61. ai_connect_channel_401(AN_INP_7);
  62. ai_connect_channel_401(AN_INP_8);
  63. ai_connect_channel_401(AN_INP_9);
  64. ai_connect_channel_401(AN_INP_10);
  65. ai_connect_channel_401(AN_INP_11);
  66. ai_connect_channel_401(AN_INP_12);
  67. ai_connect_channel_401(CRNT_LIM_U_BFR_R);
  68. ai_connect_channel_401(CRNT_LIM_U_ABFR_R);
  69. }