Author Topic: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)  (Read 60809 times)

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #75 on: September 11, 2010, 05:18:28 AM »
There's no point writing a project in assembler, that's for masochists. (and I've spend decades writing assembler for almost every known processor going)

Write your project in C. Then if it turns out to be too slow optimise it - usually rethinking your method is plenty, failing that have a look at the assembler the C compiler is kicking out and rewrite the slow parts then link them back (as assembler) into your C project (or inline using the asm keywords). Finally, PIC's are cheap! So just use a faster one!

PIC16's aren't particularly good targets for C compilers so you can generally optimise code for them quite well, 18's are much better targets and by the time you get to the 32's you'd struggle to beat a good C compilers optimisations anyway so would be better off optimising by changing the method.

Where the Mikro stuff scores over things like the lite version of the compiler that comes with MPLAB is the fairly large set of libraries. Need an LCD? Just make the library call, GLCD? Ditto. They provide libraries and example code for everything from pressing a button, through USB all the way to having a wireless network and serving web pages.
To be fair to use these libraries you'll probably run out of space on the free version and will need to buy the full version.
The downside is it's not the best compiler when it comes to producing optimised code, but as I mentioned above there are ways...
« Last Edit: September 11, 2010, 05:19:59 AM by kwackers »

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #76 on: September 11, 2010, 06:46:29 AM »


Write your project in C.



Hi Kwackers

I don't know C, so it's a bit difficult to write it in C ...

I have never yet found any 'tutorial' or whatever that actually assumes you know nothing about it.

One has the usual 'flash a LED' stuff, gives some example code, but does not explain all of the damn symbols / directives etc.

Some can be inferred, others I've not a clue ...  :bang:

Void ??

Braces ??

// appears to be comment ?

Gave up  :(

Apologies to Chris for hi-jacking his thread  ..

Dave BC



« Last Edit: September 11, 2010, 06:48:06 AM by Bluechip »
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #77 on: September 11, 2010, 08:00:16 AM »
If you really want to give it a go send me a PM with your questions and I'll answer them.

But some simple things to help:-

your program starts in the function 'main' so:

void main()

this means you have a function that returns no result (hence the void)

You could return an integer - eg

int fred() 

would be a function called fred that returns an integer (note that main never returns in a PIC so there's no point in it returning anything).

the braces simply collect code together so:

void main()
{
    // you're right this is a comment - until the next line

   // everything between the braces is part of main

   {
      // you can open as many braces as you like - it can help to keep bits together
      // but remember the closing ones
      // and indenting them makes the code look nice....
   }
}


Most directives have a '#' in front of them
the most common one is a string substitution, e.g.
#define A_VAR 23

whenever A_VAR appears then 23 is substituted, handy for defining registers and stuff you might want to change later.

Another is the #include directive, this simply takes the filename after it and inserts it into the file (as though you'd cut and paste the whole thing in)
It's most common use is for header files - usually a file full of #defines that are appropriate for the PIC you're using.

Hope that's of some help.

p.s Chris doesn't mind - I get the same questions off him all the time    :)

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #78 on: September 11, 2010, 08:07:19 AM »
Bluechip - your not hijacking my thread...all good discussion is worth while! Kwackers taught me what I know ... he knows what he is talking about for sure!!

Download mikroC from the link I sent, it is the top download - MikroC compiler.

Kwacks is right with regards to the library - it is bloody fanstastic! Take me for example, a dumb arse when it comes to PICs: So OK, I can write a few lines of "if, else, while"...bla but I wouldn`t have a clue how to get the LCD to run. Well you just call on the LCD library, look at the example and change it suit your needs. If you scout about on the MikroC website there is a download containing examples for the 16F887 and if you open these up with MikroC you can pretty much see how things are working. So like you said there is an LCD example, a flashing LED, GLCD, TMR1, TRM0 example etc. Loads of them, they are really useful.

With regards to learning,... don`t give up it really is fairly easy. I`m sure Kwackers will quickly pick me up if I start spouting rubish but here is a simple code:

// <<-- these are comments so I`ll comment through it

void main()      // this is where the programme starts
{

// This is the PIC setup specifically for the 16F887

  ANSEL  = 0;            // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;          // Disable comparators
  C2ON_bit = 0;

  TRISA.b0 = 0x00;          // Bit 0 on PORTA - TRIS sets pins as output   TRIS 0XFF would be input
  PORTA.b0 = 0x00;          // initiates it at 0
  TRISA.b1 = 0xFF;          // Bit 1 on PORTA is an INPUT - lets say a button
  PORTA.b1 = 0x00;          // initiates it at 0
 
  while (1)                 // while (Statement) is true, it does everything between the braces -
                           //  1 is always true so this is an endless loop.
  {
     if (PORTA.b1)           // if we press the button
     {                      // do everything between these brackets
       PORTA = 0xFF;        // Turn ON LEDs on PORTA
       Delay_ms(1000);      // 1 second delay
       PORTA.b0 = 0x00;        // Turn OFF LEDs on PORTA
     } 
  }
}             

So this code is going to turn on the LED for 1 second each time you press the button.

Nice thing about C is you can make it a little more simple by using define - same code using define:


#define LED1 PORTA.b0   
#define button PORTA.b1

void main()      // this is where the programme starts
{

// This is the PIC setup specifically for the 16F887

  ANSEL  = 0;            // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;          // Disable comparators
  C2ON_bit = 0;

  TRISA.b0 = 0x00;          // Bit 0 on PORTA - TRIS sets pins as output   TRIS 0XFF would be input
  PORTA.b0 = 0x00;          // initiates it at 0
  TRISA.b1 = 0xFF;          // Bit 1 on PORTA is an INPUT - lets say a button
  PORTA.b1 = 0x00;          // initiates it at 0
 
  while (1)                 // while (Statement) is true, it does everything between the braces -
                            //  1 is always true so this is an endless loop.
  {
     if (button)            // if we press the button
     {                      // do everything between these brackets
       LED1 = 0xFF;         // Turn ON LED
       Delay_ms(1000);      // 1 second delay
       LED1 = 0x00;         // Turn OFF LED
     } 
  }
}


Well I hope I`ve not mucked up somewhere but if I can do it, I`m sure you certainly can!
Chris


Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #79 on: September 11, 2010, 08:08:33 AM »
:) we posted at the same time and after that effort didn`t want to delete my post. Ignore mine :D :wave:

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #80 on: September 11, 2010, 09:43:08 AM »
String comparisions (strcmp) are the bits that always get me in C; that, and pointers. Or dereferenced pointers.... I mean, what IS a dereferenced pointer, and why would one desire it?

FWIW, I've been programming in BASIC (in various incarnations - Sinclair SuperBASIC, BBC BASIC, GWBASIC, Visual Basic versions 3-6, VB.NET 1.0 & 1.1) for the last 24 years or so, so it's not like I can't program.... yet I've never ever had to (explicitly) work with a pointer...

Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #81 on: September 11, 2010, 10:39:46 AM »
I'm not sure why you have an issue with string comparisons although they do require pointers.

So quick pointer post.

A pointer is just an address to computer memory. If your machine has 64k of memory then it's a number from 0 to 64k.
Everything you type is in memory.

So in basic if you type:  let A$ = "hello world";
Then the string "hello world" sits in memory somewhere and A$ is probably internally a pointer to it.
(excuse my basic, it's 30 years since I last wrote any).

So say you look through memory and find your string at address 27000, then A$ would be the number 27000.

In C you do the same like this

char A[] = "hello world";

The variable A is a pointer to a type of 'char' (which is 8 bits per character - i.e. a string) by putting the []'s after it we're telling it that it's a pointer to an array of characters.
The string is placed into memory and the variable A is made equal to it's address.

Being a pointer to an array we can index using the brackets, so A[4] would be the letter 'o' (0 to length of string).

Normally you'll see pointers declared with asterisks like this:
char *B = A;
This declares a pointer to types of char named B and makes it equal to A

Therefore B[4] is also equal to 'o'...

Now because the pointer is not the string - it's the address of the string, if we look at it we'll just get the number (in our example we decided it was 27000).

But by using the []'s and looking at the 4th element in the examples above we're 'de-referencing' the pointer (and adding 4). De-referencing is simply the obtaining of the contents of the memory at the location pointed to by the pointer.

Without brackets we can dereference by using a '*' in front.

so *A is the same as A[0],  *(A+4) is A[4] etc etc (brackets used to make sure the addition happens first).

The main reason to dereference is to do pointer arithmetic and then look at what's in the address you calculated. Pointers can point to any type you have or can define (using structures etc).

If this makes sense then back to string compares.

char A[] = "my string";  // this string is 9 characters long - including the zero
char B[] = "my strang";

// pass the two pointers to our strings to strcmp
if (strcmp(A, B) == 0)
{
   // strings are equal
}

strcmp expects two pointers, in this case we created two pointers A & B that already point to some strings in memory.
the C language says strcmp returns zero if the strings are the same, so we use the 'is equals' operator '==' to check if its equal to zero.
« Last Edit: September 11, 2010, 10:41:25 AM by kwackers »

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #82 on: September 11, 2010, 11:12:40 AM »

 ( 1 )  Download mikroC from the link I sent, it is the top download - MikroC compiler.

 ( 2 )  Take me for example, a dumb arse when it comes to PICs:



Hi Chris

( 1 )  Done ...

( 2 ) All very well, but what about we poor souls whose evolution has not reached that exalted stage ?   :scratch:

Thanks for the offer of help Kwackers ... will take you up on that  :thumbup:

I think this would be better in a separate thread ? Wonder how many others are interested in C PIC compilers ?? Gotta be some, world appears to be awash with nutters at the moment ...

So .. having pulled out a 16F877 LED flasher wotsit .. and ...

Q1  How do I change that hideous 'green text on a black background' screen. I can do it on MPASM, ( when I eventually found how to ).

Dave BC
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #83 on: September 11, 2010, 12:44:28 PM »

Q1  How do I change that hideous 'green text on a black background' screen. I can do it on MPASM, ( when I eventually found how to ).



Green text on a black background in MikroC ?? - mine starts up with the theme Whidbey in the Styles Toolbar
: View --> Toolbars --> Styles Toolbar     and select whidbey or another that isn`t green!     

Does that solve the issue? I`m wondering if we are talking about different things as I can`t see any view styles with black and green!

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #84 on: September 11, 2010, 01:59:33 PM »

Hi Chris

I give the Icon a wallop, things happen, and I land up with this ..




If I do the New Project screen, as per the getting started .pdf it does not work for me. I made a folder on C:\ and called a new project Prog_1

Clicked OK after fiiling in the bits it required. Refused to save it.

So, I got no new project screen. Dunno what that looks like. Must be better ... :scratch:

Dave




I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #85 on: September 11, 2010, 02:12:47 PM »
Ewww...yes, that isn`t too pretty. Don`t let it put you off lol

Have you tried :

Tools --> options --> Colours       and then change the colours or the scheme?

I`m running V3.2 MikroC Pro and didn`t change anything from how it originally came, viewing wise.

Chris

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #86 on: September 11, 2010, 02:34:16 PM »

Chris

It appears to be stuffed anyway. Have found how to alter the screen but it's a no go for some reason.

If I try to apply the new screen, it says 'cannot write to etc.etc. some file.

Same as for the new project ....  :scratch:

This is version v8.2 wossat then ?

Officially abandoned for now. De-installed  .. back to ASM   :bang:

Dave
« Last Edit: September 12, 2010, 03:45:50 AM by Bluechip »
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #87 on: September 11, 2010, 06:37:02 PM »
Noooooooooooo !!!!!!

Don`t do that ... try a fresh install because something doesn`t seem right!


Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #88 on: September 12, 2010, 03:37:17 AM »
Chris

Did that. Still no joy ...  :(

If you look at the link you posted, one of the .pdf's to download is one for a licence key.

The text infers, to me anyway, that if you restrict the code to some 2k ( IIRC ) you don't need one.

I think maybe you do.

I had a PCB layout prog. about  2 years or so ago. You still had to e-mail the the varmints for a key to get the 'Freeware' version to ekkle.
Needn't have bothered. Was hoping it was a bit more intuitive than Eagle .. if anything it was worse..   :doh:

Anyway, off to uChip, grabbed C18, kicked it into shape, pinched a bit code off the web, compiled, stuffed into a 'F819. And off it went  :D

QED.

I might have another go at mikroC in a bit, when it's too gruesome to be outside.

Dave BC



« Last Edit: September 12, 2010, 03:43:54 AM by Bluechip »
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #89 on: September 12, 2010, 05:13:52 AM »
Yes, your right about the 2k code limit BUT the software is identical, you just add a licence key and it removes the limit. Well I`m sorry it didn`t work for you, I`m still not entirely sure why.
Chris

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #90 on: September 12, 2010, 05:29:05 AM »
Yes, your right about the 2k code limit BUT the software is identical, you just add a licence key and it removes the limit. Well I`m sorry it didn`t work for you, I`m still not entirely sure why.
Chris

Not sure it is identical. I come up with version 8.2, not the same as yours ..

No matter, the uChip C18 works fine, or so it seems.
So, I'll go with that.

Not sure whether C18 has the 'macro' gizmos yours has, but I don't have any need for them anyway at this time ..

Onward and Upward ... and back to getting about 2 tons of tomatos off. Bugger. Why do they all ripen at once? Most irresponsible of 'em.

Dave BC
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline DMIOM

  • Hero Member
  • *****
  • Posts: 676
  • Country: gb
  • Isle of Man
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #91 on: September 12, 2010, 06:08:06 AM »
...... C compiler. Which did you use ?. ................

Dave (BC)

FWIW I've had to use a variety of C compilers - I use C and C++ for PCs, and Paradigm C++ for embedded x86 (TERN) boards. When we started using PICs (app 2004) I bought the IDE from Forest Electronics (Fored) as, at that time, it seemed to offer the best value combination for dipping our toes into the PIC world.

The Fored "Wiz-C" system (IIRC, originally branded "PIC-C" / "Pixie" but changed possibly due to copyright issues) has an IDE with an ANSI compiler, a text editor (albeit with some quirky keystrokes), a graphical building blocks editor where you drag & drop elements (which I don't use), in-circuit debugging, and, most importantly for us, a simulator.  Whilst there is no native version control system, I use the same Subversion/Tortoise which I use across other development toolsets as well.

The Fored system has done OK for us, once I got used to it; the code it produces is good, tight and reliable; and we have developed a number of systems which both I and my clients are happy with.

Fored do provide updates and bug fixes (although the Yahoo group can be a quicker resource); but the biggest problem for Fored, as a small development outfit, seems to be keeping up with the perenially evolving PIC family (both in terms of processor definitions and also adding new support libraries) - this may not be an issue in a hobby environment but can be in a commercial one.

Was it the right thing to buy in 2004? yes, even in hindsight, I still think so.

Would I buy it again now if I was starting over again with relatively little PIC experience? quite possibly.

Would I buy Fored now for serious, open-ended commercial development? knowing what I do now, almost certainly not.

Am I going to stick with Fored? .... that's a harder question.  We have a certain investment in Fored, something in capital terms but far more in terms of time and developed code.  However, since starting with Fored, we have also built up a significant Proteus ISIS/ARES system.  We already use the Proteus mixed-signal simulation - but Proteus also have MPLAB integration and a PIC simulator.  If, for example, we move to using dsPIC (which is not supported by Fored) we will have to move to a new IDE and compiler, and in fact last winter I started a low-priority project to assess the implications of migrating to either Microchip's own, or HiTech C compiler.

Dave (IOM)

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #92 on: September 12, 2010, 08:41:19 AM »
Hi Dave (IOM)

That looks interesting. £50 is not a killer is it, if you need the full Monty? Good link  :thumbup:

Having got C18 up and running, I'll stick with that for now. Even when the Optimizer doins times out, it's very likely much more than I'll need.

IOM ? Is that Okells still going? Very effective at erasing brain cells IIRC  :lol:

Dave BC



 

I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline z3t4

  • Jr. Member
  • **
  • Posts: 26
  • Country: 00
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #93 on: September 22, 2010, 11:51:58 AM »
I have never yet found any 'tutorial' or whatever that actually assumes you know nothing about it.
Dave BC


Hi Dave

Speaking as another who's interested in messing with PICs but (in my case) almost entirely devoid of any skill or knowledge, I'm finding the Gooligum tutorials really helpful. Apols if you've seen these already.

John

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: X2 X-axis Stepper motor Power Feed - (possible CNC conversion?)
« Reply #94 on: September 22, 2010, 01:12:43 PM »
Hi John

Have seen that one. Some useful bits on it. I'm on MPLAB C18 at the moment, all I could get to download and perform.
Quite a lot of tutorial sites seem to use Hi-Tech C, CCS,  or some other compiler. Never too sure whether code works on C18 or not. Usually yes, but there are exceptions it seems ...

Not done too much lately, waiting for the weather to close in .. not long to Crimbo now  :D  :D ..

Pratting about with uChips seems more appropriate when it's too miserable to be out.  ::)

Dave BC

I have a few modest talents. Knowing what I'm doing isn't one of them.