Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Microchip Circuit - Getting Started

Status
Not open for further replies.
No car batter, lol. But I do have an 18.4V drill battery I can give a shot. But I neet to make sure first that the code I have is also fine. I think I might need to add some pull-up, pull down, resistor to the logic signals. One thing I should change is the wires. I'm using really thin wire in the protoboard, like 32GWA for the 12V and power ground. I will change those to 22GWA and see if that helps.
 
Last edited:
No car batter, lol. But I do have an 18.4V drill battery I can give a shot. But I neet to make sure first that the code I have is also fine. I think I might need to add some pull-up, pull down, resistor to the logic signals.

I'm not sure if a drill battery will work as well, but it's definitely worth a shot.

And yes, pull-up (or pull-down) resistors are a good idea in many cases.
 
I have a feeling you are partially stalling the motor. Here are a few things you can try:

500mA should work for a properly configured system but it's a bit low for a 2A motor especially when trying to jump right to 500 steps/second with no acceleration curve and while using full steps. I would raise the current to 1A at a minimum.

You have MS1 and MS2 both low putting your motor controller in full step mode. Full steps are coarse and require lots of current to operate smoothly especially without an acceleration curve. Set them both high so you get 1/16 steps. The smaller steps are smoother and it's more likely the motor will start moving.

Motors can't start rotating at full speed instantaneously. To do so would require massive amounts of power. To get around this, you need to accelerate the motor up to the speed you want. Even a simple linear acceleration curve that only takes 1/2 a second can work wonders! At the very least you should be stepping the motor more slowly especially when using full steps.
 
I tried a smaller motor stepper motor and still did the same thing as the big one. I've changed MS1 and MS2 to different setting and increased current with no success. I might upload a video to youtube of what the motor is doing. Also I'm using 3.3V for the logic circuit and thermal pad is not tied to ground right now, could that be an issue? Also the capacitor for VBBx I'm using is 47uF not 68uF as shown in the schem I posted. I kept on reading the datasheet of the A3979 and I gotta fix a couple of things.

I have the A3979 chip installed on a SSOP28 TO DIP28 PCB ADAPTER. This adapter then goes to a socket on the protoboard. This could in fact increase the resistance for the Rsense resistors. Maybe that's why I don't see any voltage across RS1 or RS2??? The picture I posted doesn't show the socket for the A3979 and some components are missing as this is an older picture.
 

Attachments

  • IMG_20111106_235812.jpg
    IMG_20111106_235812.jpg
    1.2 MB · Views: 128
Last edited:
You absolutely need to tie the thermal pad to GND. Odd behavior can occur if you don't!

Definitely upload a video with sound. You can tell a lot about what's going on by the sound of the motor.
 
So I connected the thermal tab to ground and didn't make much difference, but at least I got the thing spining now, maybe it did make a difference. The below code is what got it working. Notice in the video that I have three 1OHM resistors for RxSense. I'm getting the 0.2OHM 2W and 0.1OHM 2W Monday in the mail and will replace those. My Fluke DVM always reads the three parallel resistors as 0.4-0.5 maybe the leads resistance account for the error and they are 5%.

The problem I'm having now is that MS2 is not changing state, it's always low, don't know why, I checked at the pic and disconnected ms2 wire from A3979 and still don't change state when I run the code with ms2 = 1; or ms2 = 0; it's always low. So for the code below MS1 was high and MS2 was low.

I have to work on the acceleration part. I'll see what I can come up with or if you have a pice of code I could try let me know. I uploaded a video. So far so good, I'm almost there, thanks alot to you guys for your help. I just need to get this running smoothly and I'm done.

Code:
#define FCY 8000000UL

#include <P24FJ64GB002.h>
#include <libpic30.h> 
 
_CONFIG1( FWDTEN_OFF  & ICS_PGx1 & GWRP_OFF & GCP_OFF & GWRP_OFF & JTAGEN_OFF) 
_CONFIG2( POSCMOD_NONE  &   I2C1SEL_PRI & IOL1WAY_ON & OSCIOFNC_ON & FCKSM_CSDCMD  & FNOSC_FRC & PLL96MHZ_OFF & IESO_OFF)
_CONFIG3(SOSCSEL_IO)
//Fast Internal RC (FRC) Oscillator 8MHz Clock Source

//Function Prototypes
void PWMStep (void);
void PWMRef (void);
void PWMVpfd (void);

//Defines
#define                   sleep                    LATAbits.LATA0
#define                   ena                       LATAbits.LATA1
#define                   pirsens                PORTAbits.RA2
#define                   rst                        LATAbits.LATA3
#define                   sr                          LATAbits.LATA4
//#define                   sense1                  PORTBbits.RB2
//#define                   sense2                  PORTBbits.RB3
#define                   step                      LATBbits.LATB4
#define                   ms1                      LATBbits.LATB8
#define                   ms2                      LATBbits.LATB7
//#define                   home                   PORTBbits.RB9
#define                   dir                        PORTBbits.RB15
 
main ()
{

    AD1PCFG = 0xFFFF;          //All pins are digital

    //Output Ports
    TRISAbits.TRISA0 =   0;      //Set sleep port as output
    TRISAbits.TRISA1 =   0;      //Set ena port as output
    TRISAbits.TRISA3 =   0;      //Set rst port as output
    TRISAbits.TRISA4 =   0;      //Set sr port as output
    TRISBbits.TRISB4 =   0;      //Set step port as output
    TRISBbits.TRISB7 =   0;      //Set ms1 port as output
    TRISBbits.TRISB8 =   0;      //Set ms2 port as output
    TRISBbits.TRISB15 = 0;      //Set dir port as output
 
    //Input Ports
    //TRISBbits.TRISB9 = 1;      //Set home port as input
    TRISAbits.TRISA2 = 1;      //Set pirsens port as input
    //TRISBbits.TRISB2 = 1;      //Set sense1 port as input. Analog
    //TRISBbits.TRISB3 = 1;      //Set sense2 port as input. Analog

    //Output ports initial states
    sleep = 1; //Logic high is normal operation. When logic low minimize power consumption when the motor is not in use.
    ena = 1;    //Logic high, the outputs are disabled. Logic low enables all of the DMOS outputs.
    rst = 1;     //Logic high is normal operation. Pulse low resets the device.
    sr = 0;       //When the SR input is logic low, Active mode is enabled and synchronous rectification can occur. When the SR input is logic high, synchronous rectification is disabled
    step = 0;   //A low-to-high transition on the STEP input sequences the translator and advances the motor one increment.
    ms2 = 1;   //The input on terminals MS1 and MS2 selects the microstepping format.
    ms1 = 1;   //H H Sixteenth Step 4W1-2 Phase; L H Quarter Step W1-2 Phase; H L Half Step 1-2 Phase; L L Full Step 2 Phase
    dir = 1;     //The state of the DIR input determines the direction of rotation of the motor.

    PWMRef ();
    PWMVpfd();
 //   PWMStep ();

        while (1)
              {  
                          ena = 0;     
                          step = 1;
                          __delay_us(500);
                          step = 0;  
                          ena = 0;      
                          __delay_us(500);                
    
                               }
}

//void PWMStep (void)
//{
//       RPOR2bits.RP4R = 18;                               //OC1 Output to Pin RB4 PWM
//       OC1CON1 = 0;                                             // Clear registers
//       OC1CON2 = 0;
//       OC1RS   = 199;                                             //20KHz PWM period
//       OC1CON2bits.SYNCSEL = 0x1F;               //synchronized by itself
//       OC1CON1bits.OCTSEL = 0x07;                  //Peripheral clock is the source for output Compare
//       OC1CON1bits.OCM = 0b110;                     // Edge-aligned PWM mode on OC
//} //endPWMStep 

void PWMRef (void)
    {
           RPOR7bits.RP14R = 19;                             //OC2 Output to Pin RB14 PWM
           OC2CON1 = 0;                                             // Clear registers
           OC2CON2 = 0;
           OC2RS   = 199;                                             //20KHz PWM period
           OC2R = 180;                                                 //25% initial duty cycle, (180/199) * 3.3 = ~2.98Vout, Motor Current = (2.98V/(8*0.33OHM) = ~1.13A
           OC2CON2bits.SYNCSEL = 0x1F;               //Synchronized by itself
           OC2CON1bits.OCTSEL = 0x07;                  //Peripheral clock is the source for output Compare
           OC2CON1bits.OCM = 0b110;                     // Edge-aligned PWM mode on OC
    } //endPWMRef

void PWMVpfd (void)
    {
           RPOR6bits.RP13R = 20;                             //OC3 Output to Pin RB13 PWM
           OC3CON1 = 0;                                             // Clear registers
           OC3CON2 = 0;
           OC3RS   = 199;                                             //20KHz PWM period
           OC3R = 82;                                                   //40% initial duty cycle, (80/199) * 3.3V = ~1.32Vout
           OC3CON2bits.SYNCSEL = 0x1F;               //Synchronized by itself
           OC3CON1bits.OCTSEL = 0x07;                  //Peripheral clock is the source for output Compare
           OC3CON1bits.OCM = 0b110;                     // Edge-aligned PWM mode on OC
    } //endPWMVpfd
 
Last edited by a moderator:
Hi guys.
I did end up building the board and installed all the parts.
The motor worked ok for a little while, but it then stopped working.
I think I killed the A3979 by leaving the current set at 2.5A. Will replace the A3979 tomorrow and see what happens. Here is the board I made. Any comments, critics, extra ideas are welcomed. Top and Bottom Layers are full ground plane to help with thermal and it's 2oz Copper.
 

Attachments

  • BarePCBBot.JPG
    BarePCBBot.JPG
    39.2 KB · Views: 130
  • BarePCBTop.JPG
    BarePCBTop.JPG
    61 KB · Views: 141
  • FullPCB.jpg
    FullPCB.jpg
    65.2 KB · Views: 130
  • PCBDimmensions.png
    PCBDimmensions.png
    21.8 KB · Views: 125
  • PCBLayout.png
    PCBLayout.png
    67.8 KB · Views: 123
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top