Question

Im using Ethernut 2.1 B and I need a C program that outputs a clock signal at the timer 1 output B, with other words on output OCIB. The frequency of the clock signal should be at 1.0 kHz.

Anyone know how this could be done?

Was it helpful?

Solution

You need to look in COM bits for your timer. For instance, for Timer0 (8-bit), the COM bits are set in the TCCR0 register. Probably the setting you'd be interested in is

TCCR0 |= (0<<COM1)|1<<COM0); // Toggle OC0 on compare match

This will toggle the OC0 (pin14) line when timer reaches the specified value.

Which timer you use depends on the precision you need: obviosely the 16-bit timers can give you more precise time resolution then the 8-bit timers.

The setting of the registers for your specific frequency (1Khz) depends on the clock speed of your chip, and which timer you are using: the timers use a pre-scaled general clock signal (see table 56 of the datasheet for possible values). This means that the prescaler settings will depend on your clock speed, and how high you want to count. For most precision you will want to count as high as possible, which means the lowest possible prescaler setting compatible with your timer's maximum value.

As far as where to start, generally, reading the datasheet is a good place, but googling "AVR timer" can also be very helpful.

OTHER TIPS

It seems to be based on the Atmel ATmega 128, so read that CPU's data sheet to figure out how to program the timer hardware.

Not sure if this microcontroller supports directly driving an output from a timer, if it doesn't you're going to have to do it in software from the interrupt service routine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top