00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 //_____ I N C L U D E S ___________________________________________________ 00012 00013 00014 #ifdef __ICCAVR__ // IAR C Compiler 00015 #include "config.h" 00016 #include "lib_mcu/compiler.h" 00017 #include "lib_mcu/mcu.h" 00018 #include "lib_mcu/adc/adc_drv.h" 00019 #include "mc_interface.h" 00020 #include "inavr.h" 00021 #include <stdio.h> 00022 #endif 00023 00024 #ifdef __GNUC__ // GNU C Compiler 00025 #include "config_for_gcc.h" 00026 #include <avr/io.h> 00027 #include "mc_interface.h" 00028 #endif 00029 00030 00031 00032 //_____ M A C R O S ________________________________________________________ 00033 00034 00035 //_____ D E F I N I T I O N S ______________________________________________ 00036 void init(void); 00037 void ADC_Init(void); 00038 void ADC_start_conv(void); 00039 void ushell_task_init(void); 00040 void ushell_task(void); 00041 void PSC_Init(unsigned int ot0, unsigned int ot1); 00042 //void PSC_Start(void); 00043 U16 mc_control_speed_16b(U16 speed_ref , U16 speed_measure); 00044 U16 get_Hall_Period(void); 00045 void store_new_amplitude(U16 new_val); 00046 S16 read_acquisition(void); 00047 void Start_ADC(void); 00048 00049 00050 //_____ D E C L A R A T I O N S ____________________________________________ 00051 volatile U8 Main_Tick = 0; 00052 volatile S16 Ref_Speed = 0; 00053 00054 extern volatile U8 Flag_IT_ADC; 00055 extern volatile S16 User_Speed; 00056 extern volatile U16 Measured_Speed; 00057 extern volatile Bool mci_run_stop; 00058 00059 00060 int main(void) 00061 { 00062 00063 init(); 00064 00065 ADC_Init(); 00066 00067 ushell_task_init(); 00068 00069 PSC_Init(2, MAX_PWM); 00070 00071 // PSC_Start(); /* for the first time MC100*/ 00072 00073 00074 while(1) 00075 { 00076 00077 if (Main_Tick) 00078 { 00079 Main_Tick=0; 00080 // Start_ADC(); 00081 00082 if (mci_run_stop == RUN) 00083 { 00084 Ref_Speed = User_Speed; 00085 } 00086 else 00087 { 00088 Ref_Speed = 0; 00089 } 00090 00091 Measured_Speed = (U16)K_SPEED / get_Hall_Period(); 00092 mci_store_measured_speed((U8)Measured_Speed); 00093 00094 #if (REGULATION_MODE == 2) 00095 store_new_amplitude( mc_control_speed_16b((U16) Ref_Speed , (U16) Measured_Speed) ); 00096 #else 00097 if (mci_run_stop == RUN) 00098 { 00099 00100 // store_new_amplitude( AMPLITUDE_IN_OPEN_LOOP ); 00101 store_new_amplitude( Ref_Speed ); 00102 } 00103 else 00104 { 00105 store_new_amplitude( 0 ); 00106 } 00107 #endif 00108 ushell_task(); 00109 } 00110 00111 if (Flag_IT_ADC) 00112 { 00113 00114 mci_store_measured_current(read_acquisition()); 00115 00116 Flag_IT_ADC=0; 00117 } /* end of Flag_IT_ADC */ 00118 00119 #ifdef MC200 00120 /* test the overcurrent input MC200 */ 00121 if (( PIFR0 & (1<<PEV0A)) !=0 ) 00122 { 00123 /* fault on overcurrent */ 00124 Set_PC3(); /* switch on the overcurrent led */ 00125 Clear_PE1(); /* switch off the run/stop led */ 00126 while (1) ; /* infinite loop */ 00127 } 00128 #endif 00129 00130 } /* end of while(1) */ 00131 } /* end of main */ 00132 00133
1.5.3