gpt4 book ai didi

c - 如何在 Atmega32u4 微 Controller 上为定时器/计数器 4 获取 64Mhz 时钟?

转载 作者:太空宇宙 更新时间:2023-11-04 02:25:57 26 4
gpt4 key购买 nike

所以目前我需要一个由定时器/计数器 4 生成的频率为 64Mhz 的 PWM。我当前的频率是系统时钟的 16Mhz,我需要以某种方式将其乘以 4。数据表声称使用 PLL 时钟可以降低到该频率,但似乎弄乱 PLL 寄存器会干扰 USB 通信。如果有人知道如何解决或规避问题,我附上了我的代码。

int D4 = 9;

//PWM Waveforms
byte arr1[] = {0x0C, 0x0C, 0x0F, 0x0F, 0x0C, 0x0C, 0x08, 0x08, 0x08, 0x08,
0x04, 0x04, 0x0, 0x0, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08};
byte arr2[] = {0x00,0x8,0xF,0x8};

int i = 0;
int b = 0;
int g = 0;

void setup() {
// put your setup code here, to run once:
noInterrupts (); // no interrrupts during setup

//PLL Clock registers (Disabled so code will upload)
// PLLCSR = (1<<PLLE);
// PLLFRQ = (1<<PLLTM1)|(0<<PLLTM0);

//Timer/Counter1 used to controll PWM update
TCCR1A = (1<<WGM11)|(1<<WGM10);
TCCR1B = (1<<WGM13)|(1<<WGM12)|(0<<CS12)|(0<<CS11)|(1<<CS10);
OCR1A = 0xA0;

TIMSK1 = (1<<TOIE1);

//Timer/Counter4 used to generate PWM
DDRC = (1<<DDC7)|(1<<DDC6);
TCCR4A = (0<<COM4A1)|(1<<COM4A0)|(1<<PWM4A);
TCCR4B = (1<<PSR4);
TCCR4B = (0<<DTPS41)|(0<<DTPS40)|(0<<CS43)|(0<<CS42)|(0<<CS41)|(1<<CS40);
TCCR4D = (0<<WGM41)|(0<<WGM40);
pinMode(D4, OUTPUT);

interrupts (); // enable global interrupts
//Setting 4 bit resolution
OCR4C = 0xF;
}

ISR (TIMER1_OVF_vect) // Updating PWM on timer4 using timer1 interrupt
{
if (b == 8){
OCR4A= 0x08;
if (g == 400){
b = 0;
g = 0;
}
else{
++g;
}
}
else{
OCR4A= arr1[i];
if (i < (sizeof(arr1)-1)){
i++;
}
else{
i = 0;
++b;
}
}
}

void loop() {
// put your main code here, to run repeatedly:

}

最佳答案

So currently I need to have a PWM generated from timer/counter4 with a frequency of 64Mhz.

这不会发生。定时器/计数器的最大时钟为 64 MHz;这将导致最大输出频率为 32 MHz。

也就是说,您需要的寄存器值是:

PLLFRQ = _BV(PLLUSB) | _BV(PLLTM1) | _BV(PDIV3) | _BV(PDIV1);
PLLCSR = _BV(PINDIV) | _BV(PLLE);

这组:

  • PLL 输入定标器为 ÷2(使输入频率为 8 MHz,这是必需的)
  • PLL 输出频率高达 96 MHz
  • PLL USB 除数为 ÷2(使 USB 频率为 48 MHz,这是必需的)
  • PLL 计时器除数为 ÷1.5(使计时器频率为 64 MHz)

关于c - 如何在 Atmega32u4 微 Controller 上为定时器/计数器 4 获取 64Mhz 时钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51195291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com