Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Problem with getting signal

2008-02-14 by khahramon0786

Hi All. Look at my source code, i couldn't find my fault there.
I want to get 40Khz, but in VMLAB it shows 29Khz.here is my source code.

/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.8b Professional
Automatic Program Generator
© Copyright 1998-2006 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 13.02.2008
Author  : Khahramon                            
Company : TUIT                           
Comments: 


Chip type           : ATmega16
Program type        : Application
Clock frequency     : 4,000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

#include <mega16.h>
#define xtal 4000000

#define hz 40000


interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// i need 40Khz signal in PORTA.0, that's way i took 80kHz interrupt 
TCNT1=0x10000-(xtal/1/(2*hz));
PORTA.0^=0x01;


}

void main(void)
{

PORTA=0x00;
DDRA=0x01;
TCCR1A=0x00;
TCCR1B=0x01;
// i need 40Khz signal in PORTA.0, that's way i took 80kHz interrupt 
TCNT1=0x10000-(xtal/1/(2*hz));

ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;



// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// Global enable interrupts
#asm("sei")

while (1)
      {
         
      };
}
/***********************************
Can you help me where's my mistake

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.