#ifndef _ADC_H__ #define _ADC_H__ #include "bsp/bsp.h" #include "os/os_type.h" /* inserted ADC 由timer0 ch3触发, 注意:adc所有外部触发都是下降沿触发 */ #define MOTOR_TEMP_CHAN ADC_CHANNEL_0 #define HANDLERBAR_CHAN ADC_CHANNEL_1 //转把信号 #define VBUS_V_CHAN ADC_CHANNEL_2 #define W_PHASE_V_CHAN ADC_CHANNEL_3 #define V_PHASE_V_CHAN ADC_CHANNEL_4 #define U_PHASE_V_CHAN ADC_CHANNEL_5 #define W_PHASE_I_CHAN ADC_CHANNEL_6 #define V_PHASE_I_CHAN ADC_CHANNEL_7 #define U_PHASE_I_CHAN ADC_CHANNEL_8 #define VBUS_I_CHAN ADC_CHANNEL_9 #define ISQ2_OFFSET 10 #define ISO3_OFFSET 15 #define IL_OFFSET 20 #define ADC_SAMPLE_TIME ADC_SAMPLETIME_7POINT5 //#define ADC_RANK_CHANNEL(c1, c2, l) ((c1)<> ISQ3*/ static __inline__ void adc_update_insert_sample_rank(u32 adc, u8 channel) { ADC_ISQ(adc) = ADC_RANK_CHANNEL(channel); } static __inline__ void adc_update_insert_sample_time(u32 adc, uint8_t adc_channel , uint32_t sample_time) { uint32_t sampt; /* ADC sampling time config */ if(adc_channel < 10U){ sampt = ADC_SAMPT1(adc); sampt &= ~((u32)(ADC_SAMPTX_SPTN << (3U*adc_channel))); sampt |= (u32) sample_time << (3U*adc_channel); ADC_SAMPT1(adc) = sampt; }else if(adc_channel < 18U){ sampt = ADC_SAMPT0(adc); sampt &= ~((u32)(ADC_SAMPTX_SPTN << (3U*(adc_channel-10U)))); sampt |= ((u32)sample_time << (3U*(adc_channel-10U))); ADC_SAMPT0(adc) = sampt; } } static __inline__ bool adc_eoic_interrupt(void) { #if 1 if (ADC_STAT(ADC0) & ADC_STAT_EOIC){ return true; } if (ADC_STAT(ADC1) & ADC_STAT_EOIC){ return true; } #else if ((ADC_STAT(ADC0) & ADC_STAT_EOIC) && (ADC_STAT(ADC1) & ADC_STAT_EOIC)) { return true; } #endif return false; } static __inline__ void adc_clear_eoic_flags(void) { ADC_STAT(ADC0) &= ~((u32) ADC_STAT_EOIC); ADC_STAT(ADC1) &= ~((u32) ADC_STAT_EOIC); } static __inline__ void adc_insert_continue_mode(u32 adc_periph) { ADC_CTL0(adc_periph) &= ~((uint32_t)(ADC_CTL0_DISIC )); } void adc_init(void); s32 adc_sample_regular_channel(int chan, int times); void adc_start_insert_convert(void); #endif /* _ADC_H__ */