18f4431; driving a stepper IN HARDWARE mode


Results 1 to 5 of 5

Threaded View

  1. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    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
    Half-step is 1st graphic, 2-phase is 2nd.
    Attached Images Attached Images   
    Last edited by Bruce; - 20th January 2010 at 01:43.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. 18F4431 - Complementary mode PWM
    By AndrewC in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 15th December 2011, 12:23
  2. Driving two stepper motors at the same time
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th February 2010, 18:33
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 22:07
  4. Driving Stepper Motor with PBL3717
    By crhomberg in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th November 2007, 21:59
  5. Driving a stepper motor bipolar
    By debutpic in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th June 2007, 18:34

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts