Interputing Code

I have copied some code, and I need to edit it. But I am not sure what small parts of it are doing.

The part in question is "_BV" what is this doing in this code?

Here is the code I am needing to edit.


void setup(){
  pinMode(3, OUTPUT);
  pinMode(11, OUTPUT);
  TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS02);
  OCR2A = 100;
  OCR2B = 50;
}
void loop(){
  pinMode(3, OUTPUT);
}

It is used 6 times in this code, and I am trying make sure it is doing what I think it is.

Maderdash: trying make sure it is doing what I think it is.

But you do not talk about your thoughts? ;)

It converts the a bit-number to a bit-mask, 0 -> 0x1, ... 4 -> 0x10, ... 7 -> 0x80.

Ok i was wrong then. I was thinking it was simply placing a 1 into the value.

my thinking: "_BV(COM2A0)"= placing a 1 into the "COM2A0" place, turning it "ON".

Thank you.

I was thinking it was simply placing a 1 into the value.

That’s pretty much correct. From the AVR documentation for the _BV macro–

#define _BV(bit) \
 (1 << (bit))

The Arduino ide automatically includes header files which contain identifiers for all the register names and bit names on that register for a particular processor.