High Frequency Coil Switching

Sten Martin

New Member
Hi,

I need help and have newer used PICAEXE before. I have questions about the pwmout, toggle and pausus commands.

I have four coils I have to pulse and switch at 7 kHz (period= 143 micro seconds).
Duty cycle 50%.

Each of the four coils must be switched on and off in a certain order as shown below.



Step Coil 1 Coil 2 Coil 3 Coil 4
___________________________________

1 1 0 0 1
2 0 1 1 0
1 1 0 0 1


If we look at the table, we notice that Coil 2 and Coil 3 is always the opposite (or logical NOT) of coil 1 & 4.

Questions
1. Is it possible to cut down the number of micro controller pins required to just two by the use of two additional NOT gates.

2. What command is best suited for the application, pwmout or toggle?

pwmount

(The coils are pulsed with opposite polarities)

Main: pwmout B.7, 142, 286 ‘ PWM output on pin B.7 = coil 1
pwmout B.6, 142, 286 ‘ PWM output on pin B.6 = coil 3


(Use Not gates: to coil 2 & 4 - opposite pulse polarity but from same clock)?


Or

toggle

Main: toggle 1, 4 ‘ Toggle pin 1, 4 = coils 1,4
pauseus 7 ‘ Wait 70 micro sec
toggle 1, 4 ‘ Toggle pin 1,4 = coils 1,4
pause 7 ‘ Wait 70 micro sec
goto Main ‘ Loop

(Use Not gates: to coil 2 & 4 - opposite on/of polarity)?

The driver need to be able to drive 3-4 Amps through the coils.

Note: the stability of the frequency is very critical to function and can not be allowed to drift. The pulse rise time has to be < = to 10 micro seconds.
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

The PICAXE being an interpreter has some command overhead so a TOGGLE, PAUSEUS 7, TOGGLE will not give the desired 70us period signal. You can run the PICAXE at faster operating speeds but it may still be difficult to get such exact timing.

For the application you have it would be worth looking at the HPWM command as that can provide a PWM output simultaneously to four channels with polarity inversion and can provide a deadband between switching coils.
 

Sten Martin

New Member
Thank you for your fast response and suggestions. I have looked at the HPWM command and need some help with using it. Is there any book or code samples I can find to learn about advanced interfacing with HPWM?
What I need is to switch 2 by 2 coils @ 7 kHz as explained above.
 

SAborn

Senior Member
Are you needing to switch the coils through a H bridge (reversing the polarity to the coils) if so you might have some trouble due to the fact most motor/coil driver chips dont go much higher than 5khz.

Step Coil 1 Coil 2 Coil 3 Coil 4
___________________________________

1 1 0 0 1
2 0 1 1 0
1 1 0 0 1
Also why do your code show 5 coils/pins used, and what is the "2" in the code for.
 

Sten Martin

New Member
I have spent some time to investigate different motor drivers and as SAborn is saying they can't handle the high frequency and current.
I don't know if I need H-bridge or not to reverse the magnetic field. I think it is possible to just turn the field on and of. This will make everything much easier and I will try it first. I will consider power MOSFET or IGBT and the more powerfull 28X2 Chip. However I still don't know if I must use HPWM or not and how I can use the command, it seems to be the most complex command. Any help is welcome. The first row in the code above is the step and you can ignore it. It just tell you that coil 1 & 4 has to be on at the same time in the first period and coil 2 & 3 has to be on in the next period. The 0 tells you when the coils are of.
 

hippy

Ex-Staff (retired)
Looking at your table; coil 1 and coil 4 are always on when coil 2 and 3 are off and vice-versa. It seems those signals could be generated by a single PWMOUT and using an inverter gate -

Code:
#Picaxe 20X2
PwmOut C.5, 142, 286
Do : Loop
Untested, but this should give four separate outputs, one per coil, with the correct phase, using the HPWM command in SINGLE mode -

Code:
#Picaxe 28X2
;                       _   _   _
; Coil 1 Leg 17 HPWMA _| |_| |_| |_
;                     _   _   _   _
; Coil 2 Leg 23 HPWMB  |_| |_| |_|
;                     _   _   _   _
; Coil 3 Leg 25 HPWMD  |_| |_| |_|
;                       _   _   _
; Coil 4 Leg 22 HPWMC _| |_| |_| |_

HPwm PWMSINGLE, PWMLHLH, %1111, 142, 286
Do : Loop
 

Sten Martin

New Member
Thank you hippy I am very gratefull for your help. Don't you think the HPWM command is the most reliable to use since it is implemented in hardware?

If the 28X2 and 20X2 have the same power can't I use the 20X2 with the HPWM command or is it any special reason you have shoosen 28X2?

I don't fully understand how the "polarity" and "setting" works in the HPWM command. It seems to me as you used the polarity to match the initial state of my coils with "DCBA" (or is it just a variable name)?

Is the PWMLHLH DCBA the outputs that changes with the masked (1111) polarity?

Please explain.
 

hippy

Ex-Staff (retired)
The mask %1111 enables all four HPWM pins DCBA

The PWMLHLH sets polarity for pins DCBA; D=Low, C=High, B=Low, A=High when the PWM is high

You can use the 20X2 with HPWM; the code I had just happened to use the 28X2.
 
Top