My favorites | Sign in
Project Home Downloads Wiki Issues
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 307: Refactoring analogWrite() to test for register, not cpu, definitions.
2 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Closed:  Oct 2010

Sign in to add a comment
Project Member Reported by, Jul 28, 2010
What change would like to see?

I have rewritten analogWrite and fixed an omission.


I have been doing a lot of work porting Arduino to other Atmega boards with other cpus. The cpu list includes 2560, 1281, 128, 644 and others. The timer portion of the code is the hardest part to port. There were a lot of cpu specific #ifdefs.  Instead of using cpu #ifdefs, a better way of #ifdef the control port which is properly defined in the appropriate iomxxx.h file. This allows the code to work without having to make any changes when the code is ported to a new CPU.

Additionally while doing this I discovered that timer TIMER5C which controls the PWM on mega pin 44 (Port L bit 5) was omitted and therefore the PWM function on this pin did not work.

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?

No issues at all

I used a switch statement instead of if else 

on the atmega328 it takes 14 more bytes

on the atmega1280 it takes 40 more bytes

the speed should be faster

Aug 3, 2010
Project Member #1
Interesting.  The TIMER1A, etc. constants are currently all defined on all the boards (in pins_arduino.h): is it necessary to test for them?  Other than that, it looks reasonable.
Summary: Refactoring analogWrite() to test for register, not cpu, definitions.
Status: Accepted
Labels: Component-Core
Aug 3, 2010
Project Member #2
You are correct, the constants such as TIMER1A are not needed. I will change it and upload a new version

Aug 3, 2010
Project Member #3
I have a new version of wiring_analog.c with the changes suggested by David. This should work on any cpu without changes

6.5 KB   View   Download
Oct 17, 2010
Project Member #4
Status: Fixed
Labels: Milestone-0022
Sign in to add a comment

Powered by Google Project Hosting