miniFOC 1.0.3
This open-source project aims to accomplish a FOC(Field Oriented Control) scheme that is operatable with minimum costs in China.
gd32f1x0_it.c
Go to the documentation of this file.
1/**************************************************************************/
9#include "gd32f1x0_it.h"
10#include "main.h"
11
16static unsigned char systick_counter = 0;
17
21void NMI_Handler(void) {
22}
23
28 /* if Hard Fault exception occurs, go to infinite loop */
29 while (1);
30}
31
36 /* if Memory Manage exception occurs, go to infinite loop */
37 while (1);
38}
39
43void BusFault_Handler(void) {
44 /* if Bus Fault exception occurs, go to infinite loop */
45 while (1);
46}
47
52 /* if Usage Fault exception occurs, go to infinite loop */
53 while (1);
54}
55
59void SVC_Handler(void) {
60}
61
65void DebugMon_Handler(void) {
66}
67
71void PendSV_Handler(void) {
72}
73
77void SysTick_Handler(void) {
78 /* update millisecond delay counter */
81
82 /* reduce the frequency to SPEED_UP_FREQ, update the current rotor speed */
83 if (systick_counter == (1000 / SPEED_UP_FREQ)) {
86 }
87}
88
93 /* judge whether a reception interrupt is generated */
94 if (RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE)) {
95 /* receive, process and unzip data */
96 unsigned char rcv_data = usart_data_receive(USART0);
97 mdtp_receive_handler(rcv_data);
98 }
99}
100
105 /* judge whether a timer update interrupt is generated, clear timer interrupt flag bit */
106 if (SET == timer_interrupt_flag_get(TIMER2, TIMER_INT_UP)) {
107 timer_interrupt_flag_clear(TIMER2, TIMER_INT_UP);
108
109 /* obtain the electric angle at the current time */
110 float u, v, w, angle = (float) encoder_get_electronic_angle();
111
112 /* Clarke inverse transform and SVPWM modulation */
113 if (phase_sequence == 0)
114 foc_calculate_dutycycle(angle, 0, FOC_Struct.user_expect, &u, &v, &w);
115 else
116 foc_calculate_dutycycle(angle, 0, FOC_Struct.user_expect, &v, &u, &w);
117 update_pwm_dutycycle(u, v, w);
118 }
119}
120
125 /* judge whether a timer update interrupt is generated, clear timer interrupt flag bit */
126 if (SET == timer_interrupt_flag_get(TIMER13, TIMER_INT_UP)) {
127 timer_interrupt_flag_clear(TIMER13, TIMER_INT_UP);
128
129 /* judge whether angle closed-loop control is required */
131 /* the calculated value of the angle loop is taken as the expected value of the speed loop */
134
135 /* calculate the speed loop PID and obtain the calculated value */
137 }
138}
#define SPEED_UP_FREQ
set speed update frequency to 200Hz
Definition: config.h:32
void encoder_update_speed(void)
called every 2 milliseconds to calculate the speed.
Definition: encoder.c:106
float encoder_get_electronic_angle(void)
according to the electrical angle calculated from the mechanical angle, this function will call encod...
Definition: encoder.c:93
void foc_calculate_dutycycle(float elect_angle, float d, float q, float *u, float *v, float *w)
calculate the corresponding three-phase PWM duty cycle under the current electrical angle
Definition: foc.c:99
volatile FOC_Structure_t FOC_Struct
FOC handler.
Definition: foc.c:20
volatile unsigned char phase_sequence
motor phase sequence flag variable
Definition: foc.c:24
void TIMER2_IRQHandler(void)
this function handles TIMER2 TIMER_INT_UP interrupt request
Definition: gd32f1x0_it.c:104
void UsageFault_Handler(void)
this function handles UsageFault exception
Definition: gd32f1x0_it.c:51
void HardFault_Handler(void)
this function handles HardFault exception
Definition: gd32f1x0_it.c:27
void MemManage_Handler(void)
this function handles MemManage exception
Definition: gd32f1x0_it.c:35
void SVC_Handler(void)
this function handles SVC exception
Definition: gd32f1x0_it.c:59
void PendSV_Handler(void)
this function handles PendSV exception
Definition: gd32f1x0_it.c:71
void NMI_Handler(void)
this function handles NMI exception
Definition: gd32f1x0_it.c:21
void BusFault_Handler(void)
this function handles BusFault exception
Definition: gd32f1x0_it.c:43
void TIMER13_IRQHandler(void)
this function handles TIMER13 TIMER_INT_UP interrupt request
Definition: gd32f1x0_it.c:124
void USART0_IRQHandler(void)
this function handles USART RBNE interrupt request
Definition: gd32f1x0_it.c:92
void SysTick_Handler(void)
this function handles SysTick exception
Definition: gd32f1x0_it.c:77
static unsigned char systick_counter
systick interrupt count variable is used to realize the encoder update function.
Definition: gd32f1x0_it.c:16
void DebugMon_Handler(void)
this function handles DebugMon exception
Definition: gd32f1x0_it.c:65
gd32f1x0 interrupt handler function header file
main function Header File
volatile unsigned char pid_control_mode_flag
flag variable of PID closed loop mode
Definition: pid.c:20
volatile PID_Structure_t angle_pid_handler
algorithm handler of PID angle loop
Definition: pid.c:28
volatile PID_Structure_t speed_pid_handler
algorithm handler of PID speed loop
Definition: pid.c:24
float pid_calculate_result(PID_Structure_t *pid_handler, float collect)
calculate result using sampling value
Definition: pid.c:61
#define ANGLE_LOOP_CONTROL
angle loop control mode
Definition: pid.h:18
float user_expect
user expect value of miniFOC
Definition: foc.h:20
float rotate_speed
motor rotate speed calculate from timer
Definition: foc.h:19
float mechanical_angle
mechanical angle read form encoder
Definition: foc.h:18
structure of PID algorithm
Definition: pid.h:24
float expect
user expectations in PID
Definition: pid.h:29
void delay_decrement(void)
delay counter decrement function, called by systick handler
Definition: system.c:38
void update_pwm_dutycycle(float ch0, float ch1, float ch2)
update timer1 ch0 1 2 duty-cycle
Definition: timer.c:20
void mdtp_receive_handler(unsigned char data)
medium capacity data transmission protocol unpacking handler
Definition: uart.c:36