|
楼主 |
发表于 2012-5-11 08:12:56
|
显示全部楼层
另附上pwm的ICC测试程序:
//ICC-AVR application builder : 2012-5-9
// Target : M164P
// Crystal: 30.000Mhz
#include <iom164pv.h>
#include <iolgt8f0xa.h>
#include <macros.h>
#define uint unsigned int
void port_init(void)
{
PORTA = 0xff;
DDRA = 0xff;
PORTB = 0x00;
DDRB = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRD =0x30; //PD4、PD5设置为输出
TCCR1A = 0xa3; //快速10位pwm
TCCR1B = 0x09; //1分频
}
void init_devices(void)
{
port_init();
PMCR =0x35; //置位,使能外部晶振
delay_nms(10); //延时10ms等待晶振输入稳定
PMCR=0x34; //关闭内部RC
//PMCR &=~BIT(0);
CLKPR =0x81; //置位MASK_CLKPCE,4个周期内修改分频系数
CLKPR=0x80; //1分频,默认是2分频(0x01)
CLKPR =0x00; //清除 MASK_CLKPCE
}
void delay_1ms(void) //1ms延时函数
{
uint i;
for (i=0;i<2280;i++);
}
void delay_nms(uint n) //N ms延时函数
{
uint i=0;
for (i=0;i<n;i++)
delay_1ms();
}
void main(void)
{
init_devices();
OCR1A = 100;
}
经实测,在外置30M晶振的情况下,pwm1a实际输出频率只有20KHZ左右,而且极不稳定,数值变化很大,不知是何原因。
这里是ICC工程文件: |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|