简体   繁体   English

ATMEGA32保险丝位设置,低保险丝和高保险丝,16MHz,外部晶振?

[英]ATMEGA32 Fuse bit settings, Low Fuse and High Fuse, 16MHz, External crystal?

I am using ATMEGA32 with Crystal 16MHz . 我正在将ATMEGA32与Crystal 16MHz
I have written following code to generate 1kHz wave. 我已经编写了以下代码来生成1kHz波形。

I tried writing Low- 0xFF High-0x99 我尝试写Low- 0xFF High-0x99
But I am unable to get 1kHz wave . 但是我无法得到1kHz wave I am getting 250Hz wave . 我正在收到250Hz wave instead of 1kHz . 而不是1kHz

Please help. 请帮忙。

#define F_CPU 16000000UL 
#include <avr/io.h> //io related 
#include <util/delay.h> //delay
#include "lcd.h" //custom lib for lcd
#include <stdlib.h> //for string handling
#ifndef sbit_h
#define sbit_h
int main(void)
{

    //All Declarations Go here.

   OCR0=p*127/100; //set pwm1 duty cycle
   OCR2=OCR0;      //set pwm2 duty cycle (Output compare register)

   while(1)
   { 
      if ((bit_is_set(PIND, 3 )))
       {
           pinChange(LED8,1); //Turn on solenoid valve
           pinChange(LED1,1);
           //PORTC|=(1<<PC3);
           _delay_ms(sq); //wait for squeeze time
           TCCR0 |= (1<<WGM00)|(1<<COM01)|(1<<WGM01)|(1<<CS01)|(1<<CS00); 
           //initialise timer in PWM mode 1kHz//cs00 and cs02
           _delay_us(500);//90 degree phase shift
           TCCR2 |= (1<<WGM20)|(1<<COM21)|(1<<WGM21)|(1<<CS22); //initialise timer2 in PWM mode 1kHz//CS22 for 1kHz
           _delay_ms(w1); //wait until weld time over
           TCCR0=0x00;  //stop PWM1
           TCCR2=0x00;  //Stop PWM2
           _delay_ms(h); //wait for hold time
           pinChange(LED8,0); //turn off solenoid valve
           pinChange(LED1,0);
           TCNT0=0x00; //Reset timer counter
           TCNT2=0x00; //reset timer counter
     }
}

Did you set clock selection fuse bits (and possibly clock divider) in the correct way? 您是否以正确的方式设置了时钟选择fuse bits (可能还有时钟分频器)? I'd start checking CKSEL0...3 and CKDIV8 . 我将开始检查CKSEL0...3CKDIV8

By my experience, getting an exact multiple of the desired time/frequency is almost always based on a wrong clock setting. 根据我的经验,获得所需time/frequency的精确倍数几乎总是基于错误的时钟设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM