Hi all!
First I would like to take the time to say thanks to the folks who have spent long hours making Arduino possible. I could not imagine how much more time I would spend doing projects if there were no one to do the "grunt" work, which is what I do too coincidently.
That being said I have been working on a project where I free up the restrictions on the PWM libraries that are included in with the Arduino Due, as I have done previously with the Mega 2560 and Uno before it.
My main question has to do with pins AD4 and AD6, which are tied to Timer Counter 1 and 2 from the looks of it. I have tried to configure these pins to be outputs instead, however I have been unable to get the pins configured correctly by changing the values in the variant.cpp file.
Thus far I have changed all of the PWML0-7 channels to function independently with variable frequency and PWM, as well as pins 2,3,4 and 11 to give four extra 8 bit PWM channels with variable frequency (can only do 1 for each TC ch, since A and B will share frequency… although some would not mind my requirements need each channel to function independently).
So my main questions are at this point, where are the other 2 timers or are they used at all on the Due? And, what changes would I have to make to the variant file to use TC ch 1 and 2 as PWM outputs instead of analog inputs. I have tried replacing all of the obvious code to match the other TC channels, but I suspect that the issue is with the PIO_PA6X1_AD3 parameter as I have tried changing the rest of them with no luck. Also, I have not combed all of the PWMH channels, but off hand were any tied to I/O ports on the Due?
I suspect I will be able to figure it out in time, but I was hoping to have the answer handed to me to be honest… because I have spent a lot of time digging and making modifications to get the functionality that I wanted out of the Due.
I would also like to submit a library that can be used specifically for PWM. As I mentioned before I have wrote code to directly control the hardware timers on the Mega 2560 and Uno previously. Is this something that people would even want? There are limitations of course, more so on the older boards than the Due… but would it be worth my time adding my code to a library for others to use? Or would I be wasting my time?
Code reference to my questions are below and thank you in advance.
P.S. I would not mind writing the code for all Arduino Boards as I update it, however I cannot really afford to purchase each one as I would not have much use for many other boards, the Due has been the closest to what I have been after so far. Once I get the first 3 (Mega 2560, Uno, and Due) up and running do you think there would be a chance that I could get samples one at a time as I have time to add to the library? Then again, this is only applicable if the community would like to have a more robust PWM library. Otherwise it would only work for the 3 I mentioned, which is still better than nothing.
// 58
{ PIOA, PIO_PA6X1_AD3, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC4, ADC3, NOT_ON_PWM, TC0_CHB2 }, // AD4
{ PIOA, PIO_PA4X1_AD2, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC5, ADC2, NOT_ON_PWM, NOT_ON_TIMER }, // AD5
{ PIOA, PIO_PA3X1_AD1, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC6, ADC1, NOT_ON_PWM, TC0_CHB1 }, // AD6
{ PIOA, PIO_PA2X1_AD0, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC7, ADC0, NOT_ON_PWM, TC0_CHA1 }, // AD7
i.e. Timer Counter channel:
// 13 - AMBER LED
{ PIOB, PIO_PB27B_TIOB0, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC0_CHB0 }, // TIOB0