Pages: [1]   Go Down
Author Topic: Atmega1280 Fast 10-bit PWM  (Read 1102 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup() {
 
  pinMode(45, OUTPUT); // Or DDRL |= _BV(PL4);
  TCCR5A = _BV(COM5B1) | _BV(WGM51) | _BV(WGM50);
  TCCR5B = _BV(WGM52) | _BV(CS50);
  OCR5B = 512;
}

void loop() { }

This isn't doing what I think the datasheet says it should be doing.. Did I forget some registers or something? Should be no prescaling with 10 bit fast pwm and pin 45 on the arduino mega set to set on bottom and clear on match..

AFAIK timer 5 port b is on pin 45 on the arduino mega.. If I set the ocr5b to 1023 the led lights up a little bit, but not much -- at all other values it's barely visible.

Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11650
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That seems reasonable, had a look at the datasheet - I've not used that exact mode, I've used mode 1010 (phase-correct, programmed by ICR) before (with 16 bit timer1 on ordinary Arduino.

Does sound rather like its still in 16 bit mode rather than 10...

[edit:  why not read the various counter control registers back and print them out to double check they have the values you hope?  Perhaps one of the #defines is wrong?]
« Last Edit: March 16, 2012, 02:43:37 pm by MarkT » Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Checked that (TCCR5A+B) already and they look ok.

Btw, the voltage seems to be around .62 when not "max" which is around 1.2 or something.

Do you have any code for pwm on atmega1280 that is known to work? I tried a couple of different settings with little luck..

On a side note, analogWrite works.
« Last Edit: March 16, 2012, 02:53:16 pm by remiss » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Uh, never mind, the pin is broken on the board ("made in china") for some reason.. Can't even remember using it before..

Anyway, substituing 5 with 3 solved the problem.. Thanks Mark smiley
Logged

Pages: [1]   Go Up
Jump to: