Turning Analog pins to digital pins on a leonardo

Hello
I have a sketch that controls a DC motor with quadrature encoder driven by an analog potentiometer on a Leonardo.
The sketch uses:

#define PWMPIN 10 // Output pin to control PWM for motor controller on digital 
#define DIRPIN 9 // Output direction for motor controller on digital 
#define CHANNELA 3 // motor position sensor pin Digital Pin
#define CHANNELB 2 // motor position sensor pin Digital Pin
#define POTPIN A0 // select the input pin for the potentiometer on analog pin

My goal is to adapt the above sketch for a proprietary system (see picture below) that only has the five analog pins. I am looking for a way to "map" the above outputs to the ananlog pin config listed below.

#define PWMPIN A0 // Output pin to control PWM for motor controller
#define DIRPIN A1 // Output direction for motor controller
#define CHANNELA A2 // position sensor pin
#define CHANNELB A3 // position sensor pin
#define POTPIN A4    // select the input pin for the potentiometer

On top of this, the PWM has to work at least 30Khz to avoid motor "squeal", that is handled by the pwm.h library.

The digital pins have been specifically chosen for their performance on the Leonardo as shown in the pin schematic attached below. The Leonardo and the proprietary card use the ATMEGA32U4 16-bit microcontroller.

Any thoughts or examples are most welcome.
Thank you

All analog pins can be used as digital ones as well (they're better thought of as digital pins with the extra function of being able to read analog voltages, just like how some pins can do pwm). Arduino's nomenclature here does not promote understanding of the hardware here.

Unfortunately, none of those analog pins have support for hardware pwm and software pwm is problematic at 30 kHz because of how many interrupts are firing....

Are any of the PWM-capable pins unused (even if not broken out) on that board? If so, you could solder a flying lead to the pin in question (tack it in place with hot-glue afterwards, otherwise it will break off very easily)

Hello DrAzzy
So if I correctly understand, apart from PWMPIN 10, the other pins can be mapped directly without any change in performance?

Putting the frequency issue aside, what soft pwm library would you suggest? I have seen softpwm but I am wondering if there might be another one that is more adapted to my needs?

From the picture attached of the board, would you consider your glue option to be realistic? I have never seen a hot glue gun that accurate.

Many thanks for your thoughts

chlowden:
Hello DrAzzy
So if I correctly understand, apart from PWMPIN 10, the other pins can be mapped directly without any change in performance?

Putting the frequency issue aside, what soft pwm library would you suggest? I have seen softpwm but I am wondering if there might be another one that is more adapted to my needs?

From the picture attached of the board, would you consider your glue option to be realistic? I have never seen a hot glue gun that accurate.

Many thanks for your thoughts

No experience to base it on - I design my devices such that stuff that needs to be PWMed is connected to pins with hardware output compare support. In any event, minimalism is desirable, since you're asking to really push the limits on frequency. Personally, I'd likely implement it myself.

Re second part, You're clearly misunderstanding something - I mean like this, solder - but then glue the flying lead down, because otherwise it will break very easily.

And yes, I just soldered that lead and took that picture for this post; the USBAsp in question is dead.

Ok. I have got out me magnifying glass and a very fine soldering iron point.
Thank you for the picture. It has inspired me.