📄 main.c
字号:
/**
* @file main.c
*
* Copyright (c) 2006 Atmel.
*
* @brief This module provides the main infinite loop.\n
* It generates the ramp up sequence and then calls the regulation loop
* and the uart command interpreter
* @version 1.0 (CVS revision : $Revision: 1.4 $)
* @date $Date: 2006/07/12 12:58:27 $
* @author $Author: raubree $
*****************************************************************************/
#include "config.h"
#include "config_motor.h"
#include "mc_interface.h"
#include "mc_control.h"
#include "mc_drv.h"
#include "ushell_task.h"
#include "adc\adc_drv.h"
#include "comparator\comparator_drv.h"
U16 g_regulation_period = 0; //!< Define the sampling period
U16 g_speed_monitor_period = 0;
extern Bool g_tick; //!see mc_drv.c Use for sampling time
Bool ramp_up = FALSE;
U8 tick_divider;
U8 new_position = HS_001; // arbitrary rotor position for Ramp Up Sequence
U8 tick_divider_min = 50;
U8 ramp_counter = 0;
void mc_ramp_up_init(void)
{
ramp_counter = 0;
tick_divider_min = 50;
new_position = HS_001;
ramp_up = TRUE;
g_speed_monitor_period = 0;
}
void main(void)
{
ushell_task_init();
// init motor
mc_motor_init(); // launch initialization of the motor
while(1)
{
// Show PSC state according to the Over Current information
if(PCTL2 & (1<<PRUN2)) switch_OFF_LED();// PSC ON
else switch_ON_LED();//PSC OFF => Over_Current
// Launch regulation loop
// Timer 1 generate an IT (g_tick) all 250us
// Sampling period = n * 250us
if (g_tick == TRUE)
{
g_tick = FALSE;
// Get Current and potentiometer value
mc_ADC_Scheduler();
if (ramp_up == TRUE)
{
/* BEGIN OF RAMP UP SEQUENCE */
Disable_comparator0_interrupt(); // disable bemf interrupt
Disable_comparator1_interrupt(); // disable bemf interrupt
Disable_comparator2_interrupt(); // disable bemf interrupt
ramp_counter += 1;
if ( ramp_counter >= 40 )
{
ramp_counter = 0;
if (tick_divider_min > 3)
{
tick_divider_min -= 1;
}
else
{
ramp_up = FALSE;
g_speed_monitor_period = 1;
// mc_set_Speed_Loop(); // speed regulation loop
mc_set_Open_Loop(); // no regulation loop
mci_set_motor_speed(180);
mc_regulation_loop();
Enable_comparator0_interrupt(); // enable the bemf signal
Enable_comparator1_interrupt(); // enable the bemf signal
Enable_comparator2_interrupt(); // enable the bemf signal
}
}
tick_divider += 1;
if ( tick_divider >= tick_divider_min )
{
tick_divider = 0;
if (mci_get_motor_direction()==CCW)
{
switch(new_position)
{
/* ramp up CCW */
case HS_001:
new_position = HS_011;
break;
case HS_101:
new_position = HS_001;
break;
case HS_100:
new_position = HS_101;
break;
case HS_110:
new_position = HS_100;
break;
case HS_010:
new_position = HS_110;
break;
case HS_011:
new_position = HS_010;
break;
default :
new_position = HS_001;
break;
}
}
else
{
switch(new_position)
{
/* ramp_up CW */
case HS_001:
new_position = HS_101;
break;
case HS_101:
new_position = HS_100;
break;
case HS_100:
new_position = HS_110;
break;
case HS_110:
new_position = HS_010;
break;
case HS_010:
new_position = HS_011;
break;
case HS_011:
new_position = HS_001;
break;
default :
new_position = HS_001;
break;
}
}
mc_switch_commutation(new_position);
}
/* END OF RAMP UP SEQUENCE */
}
g_regulation_period += 1;
if ( g_regulation_period >= 8 ) //n * 250us = Te : 2mS
{
g_regulation_period = 1;
mc_regulation_loop(); // launch regulation loop
}
/* monitor the speed */
if (mci_run_stop == RUN)
{
g_speed_monitor_period += 1;
if ( g_speed_monitor_period >= 4000 ) //n * 250us = 1S
{
g_speed_monitor_period = 1;
if (mci_get_measured_speed() > 250) mc_ramp_up_init();
if (mci_get_measured_speed() < (100/27)) mc_ramp_up_init();
}
}
/* monitor the uart communication */
ushell_task();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -