Change pwm freq. and get a faster analog read

Hey guys! I asked a while ago about using Uncle Ardu to handle BLDC commutation, now the project is in its last steps (here the main topic on EV forum and here on google projects).

Now, I have two issues:

1) the analog read takes way too long. In this quote from the other forum you get an idea of it

no gas reading and no output rewriting: 20 000 ns per loop

gas reading and no output writing: 150 000 ns per loop ===>analo gread is SLOW!

no gas reading but output writing: 60 000 ns per loop

gas reading and output writing: 190 000 ns per loop

target was 40 000 ns per loop to go to 6 000 rpm with a 5% commutation delay

Im perfectly fine with the output writing time but not with the analog read time. It is ok for first testing but too slow to be implemented every 5 loops or so to do real time current control (curr sensor gives analog value). ive been told there is a way to get analog reading way way faster, how to?? 130 000 ns for one analog read is not ok.

2) I need to slow dowm the Ardu`s PWM output to something between 8 and 16 kHz, how to?


PS: the project is open source (Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License), so if you want to join you are welcome!

cheers, Ludovico

) I need to slow dowm the Ardu`s PWM output to something between 8 and 16 kHz, how to?

Do you mean you need to speed up the Arduino PWM to between 8 and 16kHz?

Is it the case that the conversion time for the analogRead is too slow, or is it just the dead time caused by it? If you start an analogue conversion, you can go off, do some computations, then come back to see if the convestion is complete. The code change is quite simple, and means you split "analogRead" into two parts 1) a mux setup and begin conversion 2) a non-blocking poll end-of-conversion

yep! speed up to between 8 and 16 khz. How to? SOmething I can write in the setup part of the code to do so?

I don`t really get the thing about the analog read, I just know that when i add an analog read in the code the loop slows down about 130us per each analog read.... I ve been told i can make it way faster but idk how to