【原创】XPS pwm ip core 用法简介

没废话,真接贴代码:(如需转载,请注明出处)

#include "stdio.h"
#include "xparameters.h"
#include "xbasic_types.h"

#define PWM1_addr  XPAR_PWM_BASEADDR //添加的ip core名字为pwm

void PWM_x(unsigned long BaseAddr, double period, double Duty)

 //==============定义相关寄存器的地址=============================
 #define TCSR0 (*(volatile unsigned long *)(BaseAddr+0x00))
 #define TLR0 (*(volatile unsigned long *)(BaseAddr+0x04))
 #define TCR0 (*(volatile unsigned long *)(BaseAddr+0x08))
 #define TCSR1 (*(volatile unsigned long *)(BaseAddr+0x10))
 #define TLR1 (*(volatile unsigned long *)(BaseAddr+0x14))
 #define TCR1 (*(volatile unsigned long *)(BaseAddr+0x18))
 //===========================================================
 double clk = 50000000;  
 double clk_width = 1/clk;
 //=====一个周期时间、高电平持续时间================================
 unsigned long PWM_period = period/clk_width;
 unsigned long PWM_high = Duty * PWM_period; 
 //====装载Load Register=======================================
 TLR0 = PWM_period;
 TLR1 = PWM_high;
 //====装载Control/Status Register=============================
 TCSR0=0x606;
 TCSR1=0x606;
}

 
 //====================main===================================
 int main()
 {
  //unsigned long BaseAddr, double period, double Duty
  //period is in seconds, and duty cycle is in decimal,
  //not percentage
  PWM_x(PWM1_addr, 0.01, 0.5);
 }

 相关资料文档可以在xps软件下system assembly view下双击自己添加的pwm ip core查看其datasheet.

因为还不会将pdf文档传上来,所以,直接到按上述方法查看其资料。

转载于:https://www.cnblogs.com/hclmcu/archive/2010/09/02/1816247.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值