Go Down

Topic: RE: Low Pass Filter (Read 7313 times) previous topic - next topic

ilovetoflyfpv

Hi Gang

Well I've downloaded the ATtiny datasheet. I imagine an Electronics Engineer wrote it for Electronics Engineers. For us mere mortals where on earth do you start? There is no index. The word register appears 658 times. There are no examples. As I stated earlier, registers make me break out in a cold sweat.

Cheers

Jase :)

septillion

There is no index.
There is, in two places. First is at the back of the datasheet page 227). Second and easiest is the digital version in the PDF. If you open in in Acrobat Reader it's in the bookmark pane. In the reader from Firefox click the icon in the top left (shows page previews) and then the headings icon.

And yes, it's written for engineers and yes it takes some time to fully understand it. But there are lots of write ups on the internet to help you. For example this from Max Embedded. Although not for an ATtiny, the priciple is the same. You only need to find the right register names for the timer.

The word register appears 658 times.
Of course! Every damn thing in a micro is controlled by a register! Even a ATtiny is already a pretty complex device. That makes them powerful BUT complex.

There are no examples.
There are plenty but most are for assembly, not a higher level language like C/C++. But in AVR writing a register is as simple as
REGISTER_NAME = value

And in a register you can also use the bit names to set or clear them
REGISTER_NAME = 1 << BIT_NAME || 1 << BIT_NAME2
Or in short (aka the same)
REGISTER_NAME = _bv(BIT_NAME) || _bv(BIT_NAME2)

Or if you only want to set specific bits (and leave the rest)
REGISTER_NAME |= _bv(BIT_NAME) || _bv(BIT_NAME2)

Or clear specific bits
REGISTER_NAME &= ~(_bv(BIT_NAME) || _bv(BIT_NAME2))

But that is just bitwise operations and isn't specific for setting registers.

For example, to set PWM freqency of the ATmega328p to +-31kHz on pin 3 and 11
Code: [Select]
//Set PWM of timer2 (pin 3 & 11) to +-31kHz
  TCCR2B = (TCCR2B & 0b11111000) | 0x01;

(TCCR2B & 0b11111000) clears the first 3 bits of the TCCR2B (Timer/Counter Control, timer 2, register B) which are the CS (Set Clock) bits (see page 156 in the ATmega328p datasheet).
and | 0x01 sets the lower bit again. Which makes CS set to 0b001 which is clock without prescaling for timer 2.

Only thing on a ATtiny, I don't know which timer is used for millis() (and general timing) on the ATtiny. The PWM outputs are on timer0 so if it uses timer0 for millis() as well that means that messing with the speed of timer0 also changes the timing of millis() which is annoying...

As I stated earlier, registers make me break out in a cold sweat.
No need to. In contradiction to cracks/cheat codes the value of a register IS completely explained. Every bit is accounted for.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Go Up