PDA

View Full Version : Automation project need help



microcnc05
- 1st January 2010, 16:41
I'm having trouble with math in picbasic pro. I'll give you an over view of what I'm trying to do. I've been automating a few machines that feed out cardboard and cut it off. The feeding is done by a stepper motor directly connected to a roller. I've been using CNC control software to handle this up till now. I'd like to reduce my cost and have a smaller control.

The roller that the stepper motor is connected to is 1.987” in diameter. So to figure out how much stock is fed out each turn I need the circumference. Which is 1.987 * PI = 6.2423. So with every turn of the stepper motor it feeds out 6.2423 inches of stock.

I have a 2000 step per revolution stepper motor. So then we take the circumference 6.2423 / 2000 which gives us .003121”. This is how much stock is fed out with every step.

This is easy in normal computer programming. But working with pic's is totally new to me.

So far in this project I have a 4X4 keypad working it will store “123A 567B 789C *0#D” in a variable. I also have LCD out put working.

So basically what I need working is for the user to be able to enter the amount of stock they want. Lets say they enter 60.25” inches. With the “*” as the decimal point on the keypad.

So with the above equations all I really need to have in my program is a variable is the (steps per inch = .003121) and then you just take 60.25/.003121 = 19304 Then I would just send out 19304 pulses to a pin on the pic to step the drive.

So my question is how do I work with decimals in 16bit math?

My other question that goes with this is how do I store multiple keys typed in on the keypad so that if the user types in 60.25 I can work with it?

I've attached a picture of the stepper motor (bottom left) attached to the machine with the rollers and cardboard feeding though so you can have a better idea of what I'm doing. Thanks.

Archangel
- 1st January 2010, 18:06
I like it !
Typically you would multiply everything by 1000 for .001 resolution .
Oh, and you're cutting cardboard, forget measuring to .0001 or even .001 especially when you break it into dia/2000 the temp/humidity will kill those resolutions anyway, and seriously just how close does a cardboard piece have to fit? I make parts, mostly for the space/aircraft test industry and I see engineers throw out useless impossible tolerances which serve zero purpose other than make everyone's job harder and swell their ego's. Did a job recently where the engineer told me to bore some holes at the intersection of 2 parts and then take them apart and mill off .002 from 1 surface. Yea right, shimmed it with paper and bored it, on top of that the part it clamped was just a piece of PEX tubing which varied all over the place in diameter.
I guess what I am trying to say is, make Your own job easy.
Or turn that feed roller down to 1.9099 and it will roll out 6.000 .

microcnc05
- 2nd January 2010, 01:03
That's funny. I'm a pattern maker in the arrow space industry. I got laid off early 2009 and started doing side jobs. I started my own company about two months ago and started automating some machines for an air filter company. Your suggestion to turn the roll down to 1.9099 is what I came up with also to make it easier. The problem I had was that they hired me to retro fit the design they already made for that project. In the future they will consult me first then I can make the hardware to fit the software better. thank you for your reply.

Jerson
- 2nd January 2010, 01:57
I am thinking it will boil down to just this much

Steps = Length / 0.003121
OR
Steps = (Length * 1602) / 5

About the question of your numbers with decimal point, PBP has no native floating point support. So, you have to coax your values into a fixed decimal base or maybe use the FP support addon with all its bells and whistles.

The method above is suitable for plain integer math and can be used with PBP below PBPLong version too.

Archangel
- 2nd January 2010, 03:11
That's funny. I'm a pattern maker in the arrow space industry. I got laid off early 2009 and started doing side jobs. I started my own company about two months ago and started automating some machines for an air filter company. Your suggestion to turn the roll down to 1.9099 is what I came up with also to make it easier. The problem I had was that they hired me to retro fit the design they already made for that project. In the future they will consult me first then I can make the hardware to fit the software better. thank you for your reply.

So what kind of tolerance do you have to play with? I am thinking, run down some round numbers and periodically add in a correction, to stay in tolerance. If you keep the numbers less than 65535 then it's pretty easy, if more then you will need to store some in another variable or an array . . . another, (better ?) way is to use an encoder instead of relying on the stepper not to drop steps.

Acetronics2
- 3rd January 2010, 10:25
Hi,

As always ... +1 with Jerson !!!

7369/23 also could be considered ( 3.5 ppm error ... ROFL )

may be we could tell µCNC to have a closer look to the DIV32 function ... that will allow 2^15 as a max. value to be divided ...


Alain

Bill Legge
- 5th January 2010, 03:17
You might consider:

1. Scaling - as others have said so that you work in some basic unit that is acceptable - probably relates to the maximum error you can tollerate in the stock length.

2. consider using a 'maths co-processor' to handle complex calculations and numbers outside the range of your MCU - Ive had a preliminary play about with the MicroMega chip and it's amazingly powerful.

3. Keypad input. This is what I do:

define OSC 20 ' Define Xtal as 20 MHz, use "HS" for programming

X var byte ' Reusable variable
Y var byte ' Reusable variable
Key_Press var byte ' Keypad Read condition of keypad port
Key var byte ' Keypad Key pressed
Accumulate var word ' Keypad Accumulated input number

TRISD = %01110000 ' D0-D3 driven outputs, D4-D6 read inputs

Main:
gosub Keypad
' Use the returned 4 digit number here
goto Main
'----------------------------------------------------------------------------------------------------
Keypad:
for Y = 1 to 4 ' Accumulate four keyboard numbers
Get_Number:
PORTD = %00000001 ' Apply +5 to first row
for x = 0 to 3 ' Read the columns in turn
Key_press = PORTD & %01110000 ' Isolate the three columns
select case key_press
case %00000000 ' No key pressed
Key = 0
case %01000000 ' Righthand column
Key = 3 + 3*x
case %00100000 ' Centre column
Key = 2 + 3*x
case %00010000 ' Lefthand column
Key = 1 + 3*x
end select
if Key <>0 then Key_Done ' got a result so quit
PORTD = PORTD << 1 ' Moves +5 to rows 2,3 and 4
next X
Key_Done:
if Key = 0 then Get_Number ' No key pressed so do it again
IF Key > 9 then Key = 0 ' Treat the * and # keys as zero

Accumulate=Accumulate*10+Key ' Shift the accumulated result up and add last key press
high Heartbeat : pause 150 : Low Heartbeat
pause 300 ' If key is held down then repeat number
next Y
return
'----------------------------------------------------------------------------------------------------
end

And the circuit diagram of the keypad: