mirror of
https://github.com/rene-dev/stmbl.git
synced 2026-09-24 08:46:28 +08:00
resolver - dac
This commit is contained in:
+20
-47
@@ -41,7 +41,7 @@ volatile int res2_pos;
|
||||
volatile int res1_neg;
|
||||
volatile int res2_neg;
|
||||
volatile int res_avg;
|
||||
volatile int res_avg_tmp;
|
||||
//volatile int res_avg_tmp;
|
||||
|
||||
volatile int followe;
|
||||
|
||||
@@ -225,45 +225,9 @@ void TIM2_IRQHandler(void){//PWM int handler, 10KHz
|
||||
|
||||
void TIM7_IRQHandler(void){//DAC int handler
|
||||
TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
|
||||
dacpos++;//DMA fragen?
|
||||
if(dacpos >= 32){
|
||||
dacpos = 0;
|
||||
}
|
||||
|
||||
if((dacpos >= read_pos - read_w && dacpos <= read_pos + read_w) || (dacpos >= read_neg - read_w || dacpos <= (read_neg + read_w) % 32)){// phase shift 2
|
||||
ADC_SoftwareStartConv(ADC1);
|
||||
ADC_SoftwareStartConv(ADC2);
|
||||
//ADC_SoftwareStartConv(ADC3);
|
||||
}
|
||||
if(dacpos == read_pos - read_w - 1){
|
||||
res_avg = (res_avg_tmp/(read_w*4+2)/2)*0.2f+res_avg*0.8f;
|
||||
res_avg_tmp = 0;
|
||||
}
|
||||
if(dacpos == read_pos + read_w + 1){
|
||||
res_pos_pos.y = res1_pos;
|
||||
res_pos_pos.x = res2_pos;
|
||||
res_pos_pos = norm(res_pos_pos);
|
||||
|
||||
res1_pos = 0;
|
||||
res2_pos = 0;
|
||||
|
||||
}
|
||||
if(dacpos == (read_neg + read_w + 1) % 32){
|
||||
res_neg_pos.y = res1_neg;
|
||||
res_neg_pos.x = res2_neg;
|
||||
res_neg_pos = norm(res_neg_pos);
|
||||
|
||||
res1_neg = 0;
|
||||
res2_neg = 0;
|
||||
|
||||
res_pos = res_pos_pos;//mid(res_pos_pos, res_neg_pos);
|
||||
mot_pos = new_ang(DEG(UB_ENCODER_TIM3_ReadPos() * 360.0 / 2000.0 * 1.0));
|
||||
|
||||
pid();
|
||||
//mag_offset = new_ang(DEG(0));
|
||||
mag_pos = res_pos;//plus(mag_pos, new_ang(DEG(0.01)));
|
||||
output_pwm();
|
||||
}
|
||||
GPIO_SetBits(GPIOD,GPIO_Pin_11);
|
||||
ADC_SoftwareStartConv(ADC1);
|
||||
ADC_SoftwareStartConv(ADC2);
|
||||
}
|
||||
|
||||
|
||||
@@ -272,14 +236,27 @@ void ADC_IRQHandler(void)
|
||||
int t1, t2;
|
||||
while(!ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC));
|
||||
ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
|
||||
GPIO_SetBits(GPIOD,GPIO_Pin_11);
|
||||
GPIO_ResetBits(GPIOD,GPIO_Pin_11);
|
||||
|
||||
|
||||
t1 = ADC_GetConversionValue(ADC1);
|
||||
t2 = ADC_GetConversionValue(ADC2);
|
||||
res_avg_tmp += t1+t2;
|
||||
res_avg = res_avg * 0.95 + (t1 + t2) * 0.05;
|
||||
t1 -= res_avg;
|
||||
t2 -= res_avg;
|
||||
|
||||
if(dacpos % 4 == 0 || dacpos % 4 == 1){
|
||||
GPIO_SetBits(GPIOA,GPIO_Pin_7);
|
||||
}else{
|
||||
GPIO_ResetBits(GPIOA,GPIO_Pin_7);
|
||||
}
|
||||
|
||||
if(dacpos >= 3){
|
||||
dacpos = 0;
|
||||
}else{
|
||||
dacpos++;
|
||||
}
|
||||
|
||||
float max = 930;
|
||||
if(dacpos >= read_pos - read_w && dacpos <= read_pos + read_w){
|
||||
res1_pos += t1;
|
||||
@@ -289,9 +266,6 @@ void ADC_IRQHandler(void)
|
||||
res1_neg -= t1;
|
||||
res2_neg -= t2;
|
||||
}
|
||||
|
||||
|
||||
GPIO_ResetBits(GPIOD,GPIO_Pin_11);
|
||||
}
|
||||
|
||||
/*void findoff(void){
|
||||
@@ -415,8 +389,7 @@ int main(void)
|
||||
offsetc = new_ang(DEG(240));
|
||||
|
||||
res_avg = 2051;
|
||||
res_avg_tmp = 0;
|
||||
dacpos = 31;
|
||||
dacpos = 0;
|
||||
init_pid();
|
||||
param_init();
|
||||
setup();
|
||||
|
||||
+10
-3
@@ -12,7 +12,7 @@ void setup(){
|
||||
//TIM7: DAC krams, auf PA5
|
||||
UB_DAC_DMA_Init(SINGLE_DAC2_DMA);
|
||||
UB_DAC_DMA_SetWaveform2(DAC_WAVE1_SINUS);
|
||||
UB_DAC_DMA_SetFrq2(0,1312);
|
||||
UB_DAC_DMA_SetFrq2(0,4199);
|
||||
|
||||
//PC6 PB5
|
||||
UB_ENCODER_TIM3_Init(ENC_T3_MODE_4AB, ENC_T3_A, 2000);
|
||||
@@ -59,6 +59,13 @@ void setup(){
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //neuer res erreger
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_TIM4);
|
||||
GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_TIM4);
|
||||
GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_TIM4);
|
||||
@@ -97,11 +104,11 @@ void setup(){
|
||||
ADC_Cmd(ADC3,ENABLE);
|
||||
|
||||
//Select the channel to be read from
|
||||
ADC_RegularChannelConfig(ADC1,ADC_Channel_1,1,ADC_SampleTime_84Cycles);
|
||||
ADC_RegularChannelConfig(ADC1,ADC_Channel_1,1,ADC_SampleTime_480Cycles);
|
||||
ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);
|
||||
ADC_EOCOnEachRegularChannelCmd(ADC1,ENABLE);
|
||||
|
||||
ADC_RegularChannelConfig(ADC2,ADC_Channel_2,1,ADC_SampleTime_84Cycles);
|
||||
ADC_RegularChannelConfig(ADC2,ADC_Channel_2,1,ADC_SampleTime_480Cycles);
|
||||
ADC_ITConfig(ADC2,ADC_IT_EOC,DISABLE);
|
||||
ADC_EOCOnEachRegularChannelCmd(ADC2,DISABLE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user