⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cicuit.c

📁 基于Cortex-M3的全自动焊接机
💻 C
字号:

#define  PART_LM3S811
#include "pin_map.h"
#include "hw_types.h"
#include "hw_memmap.h"
#include  <hw_sysctl.h>
#include  <hw_sysctl.h>
#include  <sysctl.h>

#include  "pwm_init.h"
#include  "hip4081.h"
#include  "uart_init.h"
#include  <hw_timer.h>
#include  <timer.h>
#include  <hw_ints.h>
#include  <interrupt.h>
#include "motor.h"
#include "globaltype.h"
#include "define.h"

#include  "pwm.h"
#include  "pwm_init.h"
#include  "sys_tick.h"
#define  SysCtlPeriEnable       SysCtlPeripheralEnable
#define  SysCtlPeriDisable      SysCtlPeripheralDisable
#define  GPIOPinTypeOut         GPIOPinTypeGPIOOutput

unsigned int timerloadvalue;
extern struct placed_relate_parm palced_magor[];
extern unsigned long ulPeriod;
extern unsigned char send_sem;
void  clock_init(void)
{

    SysCtlLDOSet(SYSCTL_LDO_2_75V);                             //  配置PLL前需将LDO电压设置为2.75V

    SysCtlClockSet(SYSCTL_USE_PLL |                             //  系统时钟设置,采用PLL
                   SYSCTL_OSC_MAIN |                            //  主振荡器
                   SYSCTL_XTAL_6MHZ |                           //  外接6MHz晶振
                   SYSCTL_SYSDIV_10);                            //  分频结果为20MHz
}
void timer0_init(void)
{
    SysCtlPeriEnable(SYSCTL_PERIPH_TIMER0);                     //  使能定时器模块
    TimerConfigure(TIMER0_BASE , TIMER_CFG_32_BIT_PER);         //  配置定时器为32位周期定时器
    TimerLoadSet(TIMER0_BASE , TIMER_A , timerloadvalue);            //  设置定时器初值1s定时
    //使能定时器计数
    TimerEnable(TIMER0_BASE , TIMER_A);                         

}
void timer1_init(void)
{
    SysCtlPeriEnable(SYSCTL_PERIPH_TIMER1);                     //  使能定时器模块
    TimerConfigure(TIMER1_BASE , TIMER_CFG_32_BIT_PER);         //  配置定时器为32位周期触发定时器
    IntEnable(INT_TIMER1A);                                     //  使能定时器中断
}
void motor_capture_A_init(void)
{
    Motor_Int1_A_IOInit();
    Motor_Int2_A_IOInit();
    Motor_Int3_A_IOInit();
}

void motor_capture_B_init(void)
{
    Motor_Int1_B_IOInit();
    Motor_Int2_B_IOInit();
    Motor_Int3_B_IOInit();
}

void cpu_interrupt(void)
{
    IntMasterEnable();                                  /*  使能处理器中断              */
}
void cpu_dis_interrupt(void)
{
    IntMasterDisable();
}
void con_485_init(void)
{
    SysCtlPeriEnable(CON_485);
    GPIOPinTypeOut(CON_485_BASE, CON_485_PIN);
}
void exchange_485_rec(void)
{
    GPIOPinWrite(CON_485_BASE,CON_485_PIN,0x04);//高电平接收
}
void exchange_485_send(void)
{
    GPIOPinWrite(CON_485_BASE,CON_485_PIN,0x00);//低电平发送
}
void circuit(void)
{
    unsigned int delay;
    unsigned char motor;
   
    clock_init();                        //  系统初始化
    timerloadvalue = SysCtlClockGet();
    
   
    motor_capture_A_init();
    motor_capture_B_init();
    pwm_init();
    
   
    
    Motor1_Enable_IOinit();
    Motor2_Enable_IOinit();
    Motor3_Enable_IOinit();

    uart0Init();
    
    timer0_init();//测量电机速度
    
    timer1_init();//485收发切换
    con_485_init();
    cpu_interrupt();
    
    start_systick();//检测电机是否停止
    //电机初始状态设置,设定占空比30%,此时不去捕获返回的码
    Motor1_Enable(Stop);//关闭电机
    Motor2_Enable(Stop);//关闭电机
    Motor3_Enable(Stop);//关闭电机
    
    for(motor = 0; motor < 3; motor++)
    {
        palced_magor[motor].start_speed = 266666; //30%占空比
        palced_magor[motor].end_speed = 266666;
        //palced_magor[motor].start_speed = 1052631; //10%占空比
        //palced_magor[motor].end_speed = 1052631;
      
        palced_magor[motor].g_up_code = UP_CODE;//避免出现除零错误
        palced_magor[motor].g_stab_codenumber = 0;
        palced_magor[motor].g_down_code = DOWN_CODE;
        
        palced_magor[motor].total_codenumber = 0;
        palced_magor[motor].sem = 0;
        palced_magor[motor].absulotely_code = 0;
        palced_magor[motor].stop_sem = 0;
        palced_magor[motor].help_dir_code = 0;
        palced_magor[motor].motor_current_duty = 6000;// 这个起始占空比要测量的
        palced_magor[motor].EncoCnt = 0;
        palced_magor[motor].motor_exe_step = 1;
    }
    //考虑累计误差的话,那么开IO中断应在初始化中进行,且不能关闭
    //要不要动态改变优先级呢
    GPIOPinIntEnable(Motor_Enco_PORT1 ,Motor1_Enco_A);
    //IntPrioritySet(INT_GPIOB , 0 << 5);    

    GPIOPinIntEnable(Motor_Enco_PORT2 ,Motor2_Enco_A);             
    //IntPrioritySet(INT_GPIOC , 1 << 5);

    GPIOPinIntEnable(Motor_Enco_PORT3 ,Motor3_Enco_A);             
    //IntPrioritySet(INT_GPIOD , 2 << 5); 
    
    //暂时还没有使能电机B相中断//可以设置一个时钟节拍来定时开启开中断
    GPIOPinIntEnable(Motor_Enco_PORT1 ,Motor1_Enco_B);
    GPIOPinIntEnable(Motor_Enco_PORT2 ,Motor2_Enco_B);             
    GPIOPinIntEnable(Motor_Enco_PORT3 ,Motor3_Enco_B);             
    
    
    exchange_485_rec();
    send_sem = 0;//当前状态为接收
    stop_timer1();     
    for(delay = 0xffff;delay>0;delay--);
    for(delay = 0x9fff;delay>0;delay--);
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -