Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Technical Discussion (http://www.chiefdelphi.com/forums/forumdisplay.php?f=22)
-   -   Rookie help (http://www.chiefdelphi.com/forums/showthread.php?t=31880)

Mark McLeod 20-12-2004 16:43

Re: Rookie help
 
Variable declarations must be at the very beginning of a routine. I noted that above in an edit after my original post. Sorry about that.
Quote:

Originally Posted by doyler
Code:

/*******************************************************************************
* FUNCTION NAME: Process_Data_From_Master_uP
* PURPOSE: Executes every 17ms when it gets new data from the master
* microprocessor.
* CALLED FROM: main.c
* ARGUMENTS: none
* RETURNS: void
*******************************************************************************/
void Process_Data_From_Master_uP(void)
{
static unsigned char servo1=0;
static unsigned char counter=0;
Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
 
Default_Routine(); /* Optional. See below. */
 
/* Add your own code here. */
 
if (counter < 20) // about one 1/3 second in the slow loop
counter++;
else
{
counter = 0;
if (servo1 < 255)
        servo1++; // servo1 will slowly step through each of it’s positions
else
        servo1 = 0; // servo1 will quickly reset to the zero position
}
pwm03 = servo1;
 
printf("PWM OUT 7 = %d, PWM OUT 8 = %d\n",(int)pwm07,(int)pwm08); /* printf EXAMPLE */
 
Putdata(&txdata); /* DO NOT CHANGE! */
}

(sorry if i am being annoying, im just new at this)

You're not annoying. I like to help you get started.

doyler 20-12-2004 16:54

Re: Rookie help
 
Error - Source file 'C:\...\ifi_utilities.c' name exceeds file format maximum of 62 characters.
:)

silly mplab

[edit]

hmm, do i need to install my usb to serial converter?

[/edit]

Mark McLeod 20-12-2004 16:55

Re: Rookie help
 
Quote:

Originally Posted by doyler
Error - Source file 'C:\...\ifi_utilities.c' name exceeds file format maximum of 62 characters.
:)

silly mplab

Have that default code folder sitting on your desktop don't you?:rolleyes:

doyler 20-12-2004 16:56

Re: Rookie help
 
yeah, but i have a keyspan usb -> serial

does xp not auto add it?

[edit]

Build Succeeded!

now to add it to the controler :(

[/edit]

Mark McLeod 20-12-2004 17:02

Re: Rookie help
 
Quote:

Originally Posted by doyler
yeah, but i have a keyspan usb -> serial

does xp not auto add it?

XP will. [edit2] But you probably have to install that particular device driver the first time. An install CD should have come with the converter, or you might be able to download the driver from keyspan.

Are you getting a download error using IFI_Loader?
Sometimes those adaptors auto connect to a different COM port than it advertises. You can run through and try all the possible COM ports in IFI_Loader by choosing "PortSettings" and COM1, try to download, then COM2, and try to download, etc.

[edit]
I misunderstood.
Do you have the controller or will you try that later?

For those of you reading along...
The error doyler got was because one of the path and filenames was too long for MPLAB to handle. Combined they cannot be more than 62 characters or so. The usual solution is to keep the directory for all your FIRST code at the top level of the C drive, i.e., "C:\FIRST" not on your desktop because that's really at "C:\Documents and Settings\doyler\Desktop\" which is already 41 characters long.

Mark McLeod 20-12-2004 18:43

Re: Rookie help
 
Quote:

Originally Posted by doyler
keyspan usb -> serial

How about getting the driver from here?
http://www.keyspan.com/downloads/win/

doyler 21-12-2004 14:21

Re: Rookie help
 
2 questions
For that code do i have to plug them into certain pwm outs?
Also, will my code just start?

Mark McLeod 21-12-2004 14:43

Re: Rookie help
 
Quote:

Originally Posted by doyler
2 questions
For that code do i have to plug them into certain pwm outs?
Also, will my code just start?

It assumes one servo is attached to pwm 3. You can change this to any other pwm.
Code:

pwm03 = servo1;

The code should start immediately after the download has completed.

doyler 21-12-2004 14:47

Re: Rookie help
 
I charged my battery and the chargers light turned green
I plugged it in, the battery power and fault status lights blinked, but then nothing

[edit]
now battery power, program state, and fault status are blinking green while pwn in/radio is a constant red

is this good?
[/edit]

Mark McLeod 21-12-2004 14:49

Re: Rookie help
 
Quote:

Originally Posted by doyler
I charged my battery and the chargers light turned green
I plugged it in, the battery power and fault status lights blinked, but then nothing

[edit]
now battery power, program state, and fault status are blinking green while pwn in/radio is a constant red

is this good?
[/edit]

Very good.
Now press the Prog button to get a solid orange LED.

doyler 21-12-2004 14:51

Re: Rookie help
 
Ok it works
Now i just need to learn how, why, and how to change it

First off:
How would i make the program loop somewhat faster

Mark McLeod 21-12-2004 14:59

Re: Rookie help
 
Quote:

Originally Posted by doyler
How would i make the program loop somewhat faster
Also, what will the servo do when the program executes so i know i did it right

The first sound you heard was the servo moving to it's "0" position.
The servo will then take 1.4 minutes to move very slowly through a 60 degree turn before it quickly whips back to the "0" position and repeats.

You can speed this up by changing the delay we built in.
Code:

if (counter < 20) // about 1/3 second in the slow loop for one ~60/255 degree turn
Make it "counter < 2" and it'll take about 17ms to complete a cycle.

doyler 21-12-2004 15:04

Re: Rookie help
 
Code:

static unsigned char servo1=0;
static unsigned char counter=0;

Ok, so theses make two variables, 1 is the servos position(?) and the other is the counter right

(i will go through it step by step)

Mark McLeod 21-12-2004 15:17

Re: Rookie help
 
Quote:

Originally Posted by doyler
Code:

static unsigned char servo1=0;
static unsigned char counter=0;

Ok, so theses make two variables, 1 is the servos position(?) and the other is the counter right

(i will go through it step by step)

Let me know if it worked as expected above.

Yes, servo1 is the position you set for the servo to move to. You can actually set it to any value you like. For instance if you have an RC unit, you could use that to move the servo.

The variable "servo1" could be completely replaced in this code sample with the system variable "pwm03" if you wanted. It isn't strictly needed, but it does make it easy to switch to a different pwm without having to change all your code.

This routine (Process_Data_From_Master_uP) in the default code is called the slow loop. It executes about 59 times per second (in the EDU, FRC is 38 times per sec.), because that's how fast the radio packets come in. We're using that characteristic of the loop to make "counter" a cheap timer. Each loop equals 1/59 second, so "counter<59" , for example, will equal one second.

[edit]
P.S.
You can also change "servo1++;" to something like "servo1 += 5;" to make the servo move faster still. But be careful that the logic of the check "if (servo1 < 255)" catches servo1 before it tries to become larger than 255. When that happens servo1 cannot hold a value larger than 255, so it will suddenly become a completely unexpected value.

doyler 21-12-2004 15:21

Re: Rookie help
 
Yes, it worked

So 38 is 1 second?
Then why is 2 faster then 20

I understand the variables part (except for the counter which is covered in the below code)

Code:

if (counter < 2) // about half a second in the slow loop for one 60/255 degree turn (2 = 7 seconds, 20=2 minutes)
counter++;

I know counter++ just adds one to the variable counter, but i dont understand how the counter itself works

[edit]
i dont understand your edit fully
[/edit]


All times are GMT -5. The time now is 02:29.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi