Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

PWM Frequency setting doesn't work on Due

Open polymetric opened this issue 4 years ago • 3 comments

I'm really only using the Due because it's got a lot of interrupt pins. If I can figure out how to use pin interrupts for rotary encoders on the 328p this won't be as big of a deal. Either way it'd still be a nice feature. Currently I can increase it by changing the PWM_RESOLUTION field in variants.h, which works fine.

polymetric avatar Jan 01 '21 04:01 polymetric

We really welcome people trying new chips!!

The due uses a 32bit SAM3X8E chip which has a analogWriteFrequency() method.

The SA3X8E is a type of SAM3XA chip so perhaps targetting #define _SAM3XA_ for chip detection is appropriate.

I can't test (I have no DUE) but I'd try copy/rename the file teensy_mcu.cpp (link below) to samxa_mcu.cpp and then changing the #define to #if defined(_SAM3XA_) logic in new file and in generic_mcu.cpp

https://github.com/simplefoc/Arduino-FOC/blob/master/src/drivers/hardware_specific/teensy_mcu.cpp

Putting it another way I suspect that our hardware specific logic for teensy would work for due - but probably worth breaking them out as they may diverge.

owennewo avatar Jan 02 '21 16:01 owennewo

Hey guys, This is a great issue, but we will need some help here I think. I do not own a due and we will need some volunteers to provide us with some examples of working codes samples. Otherwise it will take some time until we resolve it and it is a shame a bit :D

askuric avatar Jan 25 '21 18:01 askuric

Arduino DUE is supported from this moment. The support is currently in the dev branch and it will pass in the next release. It supports all drivers and all the features except 6PWM mode. If I will have enough time I'll try to squeeze that as well into the next release. Here is the link for current version of the library in dev: https://github.com/simplefoc/Arduino-FOC/tree/dev

The support enables combining the pwm and timer pins at the same time and for now we support only the pwm pins supported with the Arduino implementation. Let us know if you are interested in having fuller support!

askuric avatar Jan 29 '21 22:01 askuric