经典款嵌入式智能小车的设计技巧,提供硬件选型
用硬件描述语言描述驱动的过程。
process(Bus2IP_Clk,slv_reg1,the_end)
begin
if slv_reg1=x00000000 then
counter=x00000000;
chao_out = 0;
div_clk=0;
elsif rising_edge(Bus2IP_Clk) then
if the_end = 1 then
chao_out = 1;
counter=counter+1;
if(counter=x1F4) then
counter=x00000000;
chao_out = 0;
div_clk=1;
end if;
end if;
end if;
end process;
-- implement slave model software accessible register(s) read mux
SLAVE_REG_READ_PROC : process( Bus2IP_Resetn,slv_reg_read_sel, slv_reg0, slv_reg1,Bus2IP_Clk,div_clk ) is
begin
case slv_reg_read_sel is
when 10 =>
if Bus2IP_Resetn = 0 then
timer_count = x00000000;
the_end = 0;
elsif div_clk=1 then
if slv_chao_in=1 then
the_end = 0;
timer_count = timer_count + 1;
else
slv_ip2bus_data = timer_count; --slv_reg0;
the_end = 1;
timer_count = x00000000;
end if;
else
slv_ip2bus_data = slv_reg0;
end if;
when 01 => slv_ip2bus_data = slv_reg1;
when others => slv_ip2bus_data = (others => 0);
end case;
end process SLAVE_REG_READ_PROC;
5.3 PWM模块的调试
由于需要两路的PWM来分别操作舵机和直流电机,所有PWM的调试时至关重要的。
代码如下:
int main()
{
unsigned long i,j;
//close PWM
PWM_IP_mWriteSlaveReg1(XPAR_PWM_IP_0_BASEADDR,0,0x00); //PWM0
PWM_IP_mWriteSlaveReg1(XPAR_PWM_IP_1_BASEADDR,0,0x00); //PWM1
for(i=0;i=99999;i++);
PWM_deal(0x2E);
while(1)
{
PWM_deal(0x2E);
delay(60);
PWM_deal(0x38);
delay(60);
PWM_deal(0x2E);
delay(60);
PWM_deal(0x24);
delay(60);
}
return 0;
}
void PWM_deal(unsigned char reg0)
{
//PWM0 舵机
//PWM 频率
PWM_IP_mWriteSlaveReg1(XPAR_PWM_IP_0_BASEADDR,0,0x1F4);
//PWM 占空比
PWM_IP_mWriteSlaveReg0(XPAR_PWM_IP_0_BASEADDR,0,reg0);
//PWM1 直流电机
PWM_IP_mWriteSlaveReg1(XPAR_PWM_IP_1_BASEADDR,0,0x1F4); //
PWM_IP_mWriteSlaveReg0(XPAR_PWM_IP_1_BASEADDR,0,reg0); //slv_reg0
}
智能小车 Spartan-6 FPGA 电源稳压芯片 全桥驱动 相关文章:
- 十个中文例程教会你轻松上手制作Arduino智能小车(06-04)
- 智能小车循迹记时测速程序(12-02)
- 智能小车的PWM键盘控制电机程序(12-02)
- XS128单片机程序:智能小车舵机的控制(12-01)
- 基于51单片机的遥控智能小车实作心得(12-01)
- 基于51单片机的智能小车(遥控模块寻迹避障)(11-29)