Hallo

Wir greifen vor, im Moment sind wir doch noch beim Aufruf der ISR.

Die eigentliche Funktion des Timer2 ist die Erzeugung des 36kHz-Trägersignals für die IR-Kommunikation. In der orginalen CD-Lib wurde im CTC-Mode beim Erreichen des OCR2-Wertes der OC2-Ausgang umgeschaltet (togglen) und der Zähler wieder bei 0 gestartet. Bei 72kHz ergibt das 36kHz an OC2-Pin. Die ISR wird aber mit 72kHz angesprungen.

Neuere Libs (mit FastPWM) schalten pro Zähldurchlauf des Timers2 (0x25-0xff) zweimal den OC2-Pin um, aber die ISR wird nur beim Überlauf am Ende mit 36kHz aufgerufen.

Die Änderung des Timer2 auf 36kHz gibt es seit Version 2.3(beta2) in der asuro-Lib (IR-Abstandsmessung von Waste):
Code:
/*******************************************************************************
*
* File Name:   asuro.c
* Project  :   ASURO
*
* Description: This file contains ASURO main features
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------
* 1.00	   14.08.2003   Jan Grewe		 build
* 2.00     14.10.2003   Jan Grewe        LEFT_VEL, RIGHT_VEL -> MotorSpeed(unsigned char left_speed, unsigned char right_speed);
*										 LeftRwd(),LeftFwd(),RightRwd(),RigthFwd() -> MotorDir(unsigned char left_dir, unsigned char right_dir);
*                                        GREEN_ON,GREEN_OFF,RED_ON,RED_OFF -> StatusLED(unsigned char color);
*                                        LED_RED_ON, LED_RED_OFF -> FrontLED(unsigned char color);
*                                        Blink(unsigned char left, unsigned char right) -> BackLED(unsigned char left, unsigned char right);
*                                        Alles in Funktionen gefasst => leichter verständlich ?!?!
* 2.10     17.10.2003   Jan Grewe        new Timer funktion void Sleep(unsigned char time36kHz)  
*
* Copyright (c) 2003 DLR Robotics & Mechatronics
*****************************************************************************/
/****************************************************************************
*
* File Name:   asuro.c
* Project  :   asuro library "Robotrixer Buxtehude"
*
* Description: This file contains additional functions:
*
* signal (SIG_ADC)                 interrupt/signal routine for encoder-counter
* signal (SIG_INTERRUPT1)          signal for switches
* Encoder_Init()                   initializing encoder-counter
* Encoder_Start()                  start autoencoding
* Encoder_Stop()                   stop autoencoding
* Encoder_Set(int,int)             set encodervalue
* Msleep(int delay)                wait for delay in milliseconds
* Gettime()                        get systemtime in milliseconds
* PrintInt(int)
*
* modifications in Sleep, SIG_OUTPUT_COMPARE2, PollSwitch, LineData
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------
* beta1	   31.03.2005   Robotrixer		 asuro library
* -------  ----------   --------------   ------------------------------
* the encoder source is based on RechteckDemo.c ver 2.0 by Jan Grewe 22.10.2003 
* Copyright (c) 2003 DLR Robotics & Mechatronics

*****************************************************************************/
/****************************************************************************
*
* File Name:   asuro.c
* Project  :   asuro library modified for IR collision detector
*
* Description: modifications made in following functions:
*
* SIGNAL (SIG_OUTPUT_COMPARE2)	->	SIGNAL (SIG_OVERFLOW2)
* Gettime()							counts now 36kHz
* Init()							timer2 modified for adjustable duty cycle
* Batterie()						bug fixed
* Sleep()							counts now 36kHz
* Msleep()							counts now 36kHz
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------
* beta2	   11.06.2005   Waste   		 asuro library
* -------  ----------   --------------   ------------------------------
*****************************************************************************/
/***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   any later version.                                                    *
***************************************************************************/

#include "asuro.h"
volatile unsigned char count36kHz;
volatile unsigned long timebase;
volatile int autoencode=FALSE;

/* uses timer2 (36kHz for IR communication */
SIGNAL (SIG_OVERFLOW2)
{
	TCNT2 += 0x25;
	count36kHz ++;
	if (!count36kHz) timebase ++;
}

,,,

/* Init function Processor will be initalized to work correctly */
void Init (void)
{
	//-------- seriell interface programmed in boot routine and already running -------
	//  prepare 36kHz for IR - Communication
	TCCR2 = (1 << WGM20) | (1 << WGM21) | (1 << COM20) | (1 << COM21) | (1 << CS20);
	OCR2  = 0x91; // duty cycle for 36kHz
	TIMSK |= (1 << TOIE2); // 36kHz counter for sleep
....
Gruß

mic