Yahoo Groups archive

AVR-Chat

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

Thread

Compare Output Mode problem

Compare Output Mode problem

2005-03-23 by rlrsmith

Having a problem with the Compare Output functions in Timer1 on an 
ATMega32.
Have simulated the code under AVRStudio with various combinations of 
the top 4 bits of the TCCR1A register - the code only appears to 
affect the PIND register rather than the PORTD register.  I can't 
spot the deliberate mistake - can anyone else help?

Thanks,

Richard Smith
rlrsmith@yahoo.co.uk

Code listing below:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

INTERRUPT(SIG_OUTPUT_COMPARE1A)
{
}

INTERRUPT(SIG_OUTPUT_COMPARE1B)
{
}

int main(void)
{
	DDRD=0xFF;
	PORTD = 0xFF;
	
	//Reset counter
	TCNT1 = 0;

	//Initiate timers
	TCCR1A = 0b10101100;	//See pg.105
	TCCR1B = 0b00000000;	//See pg.105

	//Clear output compare interrupt flags
	TIFR = (_BV(OCF1A)|_BV(OCF1B));	//See pg. 111
	
	//Enable output compare interrupts
	TIMSK = (_BV(OCIE1A)|_BV(OCIE1B));	//See pg. 110
	
	OCR1A = 0x00FF;
	OCR1B = 0x000F;
	
	// Start timer
	TCCR1B |= 0b00000010;
	
	sei();
	for(;;);
}

Re: Compare Output Mode problem

2005-03-24 by paul_hvidston

Richard,

I have not programmed a 'mega32, but have used the 16 bit timer on the
tiny2313. It appears that you are incorrectly programming the timer as
an 8 bit timer. Timer1 is 16 bits. This may be your problem (or I may
be way off base).

Best regards,

Paul H.

--- In AVR-Chat@yahoogroups.com, "rlrsmith" <rlrsmith@y...> wrote:
Show quoted textHide quoted text
> 
> Having a problem with the Compare Output functions in Timer1 on an 
> ATMega32.
> Have simulated the code under AVRStudio with various combinations of 
> the top 4 bits of the TCCR1A register - the code only appears to 
> affect the PIND register rather than the PORTD register.  I can't 
> spot the deliberate mistake - can anyone else help?
> 
> Thanks,
> 
> Richard Smith
> rlrsmith@y...
> 
> Code listing below:
> 
> #include <avr/io.h>
> #include <avr/interrupt.h>
> #include <avr/signal.h>
> 
> INTERRUPT(SIG_OUTPUT_COMPARE1A)
> {
> }
> 
> INTERRUPT(SIG_OUTPUT_COMPARE1B)
> {
> }
> 
> int main(void)
> {
> 	DDRD=0xFF;
> 	PORTD = 0xFF;
> 	
> 	//Reset counter
> 	TCNT1 = 0;
> 
> 	//Initiate timers
> 	TCCR1A = 0b10101100;	//See pg.105
> 	TCCR1B = 0b00000000;	//See pg.105
> 
> 	//Clear output compare interrupt flags
> 	TIFR = (_BV(OCF1A)|_BV(OCF1B));	//See pg. 111
> 	
> 	//Enable output compare interrupts
> 	TIMSK = (_BV(OCIE1A)|_BV(OCIE1B));	//See pg. 110
> 	
> 	OCR1A = 0x00FF;
> 	OCR1B = 0x000F;
> 	
> 	// Start timer
> 	TCCR1B |= 0b00000010;
> 	
> 	sei();
> 	for(;;);
> }

Re: Compare Output Mode problem

2005-03-24 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "rlrsmith" <rlrsmith@y...> wrote:
> Having a problem with the Compare Output functions in Timer1 on an 
> ATMega32.

Is it only on the simulator that your're having problems?  I haven't 
used the simulator - just the real thing.

What is it that you're trying to do?  It's not clear from the code.

Also, are you sure that you want to use the INTERRUPT form of ISR.  
Except for very special situations you should be using the SIGNAL 
form.  The AVRLib doc describes the difference.

Don

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.