[电机控制] 【Curiosity Nano测评报告】L6234 + BLDC

[复制链接]
8293|58
 楼主| MianQi 发表于 2024-9-21 17:19 | 显示全部楼层 |阅读模式
本帖最后由 MianQi 于 2024-9-21 18:09 编辑



KiCad 上没有 Curiosity Nano Kit PIC16F13145,自己画了一个。


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
LEDyyds 发表于 2024-9-23 16:01 | 显示全部楼层
能不能分享出来
 楼主| MianQi 发表于 2024-9-23 16:18 | 显示全部楼层
正在做。。。
 楼主| MianQi 发表于 2024-9-23 16:47 | 显示全部楼层
最新进展:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| MianQi 发表于 2024-9-23 16:57 | 显示全部楼层
这次要做的是将之间在 ATmega328P 上测试过的方案在 PIC16F13145 上复现一下,上次的帖子在这里 - https://bbs.21ic.com/icview-3376522-1-1.html
呐咯密密 发表于 2024-9-25 10:02 | 显示全部楼层
很好,借鉴一下
 楼主| MianQi 发表于 2024-9-25 17:29 | 显示全部楼层
LEDyyds 发表于 2024-9-23 16:01
能不能分享出来

L6234 运行的核心功能来自 PIC MCU 的 GPIO,具体来说,就是每一步有一个管脚输出高,相对应的另一个管脚输出低,我先将基础的 GPIO 程序发到回复中,重要的是要注意的几个细节。
 楼主| MianQi 发表于 2024-9-25 17:29 | 显示全部楼层
  1. // PIC16F13145 Configuration Bit Settings
  2. // 'C' source line config statements
  3. // CONFIG1
  4. #pragma config FEXTOSC = OFF    // External Oscillator Selection bits (Oscillator not enabled)
  5. #pragma config RSTOSC = LFINTOSC// Reset Oscillator Selection bits (LFINTOSC)
  6. #pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
  7. #pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
  8. #pragma config VDDAR = HI       // VDD Range Analog Calibration Selection bit (Internal analog systems are calibrated for operation between VDD = 2.3 - 5.5V)
  9. #pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)

  10. // CONFIG2
  11. #pragma config MCLRE = EXTMCLR  // Master Clear Enable bit (If LVP = 0, MCLR pin is MCLR; If LVP = 1, RA3 pin function is MCLR)
  12. #pragma config PWRTS = PWRT_OFF // Power-up Timer Selection bits (PWRT is disabled)
  13. #pragma config LPBOREN = OFF    // Low-Power BOR Enable bit (ULPBOR disabled)
  14. #pragma config BOREN = ON       // Brown-out Reset Enable bits (Brown-out Reset enabled, SBOREN bit is ignored)
  15. #pragma config DACAUTOEN = OFF  // DAC Buffer Automatic Range Select Enable bit (DAC Buffer reference range is determined by the REFRNG bit)
  16. #pragma config BORV = LO        // Brown-out Reset Voltage Selection bit (Brown-out Reset Voltage (VBOR) set to 1.9V)
  17. #pragma config PPS1WAY = ON     // PPSLOCKED One-Way Set Enable bit (The PPSLOCKED bit can be cleared and set only once after an unlocking sequence is executed; once PPSLOCKED is set, all future changes to PPS registers are prevented)
  18. #pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
  19. #pragma config DEBUG = OFF      // Background Debugger (Background Debugger disabled)

  20. // CONFIG3
  21. #pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
  22. #pragma config WDTE = OFF       // WDT Operating Mode bits (WDT Disabled, SEN is ignored)
  23. #pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
  24. #pragma config WDTCCS = SC      // WDT Input Clock Select bits (Software Control)

  25. // CONFIG4
  26. #pragma config BBSIZE = BB512   // Boot Block Size Selection bits (512 words boot block size)
  27. #pragma config BBEN = OFF       // Boot Block Enable bit (Boot Block disabled)
  28. #pragma config SAFEN = OFF      // Storage Area Flash (SAF) Enable bit (SAF disabled)
  29. #pragma config WRTAPP = OFF     // Application Block Write Protection bit (Application Block is NOT write-protected)
  30. #pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block is NOT write-protected)
  31. #pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration Register is NOT write-protected)
  32. #pragma config WRTSAF = OFF     // Storage Area Flash (SAF) Write Protection bit (SAF is NOT write-protected)
  33. #pragma config LVP = ON         // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR. MCLRE Configuration bit is ignored)

  34. // CONFIG5
  35. #pragma config CP = OFF         // Program Flash Memory Code Protection bit (Program Flash Memory code protection is disabled)

  36. // #pragma config statements should precede project file includes.
  37. // Use project enums instead of #define for ON and OFF.

  38. #include <xc.h>

  39. void main(void) {
  40.    
  41.     TRISB4 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  42.     TRISB5 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  43.    
  44.     ANSELB4 = 0;
  45.     ANSELB5 = 0;// Digital I/O. Pin is assigned to port or digital special function.
  46.     // The ANSELx bits default to the Analog mode after Reset.
  47.     // To use any pins as digital general purpose or peripheral inputs,
  48.     // the corresponding ANSEL bits must be changed to ‘0’ by the user.
  49.    
  50.     // for delay
  51.     unsigned int i = 0;
  52.    
  53.     while(1) {
  54.         
  55.         /* turn off the LED (RB5 ---> 1Kohm ---> LED ---> RB4) */
  56.         LATB4 = 1;
  57.         LATB5 = 0;
  58.         // Insert some delay
  59.         i = 500;
  60.         while(i--);
  61.         
  62.         /* turn on the LED (RB5 ---> 1Kohm ---> LED ---> RB4) */
  63.         LATB4 = 0;
  64.         LATB5 = 1;
  65.         // Insert some delay
  66.         i = 500;
  67.         while(i--);
  68.     }
  69.    
  70.     return;
  71. }



 楼主| MianQi 发表于 2024-9-25 17:36 | 显示全部楼层
要注意的细节是:
1、PIC MCU 要能正常运行,首要的是“ Configuration Bits”的设置,这个设置最重要的有两项:时钟源的选择(本例中选用内部低速振荡器)、关闭看门狗定时器(默认为开)。
2、每一个管脚在重启后默认的都是模拟模式为开,用户要自己给相应的寄存器清零,确保关闭这项功能。
grfqq325 发表于 2024-9-26 11:00 | 显示全部楼层
MCC没有备注是什么意思
 楼主| MianQi 发表于 2024-9-26 15:12 | 显示全部楼层
grfqq325 发表于 2024-9-26 11:00
MCC没有备注是什么意思

? 没明白你的意思。
 楼主| MianQi 发表于 2024-9-26 15:18 | 显示全部楼层
MianQi 发表于 2024-9-26 15:12
? 没明白你的意思。

我用的工具组合是:

    MPLAB X IDE v6.15
    XC8 v2.50
    PIC16F1xxxx_DFP(1.25.389)

IDE  提示 MCC 不可用,我就手动设置了一下。
 楼主| MianQi 发表于 2024-9-28 17:27 | 显示全部楼层
完整的电路图:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| MianQi 发表于 2024-9-28 17:30 | 显示全部楼层
实物照:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| MianQi 发表于 2024-9-28 17:31 | 显示全部楼层
程序(待测试):
  1. // PIC16F13145 Configuration Bit Settings
  2. // 'C' source line config statements
  3. // CONFIG1
  4. #pragma config FEXTOSC = OFF    // External Oscillator Selection bits (Oscillator not enabled)
  5. #pragma config RSTOSC = LFINTOSC// Reset Oscillator Selection bits (LFINTOSC)
  6. #pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
  7. #pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
  8. #pragma config VDDAR = HI       // VDD Range Analog Calibration Selection bit (Internal analog systems are calibrated for operation between VDD = 2.3 - 5.5V)
  9. #pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)

  10. // CONFIG2
  11. #pragma config MCLRE = EXTMCLR  // Master Clear Enable bit (If LVP = 0, MCLR pin is MCLR; If LVP = 1, RA3 pin function is MCLR)
  12. #pragma config PWRTS = PWRT_OFF // Power-up Timer Selection bits (PWRT is disabled)
  13. #pragma config LPBOREN = OFF    // Low-Power BOR Enable bit (ULPBOR disabled)
  14. #pragma config BOREN = ON       // Brown-out Reset Enable bits (Brown-out Reset enabled, SBOREN bit is ignored)
  15. #pragma config DACAUTOEN = OFF  // DAC Buffer Automatic Range Select Enable bit (DAC Buffer reference range is determined by the REFRNG bit)
  16. #pragma config BORV = LO        // Brown-out Reset Voltage Selection bit (Brown-out Reset Voltage (VBOR) set to 1.9V)
  17. #pragma config PPS1WAY = ON     // PPSLOCKED One-Way Set Enable bit (The PPSLOCKED bit can be cleared and set only once after an unlocking sequence is executed; once PPSLOCKED is set, all future changes to PPS registers are prevented)
  18. #pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
  19. #pragma config DEBUG = OFF      // Background Debugger (Background Debugger disabled)

  20. // CONFIG3
  21. #pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
  22. #pragma config WDTE = OFF       // WDT Operating Mode bits (WDT Disabled, SEN is ignored)
  23. #pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
  24. #pragma config WDTCCS = SC      // WDT Input Clock Select bits (Software Control)

  25. // CONFIG4
  26. #pragma config BBSIZE = BB512   // Boot Block Size Selection bits (512 words boot block size)
  27. #pragma config BBEN = OFF       // Boot Block Enable bit (Boot Block disabled)
  28. #pragma config SAFEN = OFF      // Storage Area Flash (SAF) Enable bit (SAF disabled)
  29. #pragma config WRTAPP = OFF     // Application Block Write Protection bit (Application Block is NOT write-protected)
  30. #pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block is NOT write-protected)
  31. #pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration Register is NOT write-protected)
  32. #pragma config WRTSAF = OFF     // Storage Area Flash (SAF) Write Protection bit (SAF is NOT write-protected)
  33. #pragma config LVP = ON         // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR. MCLRE Configuration bit is ignored)

  34. // CONFIG5
  35. #pragma config CP = OFF         // Program Flash Memory Code Protection bit (Program Flash Memory code protection is disabled)

  36. // #pragma config statements should precede project file includes.
  37. // Use project enums instead of #define for ON and OFF.

  38. // Wiring
  39. // PIC16F13145              L6234
  40. //         RB4              IN1
  41. //         RB5              EN1
  42. //         RB6              IN2
  43. //         RB7              EN2
  44. //         RC6              IN3
  45. //         RC7              EN3


  46. #include <xc.h>

  47. unsigned int bldc_step = 0;

  48. void AH_BL(void);
  49. void AH_CL(void);
  50. void BH_CL(void);
  51. void BH_AL(void);
  52. void CH_AL(void);
  53. void CH_BL(void);

  54. void bldc_move(void);

  55. void main(void) {
  56.    
  57.     TRISB4 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  58.     TRISB5 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  59.     TRISB6 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  60.     TRISB7 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  61.     TRISC6 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  62.     TRISC7 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  63.    
  64.     ANSELB4 = 0;
  65.     ANSELB5 = 0;// Digital I/O. Pin is assigned to port or digital special function.
  66.     // The ANSELx bits default to the Analog mode after Reset.
  67.     // To use any pins as digital general purpose or peripheral inputs,
  68.     // the corresponding ANSEL bits must be changed to ?0? by the user.
  69.     ANSELB6 = 0;
  70.     ANSELB7 = 0;
  71.     ANSELC6 = 0;
  72.     ANSELC7 = 0;
  73.                     
  74.    
  75.     // for delay
  76.     unsigned int i = 0;
  77.    
  78.     while(1) {
  79.         
  80.         bldc_move();
  81.         
  82.         /* turn off the LED (RB5 ---> 1Kohm ---> LED ---> RB4) */
  83.         LATB4 = 1;
  84.         LATB5 = 0;
  85.         // Insert some delay
  86.         //i = 500;
  87.         //while(i--);
  88.         
  89.         bldc_step++;
  90.         bldc_step %= 6;
  91.         
  92.         /* turn on the LED (RB5 ---> 1Kohm ---> LED ---> RB4) */
  93.         LATB4 = 0;
  94.         LATB5 = 1;
  95.         // Insert some delay
  96.         //i = 500;
  97.         //while(i--);
  98.     }
  99.    
  100.     return;
  101. }

  102. void bldc_move(){        // BLDC motor commutation function

  103.         switch(bldc_step){

  104.                 case 0:
  105.                 AH_BL();    // EN2 - IN1
  106.                 //BEMF_C_RISING();
  107.                 break;

  108.                 case 1:
  109.                 AH_CL();    // EN3 - IN1
  110.                 //BEMF_B_FALLING();
  111.                 break;

  112.                 case 2:
  113.                 BH_CL();    // EN3 - IN2
  114.                 //BEMF_A_RISING();
  115.                 break;

  116.                 case 3:
  117.                 BH_AL();    // EN1 - IN2
  118.                 //BEMF_C_FALLING();
  119.                 break;

  120.                 case 4:
  121.                 CH_AL();    // EN1 - IN3
  122.                 //BEMF_B_RISING();
  123.                 break;

  124.                 case 5:
  125.                 CH_BL();    // EN2 - IN3
  126.                 //BEMF_A_FALLING();
  127.                 break;
  128.         }
  129. }

  130. void AH_BL(){
  131. // EN2 - IN1
  132.     LATB4 = 1;  // IN1
  133.     LATB5 = 0;
  134.     LATB6 = 0;
  135.     LATB7 = 1;  // EN2
  136.     LATC6 = 0;
  137.     LATC7 = 0;
  138. }

  139. void AH_CL(){
  140. // EN3 - IN1
  141.     LATB4 = 1;  // IN1
  142.     LATB5 = 0;
  143.     LATB6 = 0;
  144.     LATB7 = 0;
  145.     LATC6 = 0;
  146.     LATC7 = 1;  // EN3
  147. }

  148. void BH_CL(){
  149. // EN3 - IN2
  150.     LATB4 = 0;
  151.     LATB5 = 0;
  152.     LATB6 = 1;  // IN2
  153.     LATB7 = 0;
  154.     LATC6 = 0;
  155.     LATC7 = 1;  // EN3
  156. }

  157. void BH_AL(){
  158. // EN1 - IN2
  159.     LATB4 = 0;
  160.     LATB5 = 1;  // EN1
  161.     LATB6 = 1;  // IN2
  162.     LATB7 = 0;
  163.     LATC6 = 0;
  164.     LATC7 = 0;
  165. }

  166. void CH_AL(){
  167. // EN1 - IN3
  168.     LATB4 = 0;
  169.     LATB5 = 1;  // EN1
  170.     LATB6 = 0;
  171.     LATB7 = 0;
  172.     LATC6 = 1;  // IN3
  173.     LATC7 = 0;
  174. }

  175. void CH_BL(){
  176. // EN2 - IN3
  177.     LATB4 = 0;
  178.     LATB5 = 0;
  179.     LATB6 = 0;
  180.     LATB7 = 1;  // EN2
  181.     LATC6 = 1;  // IN3
  182.     LATC7 = 0;
  183. }
捉虫天师 发表于 2024-9-29 16:15 | 显示全部楼层
台钳不错。
 楼主| MianQi 发表于 2024-10-1 10:56 | 显示全部楼层
实测程序:
  1. // PIC16F13145 Configuration Bit Settings
  2. // 'C' source line config statements
  3. // CONFIG1
  4. #pragma config FEXTOSC = OFF    // External Oscillator Selection bits (Oscillator not enabled)
  5. #pragma config RSTOSC = LFINTOSC// Reset Oscillator Selection bits (LFINTOSC)
  6. #pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
  7. #pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
  8. #pragma config VDDAR = HI       // VDD Range Analog Calibration Selection bit (Internal analog systems are calibrated for operation between VDD = 2.3 - 5.5V)
  9. #pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)

  10. // CONFIG2
  11. #pragma config MCLRE = EXTMCLR  // Master Clear Enable bit (If LVP = 0, MCLR pin is MCLR; If LVP = 1, RA3 pin function is MCLR)
  12. #pragma config PWRTS = PWRT_OFF // Power-up Timer Selection bits (PWRT is disabled)
  13. #pragma config LPBOREN = OFF    // Low-Power BOR Enable bit (ULPBOR disabled)
  14. #pragma config BOREN = ON       // Brown-out Reset Enable bits (Brown-out Reset enabled, SBOREN bit is ignored)
  15. #pragma config DACAUTOEN = OFF  // DAC Buffer Automatic Range Select Enable bit (DAC Buffer reference range is determined by the REFRNG bit)
  16. #pragma config BORV = LO        // Brown-out Reset Voltage Selection bit (Brown-out Reset Voltage (VBOR) set to 1.9V)
  17. #pragma config PPS1WAY = ON     // PPSLOCKED One-Way Set Enable bit (The PPSLOCKED bit can be cleared and set only once after an unlocking sequence is executed; once PPSLOCKED is set, all future changes to PPS registers are prevented)
  18. #pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
  19. #pragma config DEBUG = OFF      // Background Debugger (Background Debugger disabled)

  20. // CONFIG3
  21. #pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
  22. #pragma config WDTE = OFF       // WDT Operating Mode bits (WDT Disabled, SEN is ignored)
  23. #pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
  24. #pragma config WDTCCS = SC      // WDT Input Clock Select bits (Software Control)

  25. // CONFIG4
  26. #pragma config BBSIZE = BB512   // Boot Block Size Selection bits (512 words boot block size)
  27. #pragma config BBEN = OFF       // Boot Block Enable bit (Boot Block disabled)
  28. #pragma config SAFEN = OFF      // Storage Area Flash (SAF) Enable bit (SAF disabled)
  29. #pragma config WRTAPP = OFF     // Application Block Write Protection bit (Application Block is NOT write-protected)
  30. #pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block is NOT write-protected)
  31. #pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration Register is NOT write-protected)
  32. #pragma config WRTSAF = OFF     // Storage Area Flash (SAF) Write Protection bit (SAF is NOT write-protected)
  33. #pragma config LVP = ON         // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR. MCLRE Configuration bit is ignored)

  34. // CONFIG5
  35. #pragma config CP = OFF         // Program Flash Memory Code Protection bit (Program Flash Memory code protection is disabled)

  36. // #pragma config statements should precede project file includes.
  37. // Use project enums instead of #define for ON and OFF.

  38. // Wiring
  39. // PIC16F13145              L6234
  40. //         RB4              IN1
  41. //         RB5              EN1
  42. //         RB6              IN2
  43. //         RB7              EN2
  44. //         RC6              IN3
  45. //         RC7              EN3


  46. #include <xc.h>

  47. unsigned int bldc_step = 0;

  48. void AH_BL(void);
  49. void AH_CL(void);
  50. void BH_CL(void);
  51. void BH_AL(void);
  52. void CH_AL(void);
  53. void CH_BL(void);

  54. void bldc_move(void);

  55. void main(void) {
  56.    
  57.     TRISB4 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  58.     TRISB5 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  59.     TRISB6 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  60.     TRISB7 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  61.     TRISC6 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  62.     TRISC7 = 0; // PORTx output driver is enabled. PORTx pin configured as an output.
  63.    
  64.     ANSELB4 = 0;
  65.     ANSELB5 = 0;// Digital I/O. Pin is assigned to port or digital special function.
  66.     // The ANSELx bits default to the Analog mode after Reset.
  67.     // To use any pins as digital general purpose or peripheral inputs,
  68.     // the corresponding ANSEL bits must be changed to ?0? by the user.
  69.     ANSELB6 = 0;
  70.     ANSELB7 = 0;
  71.     ANSELC6 = 0;
  72.     ANSELC7 = 0;
  73.                     
  74.    
  75.     // for delay
  76.     unsigned int i = 0;
  77.    
  78.     while(1) {
  79.         
  80.         bldc_move();
  81.         // Insert some delay
  82.         //i = 10;
  83.         //while(i--);
  84.         
  85.         /* turn off the LED (RB5 ---> 1Kohm ---> LED ---> RB4) */
  86.         //LATB4 = 1;
  87.         //LATB5 = 0;
  88.         // Insert some delay
  89.         //i = 500;
  90.         //while(i--);
  91.         
  92.         bldc_step++;
  93.         bldc_step %= 6;
  94.         
  95.         /* turn on the LED (RB5 ---> 1Kohm ---> LED ---> RB4) */
  96.         //LATB4 = 0;
  97.         //LATB5 = 1;
  98.         // Insert some delay
  99.         //i = 500;
  100.         //while(i--);
  101.     }
  102.    
  103.     return;
  104. }

  105. void bldc_move(){        // BLDC motor commutation function

  106.         switch(bldc_step){

  107.                 case 0:
  108.                 AH_BL();    // EN2 - IN1
  109.                 //BEMF_C_RISING();
  110.                 break;

  111.                 case 1:
  112.                 AH_CL();    // EN3 - IN1
  113.                 //BEMF_B_FALLING();
  114.                 break;

  115.                 case 2:
  116.                 BH_CL();    // EN3 - IN2
  117.                 //BEMF_A_RISING();
  118.                 break;

  119.                 case 3:
  120.                 BH_AL();    // EN1 - IN2
  121.                 //BEMF_C_FALLING();
  122.                 break;

  123.                 case 4:
  124.                 CH_AL();    // EN1 - IN3
  125.                 //BEMF_B_RISING();
  126.                 break;

  127.                 case 5:
  128.                 CH_BL();    // EN2 - IN3
  129.                 //BEMF_A_FALLING();
  130.                 break;
  131.         }
  132. }

  133. void AH_BL(){
  134. // EN1 - EN2 - IN1
  135.     LATB4 = 1;  // IN1
  136.     LATB5 = 1;  // EN1
  137.     LATB6 = 0;
  138.     LATB7 = 1;  // EN2
  139.     LATC6 = 0;
  140.     LATC7 = 0;
  141. }

  142. void AH_CL(){
  143. // EN1 - EN3 - IN1
  144.     LATB4 = 1;  // IN1
  145.     LATB5 = 1;  // EN1
  146.     LATB6 = 0;
  147.     LATB7 = 0;
  148.     LATC6 = 0;
  149.     LATC7 = 1;  // EN3
  150. }

  151. void BH_CL(){
  152. // EN2 - EN3 - IN2
  153.     LATB4 = 0;
  154.     LATB5 = 0;
  155.     LATB6 = 1;  // IN2
  156.     LATB7 = 1;  // EN2
  157.     LATC6 = 0;
  158.     LATC7 = 1;  // EN3
  159. }

  160. void BH_AL(){
  161. // EN2 - EN1 - IN2
  162.     LATB4 = 0;
  163.     LATB5 = 1;  // EN1
  164.     LATB6 = 1;  // IN2
  165.     LATB7 = 1;  // EN2
  166.     LATC6 = 0;
  167.     LATC7 = 0;
  168. }

  169. void CH_AL(){
  170. // EN3 - EN1 - IN3
  171.     LATB4 = 0;
  172.     LATB5 = 1;  // EN1
  173.     LATB6 = 0;
  174.     LATB7 = 0;
  175.     LATC6 = 1;  // IN3
  176.     LATC7 = 1;  // EN3
  177. }

  178. void CH_BL(){
  179. // EN3 - EN2 - IN3
  180.     LATB4 = 0;
  181.     LATB5 = 0;
  182.     LATB6 = 0;
  183.     LATB7 = 1;  // EN2
  184.     LATC6 = 1;  // IN3
  185.     LATC7 = 1;  // EN3
  186. }
 楼主| MianQi 发表于 2024-10-1 11:12 | 显示全部楼层
实际运行效果演示:


 楼主| MianQi 发表于 2024-10-2 13:21 | 显示全部楼层
详细说明:

antusheng 发表于 2024-11-24 19:31 | 显示全部楼层
BLDC不是用PWM驱动吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

32

主题

394

帖子

3

粉丝
快速回复 在线客服 返回列表 返回顶部