Shop OBEX P1 Docs P2 Docs Learn Events
Not able to input decimal value — Parallax Forums

Not able to input decimal value

christineeechristineee Posts: 17
edited 2013-07-09 23:10 in BASIC Stamp
I am trying to key in decimal value for my code but i cant seem to key in as when i click "run", there's an error message that reads:

Untitled.jpg


I tried to put in " n DEC 0.034" at the top the declare variable, it does not help at all. I also read through the syntax and ref manual but there isnt any that tell me what extra coding i should put in.
Please help me!
484 x 254 - 35K

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2013-07-05 04:54
    Like many microcontrollers, the Stamp works with integers.

    To use fractions, you have to use some tricks. For instance, the Multiply High ( **) and Multiply Middle ( */) instructions will often let you do what you want. See the Stamp Syntax manual under the "Help" menu.

    Also, you can often multiply a number like 1.234 by 1000, do the operations you need, then divide the answer by 1000 to get back.

    Cheers,
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2013-07-05 16:47
    What are you trying to accomplish?
    DEBUG CR, "Turn LED 70% onn"
    PWM 13, 190, 0.034
    

    The third parameter should be an integer specifying cycles in units of milliseconds (for the plain BS2). So if you want the PWM to last 34 milliseconds, just use 34.

    For 70% PWM, use 0.7 * 256 = 179 as the second parameter.
  • christineeechristineee Posts: 17
    edited 2013-07-07 17:59
    What are you trying to accomplish?
    DEBUG CR, "Turn LED 70% onn"
    PWM 13, 190, 0.034
    

    The third parameter should be an integer specifying cycles in units of milliseconds (for the plain BS2). So if you want the PWM to last 34 milliseconds, just use 34.

    For 70% PWM, use 0.7 * 256 = 179 as the second parameter.

    I am trying to dim the LED to just 70% of its brightness.
    The value 0.034 is in milliseconds.
    This is my calculation:
    Charge time = 5*R*C
    =5*680*(0.01*10^-6)
    =0.000034s = 0.034mS

    Why are you using 256? Isnt it 254? I am confused.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2013-07-08 09:10
    I don't see why you are using an RC product. Maybe that comes from an RCTIME command somewhere else. It has nothing directly to do with the PWM command. The percent intensity for the PWM command is the second parameter. The second parameter is either 255 (according to the Stamp manual) or 256 (according to some experiments I did a number of years ago). It doesn't matter. The result for the second parameter is either 0.7 * 255 = 178.5 or 0.7 * 256 = 179.2, either of which round off to 179 for PWM. Intensity for your purposes may be a different value. How did you come by the value 190?

    The third parameter is the number of milliseconds you want the PWM to last. The Stamp does not do concurrent PWM, so if you are driving the LED directly, you may want the PWM to last several seconds. PWM can alternatively drive the LED via an analog circuit as described in the Stamp manual.
  • christineeechristineee Posts: 17
    edited 2013-07-09 23:10
    I don't see why you are using an RC product. Maybe that comes from an RCTIME command somewhere else. It has nothing directly to do with the PWM command. The percent intensity for the PWM command is the second parameter. The second parameter is either 255 (according to the Stamp manual) or 256 (according to some experiments I did a number of years ago). It doesn't matter. The result for the second parameter is either 0.7 * 255 = 178.5 or 0.7 * 256 = 179.2, either of which round off to 179 for PWM. Intensity for your purposes may be a different value. How did you come by the value 190?

    The third parameter is the number of milliseconds you want the PWM to last. The Stamp does not do concurrent PWM, so if you are driving the LED directly, you may want the PWM to last several seconds. PWM can alternatively drive the LED via an analog circuit as described in the Stamp manual.

    Ohh i see.. I guess i did some calculation errors.
    Thanks!
Sign In or Register to comment.