Author Topic: expressing a decimal in PBASIC  (Read 5950 times)

0 Members and 1 Guest are viewing this topic.

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
expressing a decimal in PBASIC
« on: March 31, 2007, 09:32:15 AM »
I am trying to control a servo with a BS1 microcontroller but I can't figure out how to express the value 1.5 or any other decimals for that mater dose any one know how to express a decimal in PBASIC.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: expressing a decimal in PBASIC
« Reply #1 on: April 01, 2007, 03:40:20 PM »
whats your code look like so far?

look into 'float', which is a variable type for storing decimal numbers. its been almost a decade since i programmed in PBASIC, but i dont remember ever having a problem with decimals when using them . . . in theory it should just work . . .

Offline Somchaya

  • Robot Overlord
  • ****
  • Posts: 180
  • Helpful? 0
  • You know it's cute!
Re: expressing a decimal in PBASIC
« Reply #2 on: April 01, 2007, 04:47:40 PM »
I've never worked with PBASIC, but one way you could consider would be to use fixed-point math.

For example, you can store numbers like 1.5 and 2.4 as 15 and 24 respectively. This way, you can do
regular math on these "integers", and to get the digits and decimal parts, you can divide by 10 and mod by 10 respectively. Of course, if you needed more precision, you could use larger numbers like 100 or 1000, but you get the idea.

Hope this helps!
Somchaya - Back after a year of misc things
http://whisker.scribblewiki.com

Offline nanob0t

  • Robot Overlord
  • ****
  • Posts: 145
  • Helpful? 0
  • Trust Your Technolust
Re: expressing a decimal in PBASIC
« Reply #3 on: April 01, 2007, 05:17:24 PM »
A 'float' character stores decimals.  I don't know what it looks like in PBASIC though.

If anything, think of it a different way.  1.5  is also 3/2    Sometimes it can be a matter of modifying what you learned.  If you do division, make sure you store it in an appropriate integer.

Hope this helps
« Last Edit: April 01, 2007, 08:47:59 PM by nanob0t »

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
Re: expressing a decimal in PBASIC
« Reply #4 on: April 02, 2007, 08:29:33 AM »
thanks very much for the help that  helped a lot . :D

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
Re: expressing a decimal in PBASIC
« Reply #5 on: April 02, 2007, 10:22:18 AM »
so tell me if I have this right:

if I wont to pause for 1.5 ms I could use this command  PAUSE 2/3 ???

Offline nanob0t

  • Robot Overlord
  • ****
  • Posts: 145
  • Helpful? 0
  • Trust Your Technolust
Re: expressing a decimal in PBASIC
« Reply #6 on: April 02, 2007, 08:01:50 PM »
I have no clue.   Try looking for information on the web first.

If not, give the program a try like that and see if you get any errors, or if the program doesn't like to your wishes.

Maybe, if the programming language supports it, try () to encase the number.

Or perhaps, if you use this number once, and if the programming language supports it, try defining a variable at the beginning to be 3/2 or 1.5.  Then you can just say  PAUSE (Insert Variable Here)

A few ideas that may work.

Offline Somchaya

  • Robot Overlord
  • ****
  • Posts: 180
  • Helpful? 0
  • You know it's cute!
Re: expressing a decimal in PBASIC
« Reply #7 on: April 02, 2007, 10:27:06 PM »
Actually, from what I know, most languages will treat 3 / 2 as an integer division, and return an integer, so 3/2 = 1 in this case.

If you need to do a pause for fractions of a second, but the function like pause only accepts seconds, then it is unlikely that it'll work. Instead, there might be another function that will take in milliseconds or some smaller division.

Again, I'm not familiar with PBASIC, but I'm guessing through my experience with other languages, and playing with QBasic a long time ago (no idea if it's related to PBASIC though).

Another suggestion would be to try google for "pause fraction of second" or something like that.
Somchaya - Back after a year of misc things
http://whisker.scribblewiki.com

Offline JonHylands

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 562
  • Helpful? 3
  • Robot Builder/ Software Developer
Re: expressing a decimal in PBASIC
« Reply #8 on: April 03, 2007, 05:48:53 AM »
so tell me if I have this right:

if I wont to pause for 1.5 ms I could use this command  PAUSE 2/3 ???

Since the units are milliseconds, there is no way to do anything other than whole milliseconds with PAUSE.

If you're trying to control an I/O pin for a specific length of time, you could use PULSOUT. Otherwise, you need to use a better microcontroller that has higher timing resolution.

- Jon

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
Re: expressing a decimal in PBASIC
« Reply #9 on: April 05, 2007, 08:13:57 AM »
thank you for you  help

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: expressing a decimal in PBASIC
« Reply #10 on: April 16, 2007, 11:48:40 AM »
When I do my servos, I dont actually pause in milliseconds. I actually pause in units of computational cycles.

For example, if I know my microcontroller takes 1.5ms to run a while loop 300 times, then I just do a while loop 300 times for my servo  :P

300 is a non-decimal number, too 8)

Offline Somchaya

  • Robot Overlord
  • ****
  • Posts: 180
  • Helpful? 0
  • You know it's cute!
Re: expressing a decimal in PBASIC
« Reply #11 on: April 16, 2007, 12:12:40 PM »
For example, if I know my microcontroller takes 1.5ms to run a while loop 300 times, then I just do a while loop 300 times for my servo  :P

Hmm.. how do you know the microcontroller takes 1.5ms to run the loop 300 times? By calculating the number of clock cycles in the loop and comparing it to the processor speed?
Somchaya - Back after a year of misc things
http://whisker.scribblewiki.com

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: expressing a decimal in PBASIC
« Reply #12 on: April 16, 2007, 12:47:39 PM »
the easiest method is just to use an oscope - send out a high-low pulse from a DO after the while loop is done, and measure the time between pulses.

when the time reaches about 1.5ms, your servo should be centered.

i dont bother calculating or counting anything cause its too dependent on hardware (the timing crystal, voltages, etc.)

Offline Somchaya

  • Robot Overlord
  • ****
  • Posts: 180
  • Helpful? 0
  • You know it's cute!
Re: expressing a decimal in PBASIC
« Reply #13 on: April 16, 2007, 12:58:51 PM »
the easiest method is just to use an oscope - send out a high-low pulse from a DO after the while loop is done, and measure the time between pulses.

when the time reaches about 1.5ms, your servo should be centered.

i dont bother calculating or counting anything cause its too dependent on hardware (the timing crystal, voltages, etc.)

That's really smart, thanks! ;D There's so much more about electronics and stuff about robotics that I need to learn :P
Somchaya - Back after a year of misc things
http://whisker.scribblewiki.com

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
Re: expressing a decimal in PBASIC
« Reply #14 on: April 16, 2007, 01:51:59 PM »
thanks  :D

Offline nanob0t

  • Robot Overlord
  • ****
  • Posts: 145
  • Helpful? 0
  • Trust Your Technolust
Re: expressing a decimal in PBASIC
« Reply #15 on: April 17, 2007, 09:35:16 AM »
I never thought of doing it that way.  I used to do BASIC and everything was in milliseconds and very limited. 

Now I just need an oscilliscope  :(

Offline aaqilkhan

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: expressing a decimal in PBASIC
« Reply #16 on: May 24, 2007, 12:19:51 PM »
I started off with a basic stamp II microcontroller and programmed it in PBASIC. From my experience, PBASIC doesnt like decimal numbers. All numbers must be in integer format. If u really want to work with decimal numbers, try PICmicros. If you still want to play with the stamp, then try the parallax forums. They provide excellent support for their products there.

 


Get Your Ad Here