mirror of
https://github.com/rene-dev/stmbl.git
synced 2026-09-28 03:20:05 +08:00
res lesen
This commit is contained in:
+15
-7
@@ -43,7 +43,9 @@ volatile float mag_pos;
|
||||
volatile float current_scale = 1.0;
|
||||
//volatile enum state_t { low=1, } state;
|
||||
volatile int state = 0;
|
||||
volatile int t1, t2;
|
||||
|
||||
volatile int t1, t2;//rohdaten sin/cos
|
||||
volatile float res_pos;//winkel vom resolver, -pi bsi +pi
|
||||
|
||||
float minus(float a, float b){
|
||||
if(ABS(a - b) < pi){
|
||||
@@ -82,17 +84,19 @@ void TIM2_IRQHandler(void){//20KHz
|
||||
//mag_pos+=pi/100;
|
||||
output_pwm();
|
||||
|
||||
/*
|
||||
if(state == 1)
|
||||
GPIO_SetBits(GPIOC,GPIO_Pin_2);
|
||||
if(state == 0)
|
||||
GPIO_ResetBits(GPIOC,GPIO_Pin_2);
|
||||
*/
|
||||
|
||||
//GPIO_ResetBits(GPIOD,GPIO_Pin_11);
|
||||
if(state == 0){
|
||||
GPIO_SetBits(GPIOC,GPIO_Pin_4);
|
||||
//if(state == 0){
|
||||
GPIO_SetBits(GPIOC,GPIO_Pin_4);//messpin
|
||||
ADC_SoftwareStartConv(ADC1);
|
||||
ADC_SoftwareStartConv(ADC2);
|
||||
}
|
||||
//}
|
||||
state++;
|
||||
}
|
||||
|
||||
@@ -100,11 +104,12 @@ void ADC_IRQHandler(void)
|
||||
{
|
||||
while(!ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC));
|
||||
ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
|
||||
GPIO_ResetBits(GPIOC,GPIO_Pin_4);
|
||||
GPIO_ResetBits(GPIOC,GPIO_Pin_4);//messpin
|
||||
GPIO_ToggleBits(GPIOC,GPIO_Pin_2);//toggle erreger
|
||||
|
||||
t1 = ADC_GetConversionValue(ADC1);
|
||||
t2 = ADC_GetConversionValue(ADC2);
|
||||
//atan2f(res1_pos, res2_pos);
|
||||
res_pos = atan2f(t1-3111, t2-3111);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@@ -113,10 +118,13 @@ int main(void)
|
||||
TIM_Cmd(TIM4, ENABLE);//PWM
|
||||
TIM_Cmd(TIM2, ENABLE);//int
|
||||
GPIO_SetBits(GPIOD,GPIO_Pin_14);//enable
|
||||
GPIO_ResetBits(GPIOC,GPIO_Pin_2);//reset erreger
|
||||
|
||||
while(1) // Do not exit
|
||||
{
|
||||
|
||||
//printf_("%i %i", t1,t2);
|
||||
printf_("%f",RAD(res_pos));
|
||||
Wait(50);
|
||||
/*
|
||||
#ifdef USBTERM
|
||||
// Test ob USB-Verbindung zum PC besteht
|
||||
|
||||
+3
-4
@@ -86,9 +86,6 @@ void setup_pwm(){
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
|
||||
/* GPIOD clock enable */
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
||||
|
||||
/* ADC clock enable */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
@@ -134,6 +131,8 @@ void setup_pwm(){
|
||||
void setup_adc(){
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||
/* ADC clock enable */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE);
|
||||
|
||||
//Analog pin configuration
|
||||
GPIO_InitStructure.GPIO_Pin = RES_SIN_PIN;
|
||||
@@ -159,7 +158,7 @@ void setup_adc(){
|
||||
|
||||
ADC_CommonInitTypeDef ADC_CommonInitStructure;
|
||||
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
|
||||
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;
|
||||
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
|
||||
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
|
||||
ADC_CommonInit(&ADC_CommonInitStructure);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#ifdef USBTERM
|
||||
#include "stm32_ub_usb_cdc.h"
|
||||
#include "printf.h"
|
||||
#endif
|
||||
|
||||
//#define mag_res 5250
|
||||
|
||||
Reference in New Issue
Block a user