Setting PWM frequency with Arduino Yun

Hello Forum,
I am translating a Uno script into one that will work on a Yun.
On the Uno, I can change various pin parameters like this:

// Set pins as outputs
DDRD = DDRD | B11111100;  // this is safer as it sets pins 2 to 7 as outputs
DDRB = DDRB | B00111111;  // this is safer as it sets pins 8 to 13 as outputs
  
  // Pins 5 and 6  Default is 0x03 = 976.6 Hz
  TCCR0B = TCCR0B & 0b111111000 | 0x03;    // Try 0x01 for 62500 Hz; 0x02 = 7812.5 Hz or 0x03 for 976.6 Hz
  
  // Pins 9 and 10  default is 0x03 = 488 Hz
  TCCR2B = TCCR2B & 0b111111000 | 0x03;  // Try 0x01 for 31250 Hz; 0x02 = 3906.3 Hz or Ox03 for 488.28 Hz

The command starting TCCR2B does not compile and gives me the following...
Arduino: 1.5.4 (Mac OS X), Board: "Arduino Yún"

YUN_Igor_Sockit2.ino: In function 'void setup()':
YUN_Igor_Sockit2:49: error: 'TCCR2B' was not declared in this scope

This code compiles for the Uno. I suppose that I have to make this command via the Bridge with the Yun so can anyone tell me how I can do this?

Thanks,
Nick

Hi Nick,

TCCR2B is a register specific for the Atmega328, the Yùn (as like the Leonardo) mounts an Atmega32u4 that doesn't have this register. You should look for the equivalent in the 32u4's datasheet or find some code example that works on the 32u4.

Thank you cmaglie,
I had a look in the datasheet for the 32U4 as you suggested. It does not have TCCR2B.

It does have TCCR0B, TCCR1B and TCCR3B so if I change the 2B to 3B, the code compiles. I guess I now have to check which of the pin pairs each of these registers controls.

BW
Nick

NickH:
It does have TCCR0B, TCCR1B and TCCR3B so if I change the 2B to 3B, the code compiles. I guess I now have to check which of the pin pairs each of these registers controls.

Exactly, probably someone else already did this for the Leonardo, maybe a search on the forum its worth a try.