Eralt / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Refactoring analogWrite() to test for register, not cpu, definitions. #307

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

I have rewritten analogWrite and fixed an omission.

Why?

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

Original issue reported on code.google.com by mark.l.s...@gmail.com on 28 Jul 2010 at 9:54

Attachments:

GoogleCodeExporter commented 9 years ago
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.

Original comment by dmel...@gmail.com on 3 Aug 2010 at 2:05

GoogleCodeExporter commented 9 years ago
You are correct, the constants such as TIMER1A are not needed. I will change it 
and upload a new version

Mark

Original comment by mark.l.s...@gmail.com on 3 Aug 2010 at 2:15

GoogleCodeExporter commented 9 years ago
I have a new version of wiring_analog.c with the changes suggested by David. 
This should work on any cpu without changes

Mark

Original comment by mark.l.s...@gmail.com on 3 Aug 2010 at 5:05

Attachments:

GoogleCodeExporter commented 9 years ago
http://github.com/arduino/Arduino/commit/b0bc52d7d5bd92d35ba78619d9268cd574ffca9
4

Original comment by dmel...@gmail.com on 17 Oct 2010 at 9:59