• 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.

steppermotor and pic 16f84a

Status
Not open for further replies.

Alima

New Member
Hello,

I am using a pic 16f84a and a stepper motor to make full rotation. I did the following program to make sure that the stepper motor is working and it does (turning continuously without stopping)
.
Now I want the stepper motor to stop for 5s after a full turn, then do another turn, stop for another 5s continuously.
Can someone help me fix that problem?

Below is my program for the continuous turn.


'PICBasic Stepper Motor Controller Program
Symbol TRISB = 134 'Initialize TRISB to 134
Symbol PortB = 6 'Initialize Port B to 6
symbol ti = b6 'Initial ti delay
ti = 25 'Set delay to 25 ms
Poke TRISB,0 'Set Port B lines output
start:'Forward rotation sequence
poke portb,1 'Step 1
pause ti 'Delay
poke portb,2 'Step 2
pause ti 'Delay
poke portb,4 'Step 3
pause ti 'Delay
poke portb,8 'Step 4
pause ti 'Delay
goto start 'Do again


Thank you
Alima
 

bananasiong

New Member
Hi,
TRISB is initialized with 134, which is 0x86, or 0b10000110. Since RB1 and RB2 are inputs, how are you going to output it to the stepper motor?
 

arhi

Member
Alima said:
.
Now I want the stepper motor to stop for 5s after a full turn, then do another turn, stop for another 5s continuously.
This will work if that 4 steps are full circle, if not (I cannot guess how many steps in full rotation your motor have - I have here ones that are 90 degrees, 45 degrees ... up to 1.8 degrees per step)

Code:
Symbol TRISB = 134 
Symbol PortB = 6 
Symbol ti = b6 

Poke TRISB,0 
start:'Forward rotation sequence
ti = 25 
poke portb,1 'Step 1
pause ti 'Delay
poke portb,2 'Step 2
pause ti 'Delay
poke portb,4 'Step 3
pause ti 'Delay
poke portb,8 'Step 4
ti = 200
pause ti 'Delay
pause ti 'Delay
ti=175
pause ti 'Delay
goto start 'Do again
This one is bit more universal but my knowledge of basic is "nonexistant" (i remeber something from using C64 but that was many many years ago) so i'll write it in C
Code:
// how many steps in 360degrees
#define REV 200

// delay in us between steps
// real delay will be DEL us + (7 or 8) clocks
#define DEL 25

int i;
unsigned char j=0;
unsigned char[]={1,2,4,8}
TRISB=0;
PORTB=0;
while(1){
  for (i=0;i<REV;i++){
     PORTB=char[j];
     if (++j > 3) j=0; //increase j by 1 and if bigger then 3 set to 0
     Delay_us(DEL);
  }
  Delay_s(5); //wait 5 seconds
}
@bananasong iirc symbol defines the address of the variable, trisb is initialised to 0 with poke trisb, 0
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top