Wow - nice catch on that one. It does appear to work. Cool idea, and thanks for the tip.
I wish I had a stepper motor board to test this on, but it does look good compared to the
UCN5804B datasheet for 2-phase & half-step drive sequences in MPSIM logic analyzer
.. when simulated for an 18F2431.
I already had a project in MPLAB using C18 for an 18F2431, so I tossed these values in
using your OVDCOND approach, and it looks good. Do these waveforms look good for both
2-phase & half-step?
If they do, and it's worthwhile .. I'll work up an example in PBP. I'm a total newbie when it
comes to steppers - so let me know if the control signals look OK.
Here's the C18 example I used to test & simulate, which should be super easy to translate
to PBP.
Half-step is 1st graphic, 2-phase is 2nd.Code:#include p18f2431.h #include delays.h #pragma config OSC=HS,LVP=OFF,WDTEN=OFF,MCLRE=OFF union DutyCycle { unsigned int Cycle; unsigned char wByte[2]; } Duty; void main(void) { // Port init PORTB = 0; // clear port TRISB = 0; // all outputs // PCPWM init PTCON0 = 0; // Free Running mode. PTPERL = 0; // PTPERH = 1; // PTPER = $0100 or 256d for ~19.45kHz PWMCON0 = 0b01011111; // PWM[5:0] outputs enabled PWMCON1 = 1; // OVDCON synched to PWM time base DTCON = 0; // zero dead-time PTCON1 = 0b10000000; // PWM time base is ON Duty.Cycle = 1023; // 19.5kHz has a 10-bit resolution. PDC0L=Duty.wByte[0]; PDC0H=Duty.wByte[1]; PDC1L=Duty.wByte[0]; PDC1H=Duty.wByte[1]; PDC2L=Duty.wByte[0]; PDC2H=Duty.wByte[1]; while(1) { /* // half step mode OVDCOND = 0b00000001; // use override control to switch pwm pins Delay10TCYx(250); // 500uS @ 20MHz OVDCOND = 0b00000011; Delay10TCYx(250); OVDCOND = 0b00000010; Delay10TCYx(250); OVDCOND = 0b00000110; Delay10TCYx(250); OVDCOND = 0b00000100; Delay10TCYx(250); OVDCOND = 0b00001100; Delay10TCYx(250); OVDCOND = 0b00001000; Delay10TCYx(250); OVDCOND = 0b00001001; Delay10TCYx(250); */ // 2 phase mode OVDCOND = 0b00001001; Delay10TCYx(250); OVDCOND = 0b00000011; Delay10TCYx(250); OVDCOND = 0b00000110; Delay10TCYx(250); OVDCOND = 0b00001100; Delay10TCYx(250); } // End while(1) } // End main




Bookmarks