打印

新手发帖实验 水一帖秒删

[复制链接]
148|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
张さん|  楼主 | 2018-7-29 20:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#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)
        {

        
        }
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

448

主题

464

帖子

1

粉丝