embedded C++

i was wondering if the embeded C++ program is the same as regular C++ like for programing a micro controller. so if i hook my pda to a microcontroller do i program it the same way or do i need something special to comunicate between the pda and the micro controller, like a special library or something.

also can someone recomend a pda to use to program the micro controller and where i can get a serial cable adapter to hook up to the microcontroler comm port.

thanks

Reply to
maintteck
Loading thread data ...

Each microcontroller has its own compiler. It depends on the microcontroller you use. A C compiler exists for just about every microcontroller. Some microcontrollers also have C++ compilers.

If you develop the code on your PDA or computer, it will probably need to be with a "cross compiler." A cross compiler is a compiler which executes on one machine but produces code for another machine. If your PDA and your microcontroller use the same CPU, you can probably get by with the same compiler.

The next thing you'll need is a list of the relevant registers on the microcontrollers and their addresses so that you can configure the various ports of the microcontroller. This is usually just a header file with constants defining the port addresses.

I doubt that you really want to use a PDA to develop code. PDA's generally have poor input and display devices (i.e. keyboards and monitors).

It is probably more convenient to develop code on a desktop computer and then download to the microcontroller.

Depending on which microcontroller you select, you may have to purchase a piece of hardware to program the microcontroller.

More and more contemporary microcontrollers have "In Circuit Programming" ability. This means that you can program them without removing them from their target hardware. It's a pretty useful. More and more microcontrollers also have flash memory allowing the same processor to be programmed repeatedly.

I think you need to describe your plans better before any more questions can be answered. For example:

  • What microcontroller were you planning on using?
  • Do you have access to a desktop computer?
  • What is your budget for getting into microcontrollers?

Ed L

Reply to
Ed LeBouthillier

controller

i curently own a motorola 68hc11

i also have access to a desktop computer

the reason i want to use a pda is to use it as a brain for the robot. so the pda while do all desision making while the micocontroller will handle the I/o components(so all the micro controller would do is turn on and off motors its told to by the pda and send sensor info back to the pda)

the reason i want to use the pda i because of the fasted seed and easy to do floating point math as well as being able to handle longer program.

also another question is am i going a bout this the right way. is there something else that might be small enough to fit on a robot but have similar feature of the 68hc11 (I/O, PWM, Pulse counter, A/D etc) and the speed of a pda as well the ease of floating point math.

the reason i wanted to use it pda is because i already have the microcontroller. as well i know a bit of c++. but im open minded to things that would make my life easyer

Thanks

Reply to
maintteck

Look for fixed point arithmetics. That could remove the need for floating point operations.

Patrik

Reply to
RedX

OK, cool. The 68HC11 is a good microcontroller. Does yours have flash memory or what? How does it store its program? That will determine what hardware you need to program it.

I don't think that there are any free C++ cross-compilers for the

68HC11 but I know that there are several C cross-compilers.

Here's a webpage with some links to free C compilers:

formatting link

Good, you'll probably want to use that to _program_ the 68HC11. The PDA will be used to _command_ the 68HC11 after it has been programmed.

What you'll probably want to do is to write a program for the 68HC11 which takes serial commands. There are two aproaches:

1) the 68HC11 handles all navigation tasks, keeping track of distances moved, generates the motor control PWM, scans sensors and makes reports to the PDA. Typical commands are:

Forward 10 Right 90 Left 90 Reverse 10 getBumpers read left encoder read right encoder

2) the 68HC11 just turns on the motors to the specified speed and allows the PDA to request the sensor data from the PDA to control the 'bot. Typical commands are:

Speed 10 Turn Ratio 50 get sensors

That makes sense. The PDA will probably not _program_ the 68HC11 but will probably _command_ it. I doubt that you'll find a cross compiler that can run on the PDA (I could be wrong) but once you have a program running on the 68HC11, you'll be able to send serial commands from the PDA.

I think so. I did something very similar although I used a PC to control my 68HC11. I took approach 1 above and used the

68HC11 to do all the navigation tasks. It worked well enough.

There are lots of different microcontrollers around. I've used several of them from PICs to AVRs to Basic Stamps. One of the better little controllers that I've found lately is the Zilog Z8 Encore microcontrollers. You can get a complete development kit which includes a controller board with 60 I/O pins, a programmer cable and a really nice little C compiler for $40.00. I've been using one on a project lately and it's a blast for so little money.

But, it really doesn't matter what microcontroller you use. The 68HC11 is a magnificent controller and will do the job that you want. The floating point is really a product of the compiler.

You should be fine. The PDA and 68HC11 will make a nice little package. You just need to develop software for the 68HC11 to make it take serial commands from the PDA and you're off and running.

If you want, I could dig up my old code for the 68HC11 as an example of the kind of code you'll need. I've got some for both the 68HC11 and the PIC. It's written in C.

Ed L

Reply to
Ed LeBouthillier

Can you post a link? I search zilog.com and too many matches come up to sift through. How much program space does yours have? how much RAM?

Thanks, Rich

Reply to
aiiadict

thanks for the info that really helps.

the board i have has 32K RAM, 8K EEPROM, i think i have another ram chip in it but i cant remember.

also i was wondering if it was posible to use visual basic instead of c i heard it might be easyer.

aswell where do i go about finding a cable to connect pda to 68hc11 or do i have to make one (and in this case how)

also if you dont mind an example of you c code would be realy helpfull. if you dont mind of course

thanks

Reply to
maintteck

You can find it at digikey

formatting link
under:

z8f64200100kit

Digikey sells it for $39.99. The kit comes with everything you need, including a power supply.

Here's the Zilog website for the Z8 Encore:

formatting link
Here's the Zilog site for the Z8 Encore development kit:

formatting link
Cheers, Ed L

Reply to
Ed LeBouthillier

That should be good enough for just about any project.

Not Visual Basic, but some kind of basic. There's a basic called Basic11, availabe here:

formatting link
If you google "68HC11 Basic11" then you'll find all sorts of stuff on it.

You should just be able to use a serial port. Most PDA's have serial port adapters; it'll depend on your PDA. You may have to buy one. What kind of PDA do you have?

I checked and it seems I was wrong. My 68HC11 code was written in assembly. My PIC code was in C. Here is the PIC code because it is probably the most modifiable and adaptable. Of course, this code won't run on the 68HC11 directly, but with modifications to the hardware-specific routines, you could make it run on the HC11. If you want the HC11 assembly code for something similiar, let me know.

/* ============================================================== */ /* E-Bot V 1.0 */ /* */ /* Copyright 1999 Arthur Ed LeBouthillier snipped-for-privacy@earthlink.net */ /* Available for unrestricted, non-commercial use. */ /* ============================================================== */

#include #include #include

#use Delay(Clock=20000000) #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7) #use fixed_io(a_outputs=PIN_A3) #fuses HS,NOWDT,NOPROTECT, NOPUT, NOBROWNOUT

#define BUFSIZE 8 #define LCAL 66 #define RCAL 57 #define LIPT 0.132 /* 133 Left Inches per tick */ #define RIPT 0.106 /* 107 Right Inches per tick */

/* Constants */ const char ArgError[23] = "Error - Bad Argument\r\n";

/* Temporary Variables */ signed long Long1;

/* RS232 Input related Variables */ char c; char buffer[BUFSIZE]; int buffercnt=0; int bufferptr=0;

/* Time Related Variables */ int T1=0; /* PWM Timer */ long Cnt; long heart=0;

/* Command Interpreter Variables */ int CurrentCmd='*'; signed long CurrentArg=0; float WorkingArg=0.0; short CmdChange=TRUE; int PArg=0;

/* Motor Control Variables */ int MaxV=40; int CmdV=0; int Speed=0; int PWMCntr=0; int LftCnt=10; int RgtCnt=10; short thisLeft; short thisRight; short lastLeft; short lastRight;

int iL_PWM=255; /* Input Left PWM */ int iR_PWM=255; /* Input Right PWM */ int oL_PWM=100; /* Output Left PWM */ int oR_PWM=100; /* Output Right PWM */ int LCntr=100; /* Left Servo Center Position */ int RCntr=100; /* Right Servo Center Position */ signed long AccumErr=0; /* Accumulated Error */ signed int A_SL=0; /* Actual Speed Left in IPS */ signed int A_SR=0; /* Actual Speed Right in IPS */ float deltaB; /* Change in bearing */ int LTicks; /* Left Ticks in one cycle */ int RTicks; /* Right Ticks in one cycle */

int PollFlg=FALSE; int PollCnt=0; /* Counter for 200 msec counter */ int TLA=0; int TLB=0; int TLC=0; int TLD=0; int TRA=0; int TRB=0; int TRC=0; int TRD=0;

/* Robot Status Variables */ int Baseline = 58; float theX=0; /* X Position from origin in inches */ float theY=0; /* Y Position from origin in inches */ float theB=0; /* Bearing in radians */ short Bump1=0; short Bump2=0; short fHeart=FALSE;

/* Function Prototypes */ short GetInteger(void); void DoComLine(void); void DoMotion(void); void DoPosition(void); int addlimited(int n1, signed long n2); float sin(float b); float cos(float b); void song1(void); void song2(void); void sound(long duration, long frequency); void blink(void);

/* ------------------------------------------------------------- */ /* MAIN ROUTINE */ /* ------------------------------------------------------------- */

void main() {

/* Setup Timer1 for 50Hz Interrupt */ setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); set_timer1(64910); enable_interrupts(INT_TIMER1); enable_interrupts(GLOBAL);

/* Startup Sound */ song1();

if(input(PIN_A0)) { CurrentCmd='W'; }

/* Main Loop */ while(TRUE) {

/* Process Command Line */ DoComLine(); /* Do Motor Speed Control */ if(PollFlg) { DoMotion(); DoPosition();

PollFlg=FALSE; }

if(heart > 1000) { if(fHeart) { fHeart = FALSE; output_low(PIN_A3); } else { fHeart = TRUE; output_high(PIN_A3); } heart = 0; } } }

/*

-------------------------------------------------------------------------

*/ /* DoComLine */ /*

-------------------------------------------------------------------------

*/

void DoComLine() { float TFloat; int UInt1; int UInt2;

/* Process Commandline */ if(kbhit()) { /* Get Character and echo it */ c = getc(); putc(c);

if(c == 0x0D) { printf("\r\n"); /* Parse commandline */ bufferptr = 0; switch(buffer[bufferptr++]) { case 'B': /* Set Baseline Command */ if(GetInteger()) { if( Long1 > 0 ) { Baseline = Long1; } else {

printf(ArgError); }

} else { printf(ArgError); } break; case 'C': /* Set Servo Center Command

*/ if(GetInteger()) { if(( Long1 < 201 ) && (Long1 > -201)) { if(Long1 < 0) { LCntr = -Long1; } else { RCntr = Long1; } } else {

printf(ArgError); } } else { printf(ArgError); } break; case 'D': /* Drive Command */ if(GetInteger()) { if(( Long1 > -101) && (Long1 < 101)) { CurrentCmd = 'D'; oL_PWM = LCntr

  • (Long1 + PArg)/2; oR_PWM = LCntr
  • (-Long1 + PArg)/2; } else {

printf(ArgError); }

} else { printf(ArgError); } break; case 'F': /* Forward Command */ if(GetInteger()) { if( Long1 > 0 ) { CurrentCmd = 'F'; CurrentArg = Long1; CmdChange = TRUE; } else {

printf(ArgError); }

} else { printf(ArgError); } break; case 'L': /* Left Command */ if(GetInteger()) { if( Long1 > 0 ) { CurrentCmd = 'L'; CurrentArg = Long1; CmdChange = TRUE; } else {

printf(ArgError); }

} else { printf(ArgError); } break; case 'P': /* Drive Command */ if(GetInteger()) { if(( Long1 > -101) && (Long1 < 101)) { PArg = Long1; } else {

printf(ArgError); }

} else { printf(ArgError); } break; case 'Q': /* Query Command */ switch(buffer[bufferptr++]) { case 'B':

printf("Bumper=%d,%d\r\n",Bump1,Bump2); break; case 'C':

printf("QC=%c\r\n",CurrentCmd); break; case 'D': TFloat = theB*180.0/3.14159;

printf("Bearing=%6.1f\r\n",TFloat); break; case 'L':

printf("Loc=(%4.1f,",theX);

printf("%4.1f)\r\n", theY); break; case 'M': printf("L=%d R=%d\r\n",A_SL,A_SR); break; case 'S':

printf("Speed=%d\r\n", Speed); break; case 'V': printf("MaxV = %u\r\n",MaxV); break; default:

printf(ArgError); break; }; break; case 'R': /* Right Command */ if(GetInteger()) { if( Long1 > 0 ) { CurrentCmd = 'R'; CurrentArg = Long1; CmdChange = TRUE; } else {

printf(ArgError); }

} else { printf(ArgError); } break; case 'S': /* Stop Command */ CurrentCmd='*'; CmdChange = TRUE; break; case 'V': /* Velocity Command */ if(GetInteger()) { if(Long1 >= 0) { MaxV = Long1; } else {

printf(ArgError); } } else { printf(ArgError); } break; case 'W': CurrentCmd ='W'; CurrentArg = 0; break; case 'Z': /* Zero Position Command */ theX = 0.0; theY = 0.0; theB = 0.0; break; default: printf("Error - Unknown command: %c\r\n",buffer[--bufferptr]); break; }

/* Prompt and get ready for next command */ printf("BOS>"); buffercnt = 0; } else { if( !isspace(c) && (buffercnt < BUFSIZE )) buffer[buffercnt++]=toupper(c); } } }

/*

-------------------------------------------------------------------------

*/ /* DoMotion */ /*

-------------------------------------------------------------------------

*/

void DoMotion() { signed long LV_Err; /* Left Velocity Error */ signed long RV_Err; /* Right Velocity Error */

/* Compute Current Speed Should be about 2 */ A_SL = (signed int)((LCAL*(long)iL_PWM)/10); if(oL_PWM < LCntr) { A_SL=-A_SL; }

/* To compensate for sensor errors, make about 4 */ A_SR = (signed int)((RCAL*(long)iR_PWM)/10); if(oR_PWM > RCntr) { A_SR=-A_SR; }

AccumErr = AccumErr + (A_SL - A_SR);

LV_Err = (signed long)((signed long)CmdV - (signed long)A_SL - AccumErr/20)/10; RV_Err = (signed long)((signed long)CmdV - (signed long)A_SR + AccumErr/20)/10;

Speed = (signed int)((A_SL + A_SR)/2); /* Do Motion Command Actions */ if(CmdChange) { if(CurrentCmd == '*') { CmdV = 0; } else { CmdV = MaxV; WorkingArg = 0; AccumErr = 0; } CmdChange = FALSE; }

switch(CurrentCmd) { case 'W': switch(CurrentArg) { case 0: /* Forward */ oL_PWM = 140; oR_PWM = 60; blink(); if(Bump1 || Bump2) { blink(); CurrentArg = 1; Cnt=0; } break; case 1: /* Backward */ oL_PWM = 60; oR_PWM = 140; if(Cnt > 1500) { Cnt = 0; CurrentArg = 2; blink(); } break; case 2: /* Turn */ oL_PWM = 140; if(Cnt > 1500) { CurrentArg = 0; blink(); } break; } break; case '*': oL_PWM = LCntr; oR_PWM = RCntr; break; case 'F': oL_PWM = addlimited(oL_PWM , LV_Err); oR_PWM = addlimited(oR_PWM ,-RV_Err);

WorkingArg = WorkingArg + (float)Speed / 20 ; if( WorkingArg > (float)CurrentArg ) { CurrentCmd = '*'; CmdChange = TRUE; } break; case 'L': oL_PWM = LCntr-25; oR_PWM = RCntr-25;

WorkingArg = WorkingArg - DeltaB*57.29; if((WorkingArg - deltaB*57.29) >

(float)CurrentArg) { CurrentCmd = '*'; CmdChange = TRUE; } break;

case 'R': oL_PWM = LCntr+25; oR_PWM = RCntr+25;

WorkingArg = WorkingArg + DeltaB*57.29; if((WorkingArg + deltaB*57.29) >

(float)CurrentArg) { CurrentCmd = '*'; CmdChange = TRUE; } break; } deltaB=0; }

/*

-------------------------------------------------------------------------

*/ /* DoPosition */ /*

-------------------------------------------------------------------------

*/

void DoPosition() { float lft_dst; float rgt_dst; float dst;

/* Figure out distance traveled */ lft_dst = (float)LTicks * LIPT; rgt_dst = (float)RTicks * RIPT; LTicks=0; RTicks=0; if(oL_PWM < LCntr) { lft_dst=-lft_dst; } if(oR_PWM > RCntr) { rgt_dst=-rgt_dst; }

dst = (lft_dst + rgt_dst) / 2.0;

deltaB = 10.0 * (lft_dst - rgt_dst)/(float)Baseline; theB = theB + deltaB; while(theB > 6.28318) { theB = theB - 6.28318; } while(theB < -6.28318) { theB = theB + 6.28318; }

theX = theX + dst * sin(theB); theY = theY + dst * cos(theB); }

/*

-------------------------------------------------------------------------

*/ /* GETINTEGER */ /* Action: */ /* Reads digits from buffer and combines them into an integer */ /* Returns: */ /* False (0) if failure in reading integer */ /* True (1) if successful */ /* Uses: */ /* Long1 to return the integer */ /* Int2 to control loop */ /* Long2 to calculate value */ /*

-------------------------------------------------------------------------

*/

short GetInteger() { long Long2; if(buffer[bufferptr] == '-') { bufferptr++; Long1 = -1; } else { Long1 = 1; } if(isdigit(buffer[bufferptr])) { Long2 = 0; while(bufferptr < buffercnt) { if(isdigit(buffer[bufferptr])) { Long2 = Long2 * 10 + (buffer[bufferptr++]-'0'); if(Long2 > 32767) { return FALSE; } } else { Long1 = Long1*Long2; return TRUE; } } Long1 = Long1*Long2; return TRUE; } else { return FALSE; } }

/*

-------------------------------------------------------------------------

*/ /* ADDLIMITED */ /*

-------------------------------------------------------------------------

*/

int addlimited(int n1, signed long n2) { signed long t;

t =(signed long)n1 + n2;

if(t > 200) { return 200; } else { if( t < 0) { return 0; } else { return (int)t; } } }

/*

-------------------------------------------------------------------------

*/ /* COS */ /* Calculate cosine as the sine of angle plus ninety degrees */ /*

-------------------------------------------------------------------------

*/

float cos(float b) { /* Cos(x) = Sin(x-90 degrees) */ return sin(b + 1.57079); }

/*

-------------------------------------------------------------------------

*/ /* SIN */ /* Calculate Sine using Taylor series */ /*

-------------------------------------------------------------------------

*/

float sin(float b) { float x2; float x3;

/* Normalize the value between -2*Pi to 2*Pi */ while(b > 6.28318) b = b - 6.28318; while(b < -6.28318) b = b + 6.28318;

/* Determine which Quadrant */ if( b >= 4.71238) { b = b - 6.28318; } else { if(b>1.57079) { b = 3.14159 - b; } else { if(b 17) { if(T1 == 18) { output_high(PIN_C1); output_high(PIN_C2); T1++; } else { /* Supports 0 - 200 range */ for(PWMCntr=0;PWMCntr= oL_PWM) { output_low(PIN_C1); } if(PWMCntr >= oR_PWM) { output_low(PIN_C2); } } T1 = 0; didPWM = TRUE; } } else { T1++; } } while( didPWM );

/* Reset clock for proper cycle time */ set_timer1(64910); }

Reply to
Ed LeBouthillier

this is a great help thanks alot.

i curently have access to a hp 2210. but i was thinking of buying my own(any sujestions)

thanks

Reply to
maintteck

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.