PWM Frequency Library - Still will not compile for ATmega1284

After giving up on this about a year and a half ago I came back to it tonight and I still can't get the PWM.h library to compile for this chip.

Every other chip option I have will compile just fine but not this one.

Can anyone help? I'd hate to have to upgrade to the MEGA just so I can get this code to compile. I'd be happy to PayPal $100 to the first person who can give a solution.

Thanks!

Here are the errors that are being thrown out when it tries to compile

error: 'SetPinFrequency' was not declared in this scope
error: 'pwmWriteHR' was not declared in this scope

I should also mention that I using the MightyCore board definitions.

email me at brad@jacksonaudio.net if you're interested in helping.

Which arduino pwm library are you using ?
Github is littered with all varieties of these.
Since these will directly manipulate hardware registers, these will be dependent on the specific MCU.

Thanks for writing back! 6V6! (you must love amps like I do :slight_smile:

This is the library: Google Code Archive - Long-term storage for Google Code Project Hosting.

I would also be happy if this worked with the MiniCore 328 board.

Well, this was the first one I ever built:

The output valve is a 6V6GT although the only vacuum tube stuff I've done recently is a Nixie clock.

I guess I could fix the library so it accepts the 1284 and compiles, but can't test it on a physical board. Are you prepared to do the testing to check out the functionality ?
Is the 1284 the only board you've tried the example code on with the "MightyCore" ?

I've already had to make a fix it so it compiles with a recent IDE with the standard core. It looks like that could be a similar problem as that with the "miniCore". That I'll test myself.

I just got the MiniCore 328 to work at 20MHz! So that’s HUGE progress!

At least now I can run that at 20MHz!

OK. I got it to compile with the minicore using a 328 board.

You should be able to unpack the zip and compile the example .ino it within the folder because the modified library parts are in the sketch folder and it will take those in preference to those parts in the standard library location.

The original library is not compatible with modern IDEs

[this crossed with your post. Let me know how you want to carry on]

pwmLib_V0_01.zip (11.6 KB)

trying it now!

I got it to work just fine with the MiniCore 328.

Think we can get the 1284 working?

I'll make the changes now and send it for your testing.
If you try the code I sent you with a 1284 you should now get a decent error message.

I restructured it to compile with all 3 cores I tried it with (standard, mini and mighty) and the 1284 and 1284P just with the mighty core.
The functionality testing I have to leave to you.
Let me know how you get on.

pwmLib_V0_04.zip (12 KB)

6v6gt:
I restructured it to compile with all 3 cores I tried it with (standard, mini and mighty) and the 1284 and 1284P just with the mighty core.
The functionality testing I have to leave to you.
Let me know how you get on.

You are BRILLIANT!!! What did you change?

I've been messing with it and it just plain works. :slight_smile:

Very nice work!

I’m pleased that all worked OK. I’ll make a list of the changes and send them tomorrow because it is now late here.

Sounds good!

line 39 of PWM.h change to:

#include "src/ATimerDefs.h"

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 Limit recursive sketch compilation to the `src` directory by matthijskooijman · Pull Request #148 · arduino/arduino-builder · GitHub 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
  4. 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.

pwmLib_V0_05.zip (12 KB)