📄 imvc07.c
字号:
/***************************************************************************************************
File Name : IMVC07.c
Project : IMVC position control on ACPM750 AC Power Module Kit with TMS320LF2407 DSP controller
====================================================================================================
Target Sys : MSK2407 DSP board + ACPM750 v3.2 power module
Description : The real-time control interrupt functions; main function of the project
Originator/s: Technosoft Ltd.
Status : OK
====================================================================================================
Copyright ?2000 Technosoft
===================================================================================================*/
/*==================================================================================================
The project implements a position control on a three-phase IM motor, using TMS320LF2407 DSP controller.
Feedback sensors needed:
- position sensor, an incremental encoder connected to QEP interface;
- phase A and B currents, measured through A/D channels ADCIN6 and ADCIN5.
Uses symmetric PWM generator. Currents measurement is performed synchronized with
the PWM period.
The program uses one interrupt for control implementation, generated by the PWM timer underflow.
There, by using software counters, two control levels are considered:
- a fast loop, for current vector control implementation (at 100 microseconds sampling rate,
default value)
- a slow loop, for position control implementation (at 1 ms sampling rate, default value)
The interrupt structure is specifically adapted to the MCK2407 Technosoft Motion Control Kit.
Supplementary functionality is implemented for a reference generator and a data logger function,
usable with the DMC Developer Pro development platform of Technosoft and allowing a high-level
interface with the program, from a PC Windows environment.
===================================================================================================*/
/***************************************************************************************************
Include Files
/***************************************************************************************************
#include "IMVC07.h" /* application parameters (motor, controllers) */
#include "IMVC07h.h" /* external variables prototypes */
#include "DSP2407.h" /* 'LF2407 registers definitions */
#include "ini2407.h" /* application settings for 'LF2407 register programming */
/***************************************************************************************************
Local variables
****************************************************************************************************/
int new_pos,old_pos,stop;
/***************************************************************************************************
Functions
****************************************************************************************************/
/***************************************************************************************************
Routine Name: rtc_slow_int
------------------------
Purpose : Real-time interrupt routine, called from assembler function ISR_Kernel
Calling Convention : extern interrupt void rtc_slow_int();
Description : Implements the position control. Also calls the position reference function.
****************************************************************************************************/
interrupt void rtc_slow_int() /* position loop control RTI routine */
{
asm(" CLRC INTM"); /* enable interrupts */
read_encoder(); /* get rotor position */
pos = position; /* get the actual position */
pos_ref = reference(); /* compute the position reference */
pi_reg_pos(); /* call position controller */
logger(); /* call data logger function */
}
/***************************************************************************************************
Routine Name: rtc_middle_int
------------------------
Purpose : Real-time interrupt routine, called from assembler function ISR_Kernel
Calling Convention : extern interrupt void rtc_middle_int();
Description : Implements the speed control. Also calls the position reference function.
****************************************************************************************************/
interrupt void rtc_middle_int() /* speed loop control RTI routine */
{
read_encoder(); /* get rotor position */
new_pos = position; /* get the actual position (new position) */
asm(" CLRC INTM"); /* enable interrupts */
omg = new_pos - old_pos; /* compute the speed error */
pi_reg_omg(); /* call speed controller */
i_d_ref = 4309; /* setup id reference current */
logger(); /* call data logger function */
old_pos = new_pos; /* update the old position */
}
/***************************************************************************************************
Routine Name: rtc_fast_int
-------------------------
Purpopse : Real-time interrupt routine, called from assembler function ISR_Kernel
Calling Convention: extern interrupt void rtc_fast_int();
Description : Implements the current control. Rotoric d,q frame is used.
****************************************************************************************************/
interrupt void rtc_fast_int() /* current loop control RTI routine */
{
get_adc_pair1();
i_a = offset_ia - ad_res_0; /* read ia phase current */
i_b = offset_ib - ad_res_1; /* read ib phase current */
tabcdq(); /* Park transformation */
pi_reg_id(); /* call d-axis current controller */
pi_reg_iq(); /* call q-axis current controller */
tdqabc(); /* inverse Park transformation */
update_field_pos(); /* estimates and updates the rotor field position */
update_pwm(); /* update PWM compares values */
}
/***************************************************************************************************
Main function of the program
****************************************************************************************************/
void main(void)
{
/* general initializations section */
stop = 0; /* variable for program stop control */
ctrl_crt_per =3000;
ctrl_ps_per =30000;
ctrl_pos_per =150000;
fast_max_count = 2;
if( fast_max_count <= 2 ) fast_max_count = 2;
middle_max_count = 20;
if( middle_max_count <= 20 ) middle_max_count = 20;
slow_max_count = 100;
if( slow_max_count <= 100) slow_max_count = 100;
Init_SCSR_WS(); /* enable ADC & EVM clock and set 0 Wait-States */
reset_Error_ACPM(); /* reset Error of ACPM */
init_pdpint(); /* PDPINT initialization & reset PDPINT flag */
init_pwm(); /* PWM initialisation */
init_encoder(); /* encoder initialisation */
init_adc(); /* initialisation ADC register to working in interrupt mode */
loadsatvals(); /* enable saturation macro */
init_reg_id(); /* current d-axis controller initialisation */
init_reg_pos(); /* position controller initialisation */
init_reg_omg(); /* speed controller initialisation */
init_reg_iq(); /* current q-axis controller initialisation */
init_field_pos(); /* initializes the field position variables */
init_reference(); /* reference initialisation */
init_logger(); /* logger initialisation */
start_pwm(); /* enables PWM generation */
get_ia_ib_offsets(); /* offset detection for the current channels measurement */
new_pos = 0;
old_pos = 0;
position = 0;
omg_ref = 0;
i_q_ref = 0;
i_d_ref = 4309;
start_encoder(); /* enable QEP */
InitializeKernel();
while (1)
{
/* infinite loop */
}
END_APPL
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -