Need to PWM 4 outs
Update: I am moving this to Propeller as it is probably better suited and may be simpler to put all code under one roof.
I am rebuilding a CNC machine controller using the existing PS, connectors, box, etc. All I am doing is replacing the PIC16F84A with an SX28. The motors are unipolar 6 wire, so I need to turn on and off 4 transistors that are already on the board(TIP120). The board does not have sense resistors, they are PWMing at a fixed approx 50duty cycle at .03125 microsecond frequency. I could do either: leave the pins high unless output is active, in that case pulse low for each PWM cycle, or the opposite.
The inputs from the PC are step and direction, and can be altered to active low for each. I need to sequence each step input based on the dir pin. I am not sure the best way to do this. If you are moving the motor forward, then you want to change Dir, do you go to the previous Sequence, or start over at sequence A and then sequence in reverse?
Here is just a crude start to simulate PWM output. I am pretty much stuck on how to do this code so that it will toggle in each new sequence according to the direction. Also, I really need this to half step, in which case I need half stepping sequences, but I figured I need to start simple.
TIP1 VAR RA.0 'coil 1
TIP2 VAR RA.1 '2
TIP3 VAR RA.2 '3
TIP4 VAR RA.3 '4
Step VAR RB.0
DR VAR RB.1
Seq0 = %0000
SeqA = %0101
SeqB = %0110
SeqC = %1010
SeqD = %1001
'setup
TIP1 = 1
TIP2 = 1
TIP3 = 1
TIP4 = 1
MAIN:
IF STEP = 1 AND DR = 1 then? 'advance one sequence
IF STEP = 1 AND DR = 0 then ? 'back up one sequence
GOTO main
SequenceA:
RA = SeqA
'pause .015 micro seconds
RA = Seq0
'pause .015 micro seconds
'put new IF thens here for New STEP pulse?
GOTO SequenceA 'how to loop here, but get back to main if new STEP?
SequenceB:
RA = SeqB
'pause .015 micro seconds
RA = Seq0
'pause .015 micro seconds
GOTO SequenceB
SequenceC:
RA = SeqC
'pause .015 micro seconds
RA = Seq0
'pause .015 micro seconds
GOTO SequenceC
SequenceD:
RA = SeqD
'pause .015 micro seconds
RA = Seq0
'pause .015 micro seconds
GOTO SequenceD
Thanks for any suggestions how to proceed.
Post Edited (originator99) : 9/29/2006 11:25:54 PM GMT
I am rebuilding a CNC machine controller using the existing PS, connectors, box, etc. All I am doing is replacing the PIC16F84A with an SX28. The motors are unipolar 6 wire, so I need to turn on and off 4 transistors that are already on the board(TIP120). The board does not have sense resistors, they are PWMing at a fixed approx 50duty cycle at .03125 microsecond frequency. I could do either: leave the pins high unless output is active, in that case pulse low for each PWM cycle, or the opposite.
The inputs from the PC are step and direction, and can be altered to active low for each. I need to sequence each step input based on the dir pin. I am not sure the best way to do this. If you are moving the motor forward, then you want to change Dir, do you go to the previous Sequence, or start over at sequence A and then sequence in reverse?
Here is just a crude start to simulate PWM output. I am pretty much stuck on how to do this code so that it will toggle in each new sequence according to the direction. Also, I really need this to half step, in which case I need half stepping sequences, but I figured I need to start simple.
TIP1 VAR RA.0 'coil 1
TIP2 VAR RA.1 '2
TIP3 VAR RA.2 '3
TIP4 VAR RA.3 '4
Step VAR RB.0
DR VAR RB.1
Seq0 = %0000
SeqA = %0101
SeqB = %0110
SeqC = %1010
SeqD = %1001
'setup
TIP1 = 1
TIP2 = 1
TIP3 = 1
TIP4 = 1
MAIN:
IF STEP = 1 AND DR = 1 then? 'advance one sequence
IF STEP = 1 AND DR = 0 then ? 'back up one sequence
GOTO main
SequenceA:
RA = SeqA
'pause .015 micro seconds
RA = Seq0
'pause .015 micro seconds
'put new IF thens here for New STEP pulse?
GOTO SequenceA 'how to loop here, but get back to main if new STEP?
SequenceB:
RA = SeqB
'pause .015 micro seconds
RA = Seq0
'pause .015 micro seconds
GOTO SequenceB
SequenceC:
RA = SeqC
'pause .015 micro seconds
RA = Seq0
'pause .015 micro seconds
GOTO SequenceC
SequenceD:
RA = SeqD
'pause .015 micro seconds
RA = Seq0
'pause .015 micro seconds
GOTO SequenceD
Thanks for any suggestions how to proceed.
Post Edited (originator99) : 9/29/2006 11:25:54 PM GMT
Comments
Do you really mean 15 nano seconds (0.015 uSec).... I suspect what you want is much longer!
The sequences and directions are easy when you employ a state machine configuration. On top of that, you can simply turn off the selected transistors by ANDing the port bits with 0000 for the desired duration.
This is all quite possible using interrupts and a simple-minded real-time scheduler.
Cheers,
Peter (pjv)
16 cycles in 0.5uSec = 32 MHz ! I can't believe the pwm is that fast from a PIC.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
Post Edited (originator99) : 9/30/2006 5:08:53 AM GMT