Go Down

Topic: PWM Frequency Library - Still will not compile for ATmega1284  (Read 738 times) previous topic - next topic


JacksonAudio

line 39 of PWM.h change to:


#include "src/ATimerDefs.h"

6v6gt

This is a summary of the main findings and more or less what I did.

1. The original library uses a recursive include structure.
2. The IDE is not really compatible with putting sub folders in the sketch folder (which is the standard way of testing unmanaged libraries before adding these to the main library folder)
3. I tried to avoid changes which may have caused existing code to break.
4. The IDE has gone through a few changes since the original code was written and these changes don't appear to work with all cores. Here, for example https://github.com/arduino/arduino-builder/pull/148 regarding recursive includes.


This is roughly what I did.
1. changed included dir to src.
2. eliminated recursive #includes but introduced some duplication
3. Added 1284 support. The library supports 2 basic AVR groups with similar timer configuration
groupA 2x8bit, 4x16bit and groupB 2x8bit and 1x16bit. The 1284/1284p has 2x8bit and 2x16bit so it did not exactly fit in but I treated it as groupB AVR which means 1 16 bit timer is ignored. The groups are simply defined by the core board definition e.g. __AVR_ATmega88P__
5. The library uses some direct memory addressing of timer registers instead of using the defined mnemonics. This is somewhat error prone, but I checked the datasheets of the groupB MCUs against the 1284 and these addresses appear to correspond for the timers used. However, this requires careful testing with the 1284 to ensure that there are no surprises.
 

You are right that I made an error in PWM.h which would have affected the groupA boards. It happened after a late phase of restructuring after my main tests. Well spotted. For completeness, I am including the updated software.

Anyway, if you have any problems let me know and I'll see what I can do.

Personally, if I want to do something like altering the PWM frequency (or duty cycle, PWM mode etc.), I would simply refer to the data sheet for the timer registers of the specific MCU and code accordingly, but I see the advantages of such a library for those who don't want to go down to that depth and @RunnerUp has done a great job here. Of course now the Arduino platform is supporting many different varieties of architectures including even new AVR architectures so making and maintaining a completely universal library would be quite an ambitious undertaking.
 

Go Up