#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "pwm.h"
#include "math.h"
#include "stdlib.h"
volatile long ix = 0;
volatile long ixi = 0;
volatile typedef struct band
{
long Bandf;
long Bandp;
long Bandarr;
float dn;
}xaxis;
static xaxis xaccelerate[31]={{0},{0},{0}};
static xaxis *px=xaccelerate;
static long Stav=180,Movv=2160;
long Staf;
void BandTabCreat()
{
int i=0;
float T=0.25;
float st=T/32;
//float Ti=0;
float a=(Movv-Stav)/T;
float k = 8.8888;
//long Movf=Movv*k;
Staf=Stav*k;
while(i<31)
{
if(i==0)
{
px.Bandf=(i+1)*st*a*k+Staf;
px.Bandarr=84000000.0/(2*px.Bandf);
px.dn=84000000.0/(2*px.Bandf)-px.Bandarr;
px.Bandp=st*px.Bandf;
i++;
}
else
{
px.Bandf=(i+1)*st*a*k+Staf;
px.Bandarr=84000000.0/(2*px.Bandf);
px.dn=84000000.0/(2*px.Bandf)-px.Bandarr+px[i-1].dn;
if (px.dn<1)
{
px.Bandp=px.Bandp=st*px.Bandf;
i++;
}
else
{
px.Bandp=px.Bandp=st*px.Bandf+1;
px.dn=px.dn-1;
i++;
}
}
}
}
void TIM2_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2,TIM_IT_Update)==SET)
{
if (ix==0&&ixi==0)
{
TIM_SetAutoreload(TIM2,1/px[ixi].Bandarr);
ix+=1;
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
}
else if(ix<px[ixi].Bandp&&ixi<32)
{
ix+=1;
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
}
else if(ix==px[ixi].Bandp&&ixi<32)
{
TIM_SetAutoreload(TIM2,1/px[ixi+1].Bandarr);
ixi+=1;
ix=0;
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
}
else if(ixi==32)
{
ixi=40;
}
}
}
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
BandTabCreat();
delay_ms(50);
TIM2_PWM_Init(px[1].Bandarr,2);
while(1)
{
}
} |