PyroElectro.com Forum Index PyroElectro.com
Build what you want, Be the pyro you are.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The Wooden Menace; Robotic Arm
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    PyroElectro.com Forum Index -> Projects
View previous topic :: View next topic  
Author Message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 402
Location: Earth

PostPosted: Mon Nov 12, 2007 10:24 pm    Post subject: The Wooden Menace; Robotic Arm Reply with quote

The Wooden Menace Project Write-up

Quote:
The Wooden Menace is a robotic arm made from hobby servos
& (you guessed it) wood! It can be autonomously or remotely controlled.


Link


Questions & Comments?
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Mon Mar 17, 2008 6:01 am    Post subject: HELP Reply with quote

Hello everyone I need help in understanding a part of a code.



int servo0 = 0xF63B; // Servo 0
int servo1 = 0xF077; // Servo 1


these two statements just initialize the variables with certain values, I do not see how this gives the delay to the servo motors with C????


Help! I need this for my final year project! Pleaseeeeeeeee


Thank you all
Back to top
View user's profile Send private message
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Mon Mar 17, 2008 2:22 pm    Post subject: Reply with quote

Hello everyone...


I was wondering if someone could explain to me the initialization of servo1 and servo2, because I do not see how a delay is provided so that the servo moves in a certain position. I understand the interrupts and timers, how they are generated and preloaded, rescaled that is ok. I just really don't get how the servos get their pulse length (delay)...based on what????


Thank you
Back to top
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 402
Location: Earth

PostPosted: Mon Mar 17, 2008 5:15 pm    Post subject: Reply with quote

Hey Engineer41,

To answer your first question:

Code:
int servo0 = 0xF63B; // Servo 0
int servo1 = 0xF077; // Servo 1


These two lines of code initialize the variables that hold the amount that the two servos should delay while the PWM signal is +5v (aka logic 1). The values put into them initiatially are just randomly chosen as they are just changed later on when the program operates.

The actual delay calculation....

If you look at the timer initialization it has a 1:2 prescalar. This means the timer counts twice as fast than normal.

Known values:

System Clock Frequency - 20MHz
Instruction Frequency - 20MHz/4 = 5 MHz

Max Timer Value (16 bit) - 0xFFFF
Set Timer Value - 0xF63B (servo 0) & 0xF077 (servo 1)
Prescalar - 2



This formula is actually in the data sheet. Take a look at it if you need a better understanding of what is going on. Otherwise it's pretty straight forward.

The 5th post down here: http://forums.pyroelectro.com/viewtopic.php?t=13&start=15 explains this process more clearly
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Mon Mar 17, 2008 8:02 pm    Post subject: Reply with quote

Hello!


Thank you so much for answering! I am in such a mess right now with my final year project :( . I have a demonstration in two weeks and I am having trouble with my code .... Thank you so much for the explanation, I really appreciate it! I have one more question where I am totally lost, well two questions.


1. Where in the program do you bring PORT low?? If you have 5 servos and you want to bring the port high when timer 1 is set, and then bring it low at overflow, where exactly in the code do you do it?

2. I also get errors when I initialize the two timer1 registers with a different value in each switch statement :( . I am using PIC16F877A and I just initialize it like so:

TMR1H:TMR1L = some value; (0xf892 for example)

and then I do the same thing in the next switch statement and I get the same error, that I reinitialized the timer....
:?:



Thank you so much for your help! You are saving my grade :( I am at the point of desperation! :(
Back to top
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 402
Location: Earth

PostPosted: Tue Mar 18, 2008 1:28 am    Post subject: Reply with quote

Hey Engineer41,

If you're using my code (or modifications) in your senior project be kind enough to mention it in your references in your project write up. Very Happy

Arrow (1) The servo PWM's switch in this statement:
Code:
            switch(count){
         case 1:     PORTA = 0x08; // First Stage
                   WriteTimer1( servo3 );
                  break;
         case 2:      PORTA = 0x04; // Left Gripper
                  WriteTimer1( servo1 );
                  break;
         case 3:      PORTA = 0x00;
                  PORTC = 0x02; // Swivel/Rotate
                  WriteTimer1( servo4 );
                  break;
         case 4:      PORTC = 0x00;
                  PORTA = 0x02; //Right Gripper
                  WriteTimer1( servo0 );
                  break;
         case 5:      PORTA = 0x00;
                  PORTC = 0x01; // Second Stage
                  WriteTimer1( servo2 );
                  break;
         case 6:      PORTC = 0x00; //Future Servo?
                  WriteTimer1( 0 );
                  break;
            }


Case 1 turns PortA Pin 4 On & Resets the timer1.
Case 2 turns PortA Pin 4 Off, PortA Pin 3 on & Resets the timer1.
Case 3 turns PortA Pin 3 Off, PortC Pin 2 on & Resets the timer1.
Case 4 turns PoirtC Pin 2 Off, PortA Pin 1 on & Resets the timer1.
etc...
etc...

Arrow (2) It's a good idea not to initialize stuff within the switch statement. That will give compiler errors. Do all your initializations at the top of the program like I did. Modify them in the switch statement like I do. If this doesn't answer your second question feel free to copy and paste some code & the mplab error. Please not your entire program. Shocked
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Tue Mar 18, 2008 1:36 am    Post subject: Reply with quote

Hello! THank you so much for answering again!


I am using the idea of using interrupts and switch statements that you did in your code, I will certainly put your code as a reference!

I am not using MPLAB and therefore I do not have functions such as writetimer1()....I can only give new values to registers....I am using MikroC...I will try again and tell you what happens.


Thank you once again for your explanation!!!
Back to top
View user's profile Send private message
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Thu Mar 20, 2008 1:42 am    Post subject: I am not understanding something Reply with quote

Hello,


I am defining the code in this way, your code ...I am pasting here a part:

if(INTCON.TMR0IF) //check if TMR0 interrupt flag is set
{
//WriteTimer0( 0x3CAF );
TMR1L = 0x77;
TMR1H = 0xFC;

count = 0;
INTCON.TMR0IF = 0; //clear TMR0 flag
}
if(PIR1.TMR1IF == 1 && PIE1.TMR1IE == 1) //if set controls the first servo
{
count++;
switch(count){
case 1: PORTD = 0x01; // First Stage
//WriteTimer1( servo0 );
break;
case 2: PORTD = 0x02; // Servo 1
TMR1H:TMR1L = servo1;
break;
case 3: PORTD = 0x00;
//PORTC = 0x02; // Swivel/Rotate
TMR1H:TMR1L = servo2;
//WriteTimer1( servo2 );


I keep receiving an error that TMR1H label has been redefined:(


I don't understand why, because its the only way to initialize the timer1 in PIC16F877A ....

Its not compiling because of this ...anyone? Please help :(


Thank you all
Back to top
View user's profile Send private message
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Thu Mar 20, 2008 2:10 am    Post subject: Reply with quote

I have a question...which might fix my problem...how do you I assign to a variable the first byte of a hex number in this form '0xf98E' ??? If I can do that I can fix the problem, cause I need to reassign the value of Timer1...


Thank you!
Back to top
View user's profile Send private message
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Thu Mar 20, 2008 2:11 am    Post subject: I am not understanding something Reply with quote

Hello,


I am defining the code in this way, your code ...I am pasting here a part:

if(INTCON.TMR0IF) //check if TMR0 interrupt flag is set
{
//WriteTimer0( 0x3CAF );
TMR1L = 0x77;
TMR1H = 0xFC;

count = 0;
INTCON.TMR0IF = 0; //clear TMR0 flag
}
if(PIR1.TMR1IF == 1 && PIE1.TMR1IE == 1) //if set controls the first servo
{
count++;
switch(count){
case 1: PORTD = 0x01; // First Stage
//WriteTimer1( servo0 );
break;
case 2: PORTD = 0x02; // Servo 1
TMR1H:TMR1L = servo1;
break;
case 3: PORTD = 0x00;
//PORTC = 0x02; // Swivel/Rotate
TMR1H:TMR1L = servo2;
//WriteTimer1( servo2 );


I keep receiving an error that TMR1H label has been redefined:(


I don't understand why, because its the only way to initialize the timer1 in PIC16F877A ....

Its not compiling because of this ...anyone? Please help :(


Thank you all
Back to top
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 402
Location: Earth

PostPosted: Thu Mar 20, 2008 2:51 pm    Post subject: Reply with quote

Hey,

I don't have much time to look over your code but my initial thought is either that you can't define TMR1H:TMR1L = servoX; inside the switch. Or you have to define the TMR1H and TMR1L registers seperately. Try to do it without the switch statement, like with if statements and see if you get the same error.

Anyway, I'll have more time later. Smile

~Good luck Wink
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Fri Mar 21, 2008 10:50 pm    Post subject: Reply with quote

Hello!


Thank you for repliying! I can't define them together, I already figure it :D...but I need to change the timers I am using with PIC16F877A...


I have a small question, is the instruction cycle the same? If my chip is 20Mhz frequency, do I perform the calculations in the same manner?


Thank you!
Back to top
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 402
Location: Earth

PostPosted: Sun Mar 23, 2008 5:08 pm    Post subject: Reply with quote

Arrow It looks like the PIC16F877A has a two stage pipeline which means that the actual instruction frequency would be -->
20 MHz / 2

You can double check this by making a simple delay circuit to blink an led. Make the code so it should blink once a second then just see if it does. After you got that done then you're ready to move on. Wink
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Tue Mar 25, 2008 9:31 pm    Post subject: Reply with quote

Hello,


Does that mean all the calculations are to be made with doing the following?:

20MHz/2= 10Mhz = 10,000,000??

But my timers are only 8 bits and 16 bits...I'd have to use prescaler of 256 then:( don't I?
Back to top
View user's profile Send private message
Engineer41
Newbie Pyro


Joined: 17 Mar 2008
Posts: 15

PostPosted: Tue Mar 25, 2008 9:39 pm    Post subject: Reply with quote

Its a 200 ns instruction cycle...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PyroElectro.com Forum Index -> Projects All times are GMT
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group