mirror of
https://github.com/rene-dev/stmbl.git
synced 2026-02-05 18:01:21 +08:00
cleanup
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,7 +18,7 @@ term/win32/bin
|
||||
|
||||
sim/sim
|
||||
sim/plot
|
||||
|
||||
stmblx
|
||||
*.ngc
|
||||
|
||||
# Ignore list for Eagle, a PCB layout tool
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
// defines für stm32f405
|
||||
|
||||
// pid timer
|
||||
#define PID_TIM TIM5
|
||||
#define PID_TIM_RCC RCC_APB1Periph_TIM5
|
||||
#define PID_TIM_IRQN TIM5_IRQn
|
||||
|
||||
// resolver
|
||||
//// adc
|
||||
#define SIN_ADC ADC1
|
||||
|
||||
81
src/main.c
81
src/main.c
@@ -18,8 +18,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//#include <stm32f4_discovery.h>
|
||||
#include <stm32f4xx_conf.h>
|
||||
#include "stm32f4xx_conf.h"
|
||||
#include "printf.h"
|
||||
#include "scanf.h"
|
||||
#include "hal.h"
|
||||
@@ -170,49 +169,46 @@ void link_ac_sync_enc(){//berger lahr
|
||||
set_hal_pin("pid0.acc_max", 13000.0 / 60.0 * 2.0 * M_PI / 0.005);
|
||||
}
|
||||
|
||||
void DMA2_Stream0_IRQHandler(void){
|
||||
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
|
||||
GPIO_SetBits(GPIOB,GPIO_Pin_4);
|
||||
GPIO_ResetBits(LED_R_PORT,LED_R_PIN);//led
|
||||
int freq = 5000;
|
||||
float period = 1.0 / freq;
|
||||
//GPIO_ResetBits(GPIOB,GPIO_Pin_3);//messpin
|
||||
|
||||
for(int i = 0; i < hal.fast_rt_func_count; i++){
|
||||
hal.fast_rt[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_in_func_count; i++){
|
||||
hal.rt_in[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_filter_func_count; i++){
|
||||
hal.rt_filter[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_pid_func_count; i++){
|
||||
hal.rt_pid[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_calc_func_count; i++){
|
||||
hal.rt_calc[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_out_func_count; i++){
|
||||
hal.rt_out[i](period);
|
||||
}
|
||||
GPIO_ResetBits(GPIOB,GPIO_Pin_4);
|
||||
void DMA2_Stream0_IRQHandler(void){ //5kHz
|
||||
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
|
||||
GPIO_SetBits(GPIOB,GPIO_Pin_4);
|
||||
GPIO_ResetBits(LED_R_PORT,LED_R_PIN);//led
|
||||
int freq = 5000;
|
||||
float period = 1.0 / freq;
|
||||
//GPIO_ResetBits(GPIOB,GPIO_Pin_3);//messpin
|
||||
|
||||
for(int i = 0; i < hal.fast_rt_func_count; i++){
|
||||
hal.fast_rt[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_in_func_count; i++){
|
||||
hal.rt_in[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_filter_func_count; i++){
|
||||
hal.rt_filter[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_pid_func_count; i++){
|
||||
hal.rt_pid[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_calc_func_count; i++){
|
||||
hal.rt_calc[i](period);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hal.rt_out_func_count; i++){
|
||||
hal.rt_out[i](period);
|
||||
}
|
||||
GPIO_ResetBits(GPIOB,GPIO_Pin_4);
|
||||
}
|
||||
|
||||
//disabled in setup.c
|
||||
void TIM8_UP_TIM13_IRQHandler(void){ //20KHz
|
||||
TIM_ClearITPendingBit(TIM8, TIM_IT_Update);
|
||||
//GPIO_SetBits(GPIOB,GPIO_Pin_3);//messpin
|
||||
}
|
||||
|
||||
void TIM5_IRQHandler(void){ //5KHz
|
||||
TIM_ClearITPendingBit(TIM5, TIM_IT_Update);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float period = 0.0;
|
||||
@@ -259,7 +255,6 @@ int main(void)
|
||||
|
||||
TIM_Cmd(TIM8, ENABLE);//int
|
||||
TIM_Cmd(TIM4, ENABLE);//PWM
|
||||
TIM_Cmd(TIM5, ENABLE);//PID
|
||||
|
||||
link_pid();
|
||||
link_ac_sync_res();
|
||||
@@ -286,8 +281,8 @@ int main(void)
|
||||
{
|
||||
Wait(10);
|
||||
GPIO_SetBits(LED_R_PORT,LED_R_PIN);//led
|
||||
period = time/1000.0 + (1.0 - SysTick->VAL/RCC_Clocks.HCLK_Frequency)/1000.0 - lasttime;
|
||||
lasttime = time/1000.0 + (1.0 - SysTick->VAL/RCC_Clocks.HCLK_Frequency)/1000.0;
|
||||
period = systime/1000.0 + (1.0 - SysTick->VAL/RCC_Clocks.HCLK_Frequency)/1000.0 - lasttime;
|
||||
lasttime = systime/1000.0 + (1.0 - SysTick->VAL/RCC_Clocks.HCLK_Frequency)/1000.0;
|
||||
for(int i = 0; i < hal.nrt_func_count; i++){
|
||||
hal.nrt[i](period);
|
||||
}
|
||||
@@ -295,7 +290,7 @@ int main(void)
|
||||
}
|
||||
|
||||
void Wait(unsigned int ms){
|
||||
volatile unsigned int t = time + ms;
|
||||
while(t >= time){
|
||||
volatile unsigned int t = systime + ms;
|
||||
while(t >= systime){
|
||||
}
|
||||
}
|
||||
|
||||
202
src/setup.c
202
src/setup.c
@@ -8,104 +8,26 @@
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
void setup_led(){
|
||||
RCC_AHB1PeriphClockCmd(LED_R_IO_RCC, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(LED_Y_IO_RCC, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(LED_G_IO_RCC, ENABLE);
|
||||
|
||||
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_InitStructure.GPIO_Pin = LED_R_PIN;
|
||||
GPIO_Init(LED_R_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = LED_Y_PIN;
|
||||
GPIO_Init(LED_Y_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = LED_G_PIN;
|
||||
GPIO_Init(LED_G_PORT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void setup(){
|
||||
|
||||
//PC6 PB5
|
||||
//UB_ENCODER_TIM3_Init(ENC_T3_MODE_4AB, ENC_T3_A, 2000);
|
||||
//TIM4:PWM
|
||||
//TIM8:int
|
||||
|
||||
//messpin
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
|
||||
//messpin
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
|
||||
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(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
//int timer
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
|
||||
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//wird in UB_USB_CDC_Init() nochmal gesetzt!
|
||||
|
||||
/* int set up, TIM8*/
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseStructure.TIM_Period = 420*2;//20kHz
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = 9;
|
||||
//TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
|
||||
TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE);
|
||||
TIM_SelectOutputTrigger(TIM8, TIM_TRGOSource_Update);
|
||||
|
||||
RCC_AHB1PeriphClockCmd(RES_IO_RCC, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = RES_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(RES_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(RES_PORT, GPIO_PinSource5, GPIO_AF_TIM8);
|
||||
|
||||
|
||||
|
||||
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
|
||||
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
|
||||
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
|
||||
TIM_OCInitStructure.TIM_Pulse = 300;
|
||||
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
|
||||
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
|
||||
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
|
||||
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
|
||||
|
||||
|
||||
/* PWM1 Mode configuration: Channel1 */
|
||||
TIM_OC1Init(TIM8, &TIM_OCInitStructure);
|
||||
TIM_OC1PreloadConfig(TIM8, TIM_OCPreload_Enable);
|
||||
|
||||
//TIM8->CCR1 = 300;
|
||||
|
||||
TIM_CtrlPWMOutputs(TIM8, ENABLE);
|
||||
|
||||
/* int NVIC setup */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
setup_usart();
|
||||
setup_res();
|
||||
setup_pid_timer();
|
||||
setup_res();
|
||||
setup_led();
|
||||
|
||||
// systick timer
|
||||
time = 0;
|
||||
systime = 0;
|
||||
|
||||
RCC_GetClocksFreq(&RCC_Clocks);
|
||||
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
|
||||
@@ -118,6 +40,26 @@ void setup(){
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup_led(){
|
||||
RCC_AHB1PeriphClockCmd(LED_R_IO_RCC, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(LED_Y_IO_RCC, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(LED_G_IO_RCC, ENABLE);
|
||||
|
||||
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_InitStructure.GPIO_Pin = LED_R_PIN;
|
||||
GPIO_Init(LED_R_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = LED_Y_PIN;
|
||||
GPIO_Init(LED_Y_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = LED_G_PIN;
|
||||
GPIO_Init(LED_G_PORT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void setup_usart(){
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
USART_InitTypeDef USART_InitStruct;
|
||||
@@ -139,7 +81,7 @@ void setup_usart(){
|
||||
GPIO_InitStruct.GPIO_Pin = UART_DRV_RX_PIN;
|
||||
GPIO_Init(UART_DRV_RX_PORT, &GPIO_InitStruct);
|
||||
|
||||
USART_InitStruct.USART_BaudRate = 2000000;//2000000
|
||||
USART_InitStruct.USART_BaudRate = DATABAUD;
|
||||
USART_InitStruct.USART_WordLength = USART_WordLength_9b;
|
||||
USART_InitStruct.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStruct.USART_Parity = USART_Parity_No;
|
||||
@@ -180,30 +122,54 @@ void setup_usart(){
|
||||
USART_DMACmd(UART_DRV, USART_DMAReq_Tx, ENABLE);
|
||||
}
|
||||
|
||||
|
||||
void setup_pid_timer(){
|
||||
/* TIM5 clock enable */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
|
||||
|
||||
/* pid int set up, TIM5*/
|
||||
// Setup Resolver Interface
|
||||
// TIM8 triggers ADC1 and 2 at 20kHz
|
||||
// TIM8 OC1 generates resolver reference signal at 10kHz
|
||||
// DMA2 moves 4 samples to memory, generates transfer complete interrupt at 5kHz
|
||||
void setup_res(){
|
||||
//resolver timer
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
|
||||
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseStructure.TIM_Period = 1680;//5kHz
|
||||
TIM_TimeBaseStructure.TIM_Period = 420*2;//20kHz
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = 9;
|
||||
//TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
|
||||
TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE);
|
||||
|
||||
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
|
||||
TIM_ITConfig(TIM8, TIM_IT_Update, DISABLE);
|
||||
TIM_SelectOutputTrigger(TIM8, TIM_TRGOSource_Update);//trigger ADC
|
||||
|
||||
//resolver ref signal generation
|
||||
RCC_AHB1PeriphClockCmd(RES_IO_RCC, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = RES_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(RES_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(RES_PORT, GPIO_PinSource5, GPIO_AF_TIM8);
|
||||
|
||||
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
|
||||
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
|
||||
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
|
||||
TIM_OCInitStructure.TIM_Pulse = 300;
|
||||
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
|
||||
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
|
||||
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
|
||||
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
|
||||
|
||||
TIM_OC1Init(TIM8, &TIM_OCInitStructure);
|
||||
TIM_OC1PreloadConfig(TIM8, TIM_OCPreload_Enable);
|
||||
TIM_CtrlPWMOutputs(TIM8, ENABLE);
|
||||
|
||||
/* int NVIC setup */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 12;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
// Setup ADC
|
||||
void setup_res(){
|
||||
|
||||
RCC_AHB1PeriphClockCmd(SIN_IO_RCC, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(COS_IO_RCC, ENABLE);
|
||||
/* ADC clock enable */
|
||||
@@ -231,26 +197,26 @@ void setup_res(){
|
||||
ADC_InitStructure.ADC_NbrOfConversion = ADC_ANZ;//I think this one is clear :p
|
||||
ADC_InitStructure.ADC_ScanConvMode = ENABLE;//The scan is configured in one channel
|
||||
ADC_Init(SIN_ADC, &ADC_InitStructure);//Initialize ADC with the previous configuration
|
||||
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
|
||||
ADC_Init(COS_ADC, &ADC_InitStructure);//Initialize ADC with the previous configuration
|
||||
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
|
||||
ADC_Init(COS_ADC, &ADC_InitStructure);//Initialize ADC with the previous configuration
|
||||
|
||||
ADC_CommonInitTypeDef ADC_CommonInitStructure;
|
||||
ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult;
|
||||
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;
|
||||
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;
|
||||
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
|
||||
ADC_CommonInit(&ADC_CommonInitStructure);
|
||||
ADC_CommonInitTypeDef ADC_CommonInitStructure;
|
||||
ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult;
|
||||
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;
|
||||
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;
|
||||
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
|
||||
ADC_CommonInit(&ADC_CommonInitStructure);
|
||||
|
||||
for(int i = 1;i<=ADC_ANZ;i++){
|
||||
ADC_RegularChannelConfig(SIN_ADC, SIN_ADC_CHAN, i, RES_SampleTime);
|
||||
ADC_RegularChannelConfig(COS_ADC, COS_ADC_CHAN, i, RES_SampleTime);
|
||||
}
|
||||
for(int i = 1;i<=ADC_ANZ;i++){
|
||||
ADC_RegularChannelConfig(SIN_ADC, SIN_ADC_CHAN, i, RES_SampleTime);
|
||||
ADC_RegularChannelConfig(COS_ADC, COS_ADC_CHAN, i, RES_SampleTime);
|
||||
}
|
||||
|
||||
ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
|
||||
ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
|
||||
|
||||
//Enable ADC conversion
|
||||
ADC_Cmd(SIN_ADC,ENABLE);
|
||||
ADC_Cmd(COS_ADC,ENABLE);
|
||||
//Enable ADC conversion
|
||||
ADC_Cmd(SIN_ADC,ENABLE);
|
||||
ADC_Cmd(COS_ADC,ENABLE);
|
||||
|
||||
// Clock Enable
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
|
||||
@@ -290,5 +256,5 @@ void setup_res(){
|
||||
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
time++;
|
||||
systime++;
|
||||
}
|
||||
|
||||
32
src/setup.h
32
src/setup.h
@@ -9,8 +9,8 @@
|
||||
#ifndef test_setup_h
|
||||
#define test_setup_h
|
||||
|
||||
#include <stm32f4_discovery.h>
|
||||
#include <stm32f4xx_conf.h>
|
||||
#include "stm32f4_discovery.h"
|
||||
#include "stm32f4xx_conf.h"
|
||||
#include "misc.h"
|
||||
#include "defines_res.h"
|
||||
|
||||
@@ -21,25 +21,6 @@
|
||||
//#define mag_res 5250
|
||||
#define mag_res 8400
|
||||
|
||||
|
||||
// res in:
|
||||
// ADC1: SIN: PA3 ADC1 IN3, ADC2 IN3, ADC3 IN3
|
||||
// ADC2: COS: PB1 ADC1 IN9, ADC2 IN9
|
||||
// TODO: RCC_AHB1PeriphClockCmd hardcoded in setup.c
|
||||
#define RES_SIN_PIN GPIO_Pin_3
|
||||
#define RES_SIN_PORT GPIOA
|
||||
#define RES_SIN_CHANNEL ADC_Channel_3
|
||||
|
||||
#define RES_COS_PIN GPIO_Pin_1
|
||||
#define RES_COS_PORT GPIOB
|
||||
#define RES_COS_CHANNEL ADC_Channel_9
|
||||
|
||||
#define PWM_U TIM4->CCR1
|
||||
#define PWM_V TIM4->CCR2
|
||||
#define PWM_W TIM4->CCR3
|
||||
#define PWM_E TIM4->CCR4
|
||||
|
||||
|
||||
//sample times for F4: 3,15,28,56,84,112,144,480
|
||||
#define RES_SampleTime ADC_SampleTime_28Cycles
|
||||
|
||||
@@ -49,19 +30,18 @@
|
||||
void setup();
|
||||
void setup_res();
|
||||
void setup_pwm();
|
||||
void setup_pid_timer();
|
||||
void setup_usart();
|
||||
void setup_led();
|
||||
void SysTick_Handler(void);
|
||||
|
||||
volatile unsigned int time;
|
||||
|
||||
volatile uint32_t ADC_DMA_Buffer[ADC_ANZ*PID_WAVES];
|
||||
volatile uint16_t UART_DMA_Buffer[7];
|
||||
volatile unsigned int systime;
|
||||
|
||||
#define DATALENGTH 3
|
||||
#define DATABAUD 2000000;
|
||||
|
||||
volatile uint32_t ADC_DMA_Buffer[ADC_ANZ*PID_WAVES];
|
||||
volatile uint16_t UART_DMA_Buffer[DATALENGTH*2+1];
|
||||
|
||||
typedef union{
|
||||
uint16_t data[DATALENGTH];
|
||||
uint8_t byte[DATALENGTH*2];
|
||||
|
||||
@@ -16,7 +16,7 @@ typedef union{
|
||||
uint8_t byte[DATALENGTH*2];
|
||||
}data_t;
|
||||
|
||||
volatile unsigned int time = 0;
|
||||
volatile unsigned int systime = 0;
|
||||
volatile float u,v,w;
|
||||
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
@@ -29,14 +29,14 @@ USART_InitTypeDef USART_InitStruct;
|
||||
__IO uint16_t ADCConvertedValue[ADC_channels];
|
||||
|
||||
void Wait(unsigned int ms){
|
||||
volatile unsigned int t = time + ms;
|
||||
while(t >= time){
|
||||
volatile unsigned int t = systime + ms;
|
||||
while(t >= systime){
|
||||
}
|
||||
}
|
||||
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
time++;
|
||||
systime++;
|
||||
}
|
||||
|
||||
//set pll to 24MHz
|
||||
|
||||
Reference in New Issue
Block a user