Microstepping code picbasic pro


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Jan 2015
    Posts
    7

    Default Microstepping code picbasic pro

    Hi there i have been reading threads about microstepping, but i dont get it clearly and i reply to some threads about it, but no body answer (i think that is because they are old threads). I have a request to anybody willing to help, i dont have a stepper driver like Big easy, but i made one with a 16f84a, i programmed it to receive a dir and step pulse from another pic, and to give the combinations to some mosfets and to the coils of the bipolar motor. At first it worked well with some weird movements sometimes, (i guess it was because of the supply or some electrical noises), but as i have been studying, im interested in programming a pic to work as a microstepper driver. Until now, i know that some pwm are required to make the required signals to operate the coils, but i dont have it very clear.

    Of course, if somebody can help me out with this in picbasic pro language i would be very grateful!. So the basic idea is:

    -Inputs:
    *Full Step
    *Half Step
    *switches to select the microstepping config (4, 8, 16, 32, etc)
    *Step
    *DIR
    *Enable
    -Outputs
    *the pwm signals to the power transistors or the Hbridges to drive the Bi Polar Motor
    *anything else needed
    I think that just one pic would control one motor, because it would be too much to ask for the three motors. I have a 16f877a and a 18f2550.

    I guess it is to much to ask, but i want to learn further about programming in picbasic pro and maybe it can be done .

    And sorry for my bad english, im from Mexico!

    Best Regards and happy holidays.

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    Feliz Navidad y Buenos Anos!

    I'd be more than happy to help you (so would many others), but I have zero experience with motors and PWM.

    Robert


    Edit: start by posting a schematic and your code so far, that will help us to help you.

  3. #3
    Join Date
    Jan 2015
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    Oh hello there and Feliz año too!. I don't have anything yet, just all my enthusiasm to begin and learn. As I said before I have been reading and searching on the web. I found an application note from microchip about stepping and it was very well explain but the code explain their was in assembler and I don't understand a bit of that language. The link to the document is this one:

    https://www.google.com.mx/url?sa=t&s...KMe0MPOHHzXisQ

    It's very interesting actually, still I don't get anything from the code cause I know nothing about assembler. Im downloading books to learn more.

    Thank you Robert for taking your time to look at my post. Anything I find out or investigate I will feedback the thread.

    Best Regards!

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    What does your hardware look like?
    Are you doing the current sensing/control with the PIC itself (ie sampling the actual current using the ADC) (no you're not if you're using the 16F84) or are you using external comparator and flip/flops to sense and regulate the current?

    When microstepping you're not only controling the currents direction thru the coil (like you are when fullstepping) but also the amplitude. If you draw the waveform of fullstepping mode out on paper you're going to get something that, with a little bit of imagination, is looking like two sine waves with a 90° phase shift between A and B. They are very crude sinewaves with only 2 "steps" to them but never the less. Now draw the waveform for halfstepping out on paper and you'll see that it looks a Little bit more like two sinewaves, still very crude sinewaves with only 3 "steps" to them but still..... What microstepping does is adding more "steps" to the sinewaves. The more "steps" you add the sinewaves the smoother the motion from the motor becomes.

    So, you need to be able to regulate the amplitude of the current thru each of the two coils in a SIN/COS relation to each other.

    /Henrik.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    A very long time ago I rotated a bipolar stepper motor with adjustable speed.
    I then found the speed I needed and preset it to 10. That's why I commented out the ADCIN commands.
    The outputs turn on FET's to drive the motor. Hope this helps.

    'COMPILED FOR 12F675
    ANSEL = 0 'all inputs digital
    CMCON = 7 'comparators off
    trisio = %00010000 'ALL OUTPUTS EXCEPT GPIO.4 SPEEDPOT
    DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device to accurize osc
    @ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON
    GPIO = 0
    SPEEDPOT VAR BYTE


    START:
    LET SPEEDPOT = 10
    Low GPIO.4
    High GPIO.2
    'ADCIN 3,SPEEDPOT
    Pause SPEEDPOT
    Low GPIO.0
    High GPIO.1
    'ADCIN 3,SPEEDPOT
    Pause SPEEDPOT
    High GPIO.4
    Low GPIO.2
    'ADCIN 3,SPEEDPOT
    Pause SPEEDPOT
    High GPIO.0
    Low GPIO.1
    'ADCIN 3,SPEEDPOT
    Pause SPEEDPOT
    GoTo START

  6. #6
    Join Date
    Jan 2015
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    I don't have a hardware configuration yet, and about the sine/cosine relation I have been reading. The thing is that I don't know how to output this software configuration through the pic. And yes, the pic should do the sensing of the current, throw the corresponding pwm signals to the coils and the combination to make the steps. I want to know if it is possible to program this to the pic via picbasicpro, because I heard of some limitations it has against assembler (in the ccpm modules I read). And if it is possible to do, how to start. Actually I am studying about assembler just to comprehend the code in the application note that I shared in a previous reply.

    Best regards and thank you all people for helping .

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    Hi,
    It's possible to do with a PIC and PBP but it's not an easy task and not a suitable beginners project to implement the current control within the PIC itself.

    A much easier (but still not a beginners project IMO) is to use an exernal driver with integrated PWM current control (such as the L6207 though there are many alternatives) and then use the PIC to generated the apropriate phase- (digital) and current reference (analog) signals.

    You'd then use the two CCP modules to generate the two current refernce signals (SIN/COS) and a couple of I/O's to drive the digital inputs of the driver chip.

    As for generating the SIN/COS reference signals there's been more than a couple of threads on this forum regarding that specific task (though it usually involves a student who's final project is to build a three phase inverter or motor drive), if you search the forum I'm sure you'll find a couple of threads that might be of interest.

    What size of motor are we talking about here? Is a little NEMA11 with a rated current of couple of hundred mA and a suitable voltage of <24V or is it a NEMA56 which will need a hundred volts or more and currents in 10A range?

    /Henrik.

  8. #8
    Join Date
    Jan 2015
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    It is a Nema 23 with 2.3 amp per phase, and 1.8 V (but as i have been reading, it is better powered by a higher voltage supply, hence the current control you mentioned). Another subject that is not clear to me is the current control and microstepping, how can you implement it together or if one is dependent from the other one. not sure about it

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    Hi,
    Microstepping relies on good, precise current control/regulation, that's the whole point with microstepping. You move the rotor from one full step position to the next by gradually changing the currents in the two coils as opposed to fullstepping where you just reverse the polarity/direction of current.

    With a chip like the L6207, it handles the current control/regulation. It'll be your job to tell it how much current at any individual microstep and feed that to the two VRef inputs.

    You don't want to implement the current control/regulation in the PIC.

  10. #10
    Join Date
    Jan 2015
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    Ok but the microstepping thing, it can be done with the pic right? And actually use it as the control of the motor, and the chip you mention or the l298 can do the driving. So I could make a board with both things, control and driving, and from parallel port control the motion.

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    Technically you can do practically anything with PICs and PBP. The limits are your budget, skill, access to parts and patience.

    I will build a small light-duty CNC machine using PICs, once I do all the tasks I've already started.

    Robert

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    other than as a hobby or an educational process why bother when you could buy this

    http://www.ebay.com.au/itm/Single-Ax...-/400738287623?

    or this

    http://www.ebay.com.au/itm/CNC-Route...-/221654357464?

    for such a little amount , you could not homebrew it for less

  13. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Microstepping code picbasic pro

    Geez, it seems you still really haven't grasped the concept here.

    The L298 doesn't contain any current controller so if you're going to use that you need some way to regulate the current to whatever level your PIC commands. Remember that when you're microstepping you're NOT just setting the coil current to 1.2A or whatever - the current reference for each coil is changing. The L298 is often combined with the L297 and IT has the current controller in it. Oscillator, flip flops, compartors, blanking time etc etc. But since the L297 also has the step indexer built into it it's "locked" to full and half step mode.

    The L6207 i mentioned has the H-bridge (like in the L298) but also the current controller part of the L297 (well perhaps not the same circuit but the functionallity).

    If you DON'T use a chip with built in current controller you're going to have to implement that part of the chips circuitry with other parts or in code - possible but not easy, certainly not in the code alone.

    In the Microchip App note it looks like they are simply and "blindly" throwing PWM dutycycles from a SIN lookup table at the H-bridge without actually regulating or limiting the current. The two sense lines from the H-bridge IS connected to the ADC inputs but the only analog input read in the firmware is AN0 which is the speed reference - as far as I can see. It might work, sort of, but I think it's a very crude way and certainly one that will destroy the motor when the powersupply voltage is higher than the rated motor voltage (which, as you've found out, is needed to get any sort of speed out the motor). Either I'm missing something or that design is seriously flawed.

    Then of course, Richard is right, it'll be much easier and cheaper to just buy something - but where's the fun in that right?

    /Henrik.

Similar Threads

  1. PicBasic Pro code to drive MCP4291 DAC?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th July 2015, 03:28
  2. Execute Picbasic Pro code from external EEPROM?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th February 2014, 03:31
  3. sample code for AT45DB642D in Picbasic Pro
    By itsssyam in forum General
    Replies: 0
    Last Post: - 10th March 2010, 06:01
  4. Replies: 3
    Last Post: - 1st July 2008, 21:07
  5. Anyone have ADS1100 I2C PicBasic Pro code example
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th March 2006, 22:13

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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