Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem is counting steps of stepper motor

Status
Not open for further replies.

mohsenln90

Newbie level 2
Newbie level 2
Joined
Apr 17, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,293
Hello
my name is mohsen, I work on project that I want to count the steps of stepper motor if the numbers of steps are in Periods PORTD.2 turn on and else PORTD.3 turn on.
I wrote the program in c language in code vision avr and simulate in proteus but the simulation doesn’t work properly.
My program is:
Code:
{
     i=50;
          while(PINB.1=0)    
  {
    for(j=0;j<200;j++)
     {
         
      PORTC=0b00000011;
      delay_ms(i);
      PORTC=0b00000110;
       delay_ms(i);
      PORTC=0b00001100;
       delay_ms(i);
      PORTC=0b00001001;
       delay_ms(i);
     } 
     if(PINB.1=1)    
          {PORTC=0x00;}
     if((j>5)||(j<14)){
     PORTD.2=1;}
     else
     { PORTD.3=1;}
 
   }

}
}
Would you please help me.
Thanks.
 
Last edited by a moderator:

Yes you can measure counts at where you're giving pulses to stepper motor.
Or yiu can use counter for measuring frequency you are giving.
 

Yes you can measure counts at where you're giving pulses to stepper motor.
Or yiu can use counter for measuring frequency you are giving.

Hi
would you please write a sample code for counting steps of stepper motor?
Thanks
 

Hello!

Hi
would you please write a sample code for counting steps of stepper motor?
Thanks

Counting steps is not more difficult than counting beans or tomatoes, it's just a matter of counting.
Now I have auto-indented your code, and the result is as follows:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void MyFunc(void) {
    i=50;
    while(PINB.1=0) {
        for(j=0;j<200;j++) {
            PORTC=0b00000011;
            delay_ms(i);
            PORTC=0b00000110;
            delay_ms(i);
            PORTC=0b00001100;
            delay_ms(i);
            PORTC=0b00001001;
            delay_ms(i);
        } 
        if(PINB.1=1) {
            PORTC=0x00;
        }
        if((j>5)||(j<14)) {
            PORTD.2=1;
        }
        else {
            PORTD.3=1;
        }
   }
}
}



Here are the following problems:

1. You have more closing brackets than opening brackets.
2. This line will not work: while(PINB.1=0)
3. This line will not work: if(PINB.1=1)
4. If you fix both lines above, do you think the (3) will ever happen?
As it is inside of the (2) loop, it will never happen.
5. You have a for loop with j going from 0 to 200 (not included), and
after this, you test whether j is between 5 and 14. Do you think this
will ever happen?
etc, etc...

Instead of asking people to write your code, try to write yours with coherent indents.
If you don't, nobody is going to understand your code, and I'm afraid you will never understand
it yourself.

Dora.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top