Using a variable resistor to control PWM mark/space ratio.

Videostar

New Member
Hi

I'm new to PICAXE but I would like to use one for a project to control 1, 2 or 4 high power motors (up to 20Amps each at 24V). I originally intended to use a PIC16C71 because a) I have some and b) I have the basic circuit and software, as published in PIC Cookbook Vol 1.

Having "roughed out" the circuit, I started to look through my supplier websites to find FETs that will handle the power. During my search on the Rapid Electronics site (in UK) I found the PICAXE-18 project PCBs, both standard and high power versions and all they require is a PICAXE 18M2 and the relevant software to make them work. These PCBs will save me the trouble of designing my own, not to mention the extra cost of making them.

Now to my problem - I have looked at the manuals for these and the 18M2 and can see roughly how to read the 10k variable resistor (I think) and I suspect I know how to vary the PWM out - BUT - I cannot get my head around how to control the PWM mark/space output ratio with the variable resistor. Can anyone help with the software ?
 

Technical

Technical Support
Staff member
...to control 1, 2 or 4 high power motors (up to 20Amps each at 24V)....These PCBs will save me the trouble of designing my own, not to mention the extra cost of making them....
Welcome to the forum. Unfortunately the PCBs mentioned will be smelling bad as they melt at 4 x 24V, 20A !
 

geoff07

Senior Member
Assuming you fix the hardware problem:

- to set the PWM m/s ratio you need a number scaled according to the PWM settings you plan to use.
- a potentiometer could provide you with a variable dc voltage, which can be read by an ADC and thus create a number 0-255 or 0-1023
- scale the ADC output into the number range you need for the PWM statement, and apply
- keep rereading the ADC and adjusting the PWM, and the pot will control the speed
- the scaling does not have to be linear

You could use a Picaxe board to provide the drive signals to a much more chunky mosfet array, probably with a mosfet driver chip in between to ensure the necessary gate voltages are provided
 

Goeytex

Senior Member
As Technical indicated, the boards you referred to cannot handle that kind of power. You will need something with more efficient MOSFETS and Mosfet drivers unless you want to generate a lot of heat that must be dissipated with large heats sinks.

I can help you with the code. The code below is an example of how to do it using 8-bit ADC and a Pwm Frequency of 1000 hz. The math will change if you need to change the frequency. This is for one channel.

Code:
#Picaxe 18m2
#No_Data       '// Do not write to or erase the EEPROM memory  

'// Pin Constants
symbol ADC_PIN = B.1   '// Center of pot connects Pin B.1
Symbol PWM_PIN = B.6   '// PWMOUT on Pin B.6

'// Variables
symbol ADC_value =  B0     '// 0 -  255 
symbol duty_cycle = W1     '// 0 - 1000

'// Initialize PWM
pwmout pwm_pin, 127, duty_cycle   '// Start pwm at 1000 hz with a duty cycle of zero     

MAIN: 


   DO 

       readadc ADC_Pin, ADC_value            '// Read the Pot  (0 - 255)
       duty_cycle = ADC_value * 200 / 51     '// Do the math to map the value for 0 - 100 percent duty
       pwmduty pwm_pin,duty_cycle            '// Change the duty cycle according to pot position 
       pause 100                             '// Short Delay        
   
  Loop
 
Last edited:

Videostar

New Member
Many thanks for the code, Goeytex. That was the part I was struggling with. I am aware that the PCBs will not handle the current I need and I have attached a rough circuit of the motor control FETs. I know it looks odd but I need to use an existing remote control (circuit attached although I don't intend to use the "cutout" LED) and this was the easiest way of doing it considering I was already struggling with the code to vary the PWM. Having said all that, perhaps I ought to use the PICAXE to do the Forward/Reverse switching to ensure that the user of the remote control doesn't try to switch direction at full power and destroy the FETs or the motor.
img172.jpg
 
Last edited:
Top