CNC Dividing Head - PICAXE microcontroller

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

cfellows

Well-Known Member
Project of the Month Winner
Joined
Aug 25, 2007
Messages
3,890
Reaction score
715
After reading about Marv's plunge into the Basic Stamp world, I started doing some extensive research on microcontrollers. I've found a pretty good amount of information and some real good project examples on the PICAXE microcontroller. The most amazing bit is the their free (yes, it's really free) programming editor and simulator. It really works slick. It provides an environent where you can specify which microcontroller your using, then you can write your Basic code, and then run it in simulation mode. It shows the steps through the program and also provides a display of the microchip with the state of it's pins and the contents of the variables. You can click on the input pins to change their state and watch how your program handles these changes. This is a great way to get your feet wet with microcontrollers, write actual programs, and see how the microcontroller behaves, all at no cost.

Here is a picture of the editor with my dividing head program and the microcontroller showing pin states and variables:

PicaxeEditor002.png


Extensive documentation and information is available at the PICAXE website which is located in the UK.

http://www.rev-ed.co.uk/picaxe/

I just bought a kit from this fellow http://www.phanderson.com/picaxe/index.html which includes everything you need to get started, including the interface to your PC for download the programs to your microcontroller and the power supply. Cost with shipping was about $30. I haven't received the kit yet and have been doing all my learning with the free editor / simulator.

This is my first foray into the microcontroller world. I was a programmer for many ears, but that was many years ago. I was able to pick this back up pretty quickly and I'm pleased with how fast I was able to get something running.

There are several distributers located in the US and I just bought a kit from a
 
Chuck,

I hope you'll take the time to take a couple of snaps of the evaluation kit when you get it and then, after using it a while, write up your impression of it. I'm sure that I'm not the only one who would like to hear a hands-on evaluation from a trusted source.
 
This microcontroller stuff is kind of addicting. I've gotten sidetracked a little bit by another microcontroller system called Arduino. It's an open source microcontroller prototyping platform and there is ton's of stuff on the internet about it. Here's a link to their main website and a picture of the microcontroller board that costs about $30 at a lot of different electronics & Hobbyists websites.

http://www.arduino.cc/

Still waiting for my PICAXE circuit to arrive in the mail, but have been doing lots of playing with the PICAXE programming editor and simulator. Got my dividing head program pretty well debugged and working. This is fun! My old head is spinning with the possibilities.

Chuck
 
Hi Chuck,

This is an interesting topic and I'm glad to see it pop up. I played with some PICBasic and hardware from Micro Engineering Labs, Inc. several years ago. I got sidetracked though and didn't keep working with it.

You probably know this, but Nuts & Volts Magazine runs quite a few aricles on microcontrollers. Joe Pardue writes the Smiley's Workshop series and he is currently writing about the Arduino. www.smileymicros.com

Nuts and Volts also runs a column on the Picaxe.

Please keep us tuned in on your adventures with the micro controllers.

Regards,

Chuck Kuhn

 
Chuck; here is another Pic based project that may be interesting to you. It reads the digital caliper readout and then uses a Pic controller to output the data as an RS-232 stream. So, you can get the input into any PC based application.

This is another great use of Pic and Stamp based systems. Just use them as an interface to a PC and then use the power of the PC for serious applications.

http://www.compendiumarcana.com/caliper/
 
kuhncw said:
Hi Chuck,

This is an interesting topic and I'm glad to see it pop up. I played with some PICBasic and hardware from Micro Engineering Labs, Inc. several years ago. I got sidetracked though and didn't keep working with it.

You probably know this, but Nuts & Volts Magazine runs quite a few aricles on microcontrollers. Joe Pardue writes the Smiley's Workshop series and he is currently writing about the Arduino. www.smileymicros.com

Nuts and Volts also runs a column on the Picaxe.

Please keep us tuned in on your adventures with the micro controllers.

Regards,
Chuck Kuhn

Hey Chuck, funny you should mention Nuts & Volts. I just subscribed to it a couple of months ago and was reading through my first copy last night. That's how I ran across the Arduino stuff. Interesting magazine.

Chuck
 
black85vette said:
Chuck; here is another Pic based project that may be interesting to you. It reads the digital caliper readout and then uses a Pic controller to output the data as an RS-232 stream. So, you can get the input into any PC based application.

This is another great use of Pic and Stamp based systems. Just use them as an interface to a PC and then use the power of the PC for serious applications.

http://www.compendiumarcana.com/caliper/

Yeah, this is another area of interest. I really want a DRO for my milling machine but just can't bring myself to mortgage the house to buy one. Not to mention the grief I would get from the Chief Financial Officer! ::) So, I will be following up on this project as soon as I get a little more comfortable with the microcontroller.

Chuck
 
"Yeah, this is another area of interest. I really want a DRO for my milling machine but just can't bring myself to mortgage the house to buy one. Not to mention the grief I would get from the Chief Financial Officer! Roll Eyes So, I will be following up on this project as soon as I get a little more comfortable with the microcontroller."

Chuck,

Are you aware of the Shumatech DRO?

www.shumatech.com

It is available as a kit that you build yourself, and either buy a pre-programmed microcontroller, or program your own.

I have built one, and find it invaluable. Much cheaper than a ready-built unit, with most of the functionality!

Regards,

Anthony
 
LADmachining said:
Are you aware of the Shumatech DRO?

www.shumatech.com

It is available as a kit that you build yourself, and either buy a pre-programmed microcontroller, or program your own.

I have built one, and find it invaluable. Much cheaper than a ready-built unit, with most of the functionality!

Regards,

Anthony

Hi Anthony,

Yeah, I've seen their units and have thought long and hard about buying one. May wind up doing that since everything I've read about rolling-your-own DRO's isn't very positive. However, part of the adventure is the journey and if I have enough projects lined up, it will keep me motivated to learn about microcontrollers.

Chuck
 
cfellows said:
The most amazing bit is the their free (yes, it's really free) programming editor and simulator.

But you still have to buy the Pics from them or not?

I like the the pic a lot and have made some useful projects but the programming language I use is assembly together with the Mplab from Microchip also free with a ICD2 programmer. It would be nice, sometimes, to program in basic. My main project is a constant pressure controller fo diesel irrigation pumps with automatic engine start and servo speed control and engine monitor/protection with a 18F452, 16x4 line LCD display, 16 key keyboard, stepper motor servo actuator (controlled by a 12f675), analog 250 psi pressure sensor and speed pick-up. The assembly program's listing is 120 A4 pages long.
 
Got my PICAXE development board from PH Anderson in the mail today. Plugged it in and it seemed to do everything as advertised out of the box. Of course, all that amounted to was a flashing red LED and solidly lit green one.

You can see the components in the picture. It has a large solderless bread-board with a PICAXE 18m microcontroller on it. The printed circuit board is a USB serial interface to the PC. Also included is the USB cable. The USB interface provides power to the development board. It also provides a serial link for downloading programs from the PC to the microcontroller and an uplink for displaying debugging data on the PC screen.

PICAXE18MBoard.jpg


The PICAXE microcontrollers come in a variety of sizes, beginning with the 8 pin, 08M and going up to the 40 pin, 40x. Even the largest PICAXE is less than $10. My kit came with the 18m, which, as you might guess, has 18 pins. It has 14, 1 byte registers which also double as 2 byte, word sized registers. All math must be done in these registes. Sound familiar to you assembler programmers? There are also 40 bytes of memory for storing variables, constants, etc. And, finally, there is enough program memory for 255 lines of code. Or maybe it's 255 bytes for your code. My dividing head program consumed about 120 of the 255 available units, whatever they are.


The chip is programmed in a very simple BASIC language. Nothin fancy here, but easy and functional. As far as math goes, positive integers only. No decimals and no negative numbers. Try to go negative and you wind up with a very large positive number, 255 in the case of a byte and 65535 in the case of a word. Testing for < 0 doesn't produce an error but it doesn't work, either!

Chuck
 
Noitoen said:
But you still have to buy the Pics from them or not?

I like the the pic a lot and have made some useful projects but the programming language I use is assembly together with the Mplab from Microchip also free with a ICD2 programmer. It would be nice, sometimes, to program in basic. My main project is a constant pressure controller fo diesel irrigation pumps with automatic engine start and servo speed control and engine monitor/protection with a 18F452, 16x4 line LCD display, 16 key keyboard, stepper motor servo actuator (controlled by a 12f675), analog 250 psi pressure sensor and speed pick-up. The assembly program's listing is 120 A4 pages long.

You can buy the microcontroller chips from them or a number of other places on the internet. Several U.S. based companies sell them. The chips are cheap, all under $10 US and the supporting circuitry is minimal. However, the PICAXE is limited in the size of programs and data they will hold. For larger programs, the Arduino would be better suited. Or Microchip with external memory and supporting cuicuitry. But now you're getting complicated! :)

By the way, the PICAXE's are made with microcontrollers from PIC.

Chuck
 
What I would like to know is, can you use "of the shelf" pics or do Picaxe pics come programmed with some kind of proprietary "firmware or bootloader"? I know where to get "normal" pics.
 
The PICAXE comes with proprietary firmware already loaded. This includes their Basic interpreter and their own bootstrap program.

Chuck
 
Cr@p! Now I've discovered the BasicX. Just like the Basic Stamp but way more powerful and cheaper. I'm so confused...

Chuck
 
I've selected a stepper motor, from my motley collection, that has voltage and current requirements in line with my controller. The stepper is from a telescope tracking system. It's a bipolar stepper, with 48 steps per motor revolution. It's geared at 30 : 1 to the output shaft giving an overall number of 1440 steps per output shaft revolution.

I was thinking that would give me very nice resolution on the output divisions, but now I'm running into some of the restrictions of microcontrollers. First off, calculations are performed using integer math, so no decimals. Second of all, I'm restricted to 16 bit registers so I can only deal with number up to 65536.

Too accommodate rounding issues, I was planning to calculate the rotor position each time like so:

absolute position = division number * 1440 / number of divisions.

Example: If I have specified 49 divisions and I am on position 47, it looks like this:

abs pos = 47 * 1440 = 67680 / 49 = 1381

Oops, my intermediate result of 67680 is larger than 65536... That's a Problem! So, for the moment, I've decided to use 360 steps per rotation and simply multiply the calculated steps by 4. This reduces my resolution but I think it will be OK.

Anyone got any ideas how to fake the math with these little processors?

Chuck

 
Chuck,

I know squat about microcontrollers; but would it be possible to break down your movements into 45 degree increments for the calculations? Then 47 degrees would be 45 in one movement and 2 in the next. That would keep the step count under your limitation. It would likely result in an annoying pause in the movement of the rotary table, not good if you are interested in continuous 4 axis machining, but maybe acceptable for a positioning axis?

Basically thinking out loud.

Kevin
 
cfellows said:
Anyone got any ideas how to fake the math with these little processors? Chuck

Chuck, I have not worked with the PIC family but I have done some things with limited processors. Just a general idea, but sometimes you can set a variable or flag to a value that can be checked and used to branch in your program. Have the program check and when the register is going over 65536 set a flag = 1, yes, true or whatever and then reset the register to 0. From that point on when you do math check the flag to see if the register is its actual value or its value + 65536. Kind of a PITA but you work with what you have.

Likely there is a much more elegant solution from a real programmer, but that is my first thought without knowing the PIC.
 
abs pos = 47 * 1440 = 67680 / 49 = 1381

If you calculate 47*144/49, then multiply by 10 you'll get 1380. That will be off by 1.

47*360/49 = 345; 345*4 = 1380. In this case it's off by 1, but could be off more depending on the factors.

Assume position 20 going to 49, then

20*1440 = 28800/49 = 587 (no overflow)

20*360 = 7200/49 = 146 * 4 = 584 (so less accurate by 3 divisions).

So an algorithm might look like this:

abs_pos = curr_pos * 1440 / num_div;
if (abs_pos < 0)
{
abs_pos = curr_pos *144/num_div;
abs_pos = abs_pos * 10;
}
 
I'm not familiar with your system. But here's some thoughts...

If you write in assembly you can use larger numbers. (I was surprised that you're limited to a 16 bit value). More difficult if you have to do any multiplication or division.

You can use two sets of variables...one to count revolutions and one to count the pulses in a revolution (like seconds, minutes, hours).

As a side note...the fact that integer math is used does not mean fractional math is not possible. Use a virtual decimal point. The more bits behind the virtual decimal point then the more resolution you have. For example, if we use an 8-bit number and let the virtual decimal point be 2 in from the right...then 4.5 would be represented by

00010010
000100.10
000100 is 4
.10 is 1/2

4.75 would be

00010011
000100.11
000100 is 4
.11 is 1/2 + 1/4

Moving the virtual decimal point left by one gets you 1/8
.101 is 1/2 + 1/8

All at the loss of range if you can't use more bytes.
(Basically you've multiplied everything by a number large enough to keep significant digits...then you divide by the number to get the final result).
This 'trick' is commonly used for speed in embedded systems when you need to use fractions but don't want to spend the money for hardware to support floating point.
 
Back
Top