ADC INPUT - DAC OUTPUT how can I smooth out the 32 steps.

JPU

Senior Member
Hi All

I have set up a 14m2 to drive a brushless motor controller. The 14m2 is connected to a foot pedal (variable resistor (10K)). I have set the 14m2 to read the ADC in via a voltage divider. The voltage divider is 10K resistor and then the 10K foot pedal. When connected to the pedal the the ADC range is roughly 520 - 1023. I then convert this value via the code and output using the DAClevel command. Pin13 is the only free pin I have. (I think that using pwmout would be an easy solution here but unfortunately, the circuit is already setup and pin 13 it has to be.)

The setup works ok and the foot pedal works a treat. However, the brushless motor doesn't work as perfectly as I would like. ie depression on the pedal is split into 32 steps so you can clearly here it step up and step down through the speeds.

Please, can someone tell me or suggest a way that I could make the steps smoother so that the foot pedal movement relates directly to the speed of the motor rather than the 32 to steps.

Thanks for your help and I hope I have explained this well?

Thanks, JPU
 

RNovember

Well-known member
Please, can someone tell me or suggest a way that I could make the steps smoother so that the foot pedal movement relates directly to the speed of the motor rather than the 32 to steps.
I have the same question. Help wanted!
 

hippy

Technical Support
Staff member
You could potentially 'dither' the outputs with an appropriate RC filter; continually switch between two levels to achieve a third. For example 4 and 5 should give 4.5, 5 and 6 should give 5.5. That will increase 32 levels to 63 levels.
 

Dartmoor

Member
My tuppence worth:
What if you were to "bitbang" PWM on pin 13?
You could then go to some intermediate speed(s) if the ADC input increases or decreases?
It would probably mean limiting the acceleration/deceleration to keep them constant.
Haven't thought too much about the code yet but it is something I am interested in.

Alternatively, a capacitor across the motor coil or even a flywheel on the motor shaft may help?
To be honest, the motor speed is probably smoother in reality than the sound you hear (especially if it has a load)?
 

nekomatic

Member
Since you're using an M2 part, you might be able to use the parallel task processing feature for this? Run your existing code in one task and have a second task dedicated to generating the 'PWM' on pin 13 using pulsout.

I haven't played around with this feature myself so I don't know how well it would work - you may be using commands or functions that aren't compatible with it.

Alternatively, use serout on pin 13 to send a byte value to an 08M2 which reads it and generates a corresponding PWM output on another pin.
 

hippy

Technical Support
Staff member
Since you're using an M2 part, you might be able to use the parallel task processing feature for this? Run your existing code in one task and have a second task dedicated to generating the 'PWM' on pin 13 using pulsout.

I haven't played around with this feature myself so I don't know how well it would work - you may be using commands or functions that aren't compatible with it.
That could be a problem. The way multi-tasking works is it executes one command from one task, then executes one from another. That means how quickly any task is running, or how frequently a particular command is reached, depends on what is being done in other tasks.

An alternative is to use interrupts but there is no support for hardware interrupts on the M2 and they aren't instant and don't have a fixed latency on an X2 so there would still be some jitter in timing.

One solution would be to free-up a PWMOUT pin, even if it means having to add jumper wires to the circuit board to route signals differently.

Another solution may be to use an 08M2 or other PICAXE which can deliver the PWMOUT which can have its speed set via a serial value sent out from the pin you do have - which should be easy given the pin you have is SERTXD / SEROUT and HSEROUT capable.
 

JPU

Senior Member
One solution would be to free-up a PWMOUT pin, even if it means having to add jumper wires to the circuit board to route signals differently.
Thanks everyone, Yes I think Hippys idea would be easiest for me to put into practice.

I thought it was worth a post just in case there was a magic solution but it looks like not in this case.

Thanks again for your help.
 

erco

Senior Member
If you have the physical space to swap in a 20M2, you'll have plenty more pins & more options available. When I fab an 08M2 or 14M2 PCB I usually leave space on the bottom end of the Picaxe socket, just in case I need the next bigger chip. That said, this skinflint knows it IS satisfying to use every single pin on a Picaxe.
 
Top