<h1>THE FORUM HAS MOVED,  VISIT US AT OUR NEW SITE www.picbasic.org. Access to this Archive is restricted. Visit the NEW site at www.picbasic.org.  Unless you use the url http://www.picbasic.org you will not gain access to the support forum, wiki and knowledge base. Visit WWW.PICBASIC.ORG  Do not try to log in or register here, use your keyboard and enter the url http://www.picbasic.org directly into your browser. </h1>  

Go Back  

THE FORUM HAS MOVED, VISIT US AT OUR NEW SITE www.picbasic.org. Access to this Archive is restricted. Visit the NEW site at www.picbasic.org. Unless you use the url http://www.picbasic.org you will not gain access to the support forum, wiki and knowledge base. Visit WWW.PICBASIC.ORG Do not try to log in or register here, use your keyboard and enter the url http://www.picbasic.org directly into your browser.

> Proton Development Suite > Proton Plus Compiler v3

Proton Plus Compiler v3 Coding problems and general discussion related to the Development Suite

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 8th February 2010, 04:51   #1
DaOne
Licensed User
 
Join Date: May 2009
Location: Oregon
Posts: 82
DaOne is on a distinguished road
Send a message via AIM to DaOne
Lightbulb Math...

Need some quick help with a math issue. I haven't had to do this in a long long time and for some reason I cant wrap my brain around this...

I have an input of 1 through 100 steps.

I need it to become 1000 through 2000 steps matching the inputs value.

Anyone wanna help my headache?
DaOne is offline   Reply With Quote
Old 8th February 2010, 05:27   #2
wastrix
Licensed User
 
Join Date: May 2008
Location: Sydney, Australia
Posts: 1,453
wastrix is on a distinguished road
Default

Look at three things:
-What is the min. input?
-What is the input range?
-What is the output range?
-What is the offset?

I notice you specify 1-100, rather than 0-100. I will assume that was intended.

Min input: 1
Input range: 99
Output range: 1000
Offset: 1000

Formula is therefore:
out=(in-1)*(1000/99)+1000

Examples:
In=100, Out=2000
In=1, Out=1000
In=50.5, Out=1500 (Remember 50.5 is between 1 and 100, not 50)
wastrix is offline   Reply With Quote
Old 8th February 2010, 05:34   #3
DaOne
Licensed User
 
Join Date: May 2009
Location: Oregon
Posts: 82
DaOne is on a distinguished road
Send a message via AIM to DaOne
Default

Thanks wastrix! yes it was intended to be 1-100. if it was a 0 -100 would this be the change?

out=in*(1000/100)+1000

Thanks again.
DaOne is offline   Reply With Quote
Old 8th February 2010, 05:43   #4
wastrix
Licensed User
 
Join Date: May 2008
Location: Sydney, Australia
Posts: 1,453
wastrix is on a distinguished road
Default

That's correct.
wastrix is offline   Reply With Quote
Old 8th February 2010, 09:49   #5
bill9399
Licensed User
 
bill9399's Avatar
 
Join Date: Aug 2004
Location: Central Scotland
Posts: 1,599
bill9399 is on a distinguished road
Default

Quote:
Originally Posted by wastrix View Post
That's correct.
Or maybe not.

By my calculation

1-100 inclusive is a range of 100 (0 is your reference point)

Always confusing when you work with arrays and such which start with element x(0).

Try counting on your fingers. If you get stuck, use your toes as well.

Last edited by bill9399; 8th February 2010 at 09:53.
bill9399 is offline   Reply With Quote
Old 8th February 2010, 10:15   #6
fanie
Licensed User
 
fanie's Avatar
 
Join Date: Oct 2005
Location: Crime riddled ZA
Posts: 7,495
fanie is on a distinguished road
Default

Don't do the whole formula in one

out=in*(1000/100)+1000


Break it into it's individual steps, it's faster and you use less code.
fanie is offline   Reply With Quote
Old 8th February 2010, 10:30   #7
DaOne
Licensed User
 
Join Date: May 2009
Location: Oregon
Posts: 82
DaOne is on a distinguished road
Send a message via AIM to DaOne
Default

One more issue I keep banging my head with is interupts. I need to make one thats uses TMR1? to keep a contant 50 hertz pulse (servo) while allowing the main code to run. my main code is...

Code:
Device 16F88
Xtal 20

@CONFIG_REQ
@__CONFIG _CONFIG1, CP_OFF & CCP1_RB0 & DEBUG_OFF & WRT_PROTECT_OFF & CPD_OFF & LVP_OFF & BODEN_OFF & MCLR_OFF & PWRTE_ON & WDT_OFF & HS_OSC 
@__CONFIG _CONFIG2, IESO_ON & FCMEN_ON

All_Digital = TRUE
CMCON=7

TRISA = %00000001
TRISB = %00000000

Symbol Pin = PORTA.1		' Alias servo out pin
Symbol LED1 = PORTB.0
Symbol LED2 = PORTB.1
Symbol LED3 = PORTB.2
Symbol LED4 = PORTB.3
Symbol LED5 = PORTB.4
Symbol LED6 = PORTB.5
Symbol LED7 = PORTB.6
Symbol LED8 = PORTB.7
Symbol LED9 = PORTA.2
Symbol LED10 = PORTA.3
PORTA.1 = 0
PORTA.4 = 0
Dim p_one As Word
Dim p_two As Word
Dim duty As Dword
Dim out As Word
Dim Calc1 As Word
Dim Calc2 As Word

out = 1000
'main program loop here

main:
p_one = 0 ' reset counter values
p_two = 0

p_one = PulsIn PORTA.0, High
DelayMS 10
p_two = PulsIn PORTA.0, Low

duty = (p_one * 100) 
duty = duty / (p_one + p_two)


Calc1= (1000/99)+1000
Calc2= duty-1
out= Calc2 * Calc1


'****** This needs to be updates at 50 hertz by interupt****
Servo Pin , out
'***********************************************

If duty >= 1 Then LED1 = 1 : Else : LED1 = 0
If duty >= 10 Then LED2 = 1 : Else : LED2 = 0
If duty >= 20 Then LED3 = 1 : Else : LED3 = 0 
If duty >= 30 Then LED4 = 1 : Else : LED4 = 0 
If duty >= 40 Then LED5 = 1 : Else : LED5 = 0 
If duty >= 50 Then LED6 = 1 : Else : LED6 = 0 
If duty >= 60 Then LED7 = 1 : Else : LED7 = 0 
If duty >= 70 Then LED8 = 1 : Else : LED8 = 0 
If duty >= 80 Then LED9 = 1 : Else : LED9 = 0 
If duty >= 99 Then LED10 = 1 : Else : LED10 = 0 
      

GoTo main

End
I cant keep the servo output timed correctly without an interupt and I cant for the life of me figure out how to do it.
DaOne is offline   Reply With Quote
Old 8th February 2010, 10:39   #8
wastrix
Licensed User
 
Join Date: May 2008
Location: Sydney, Australia
Posts: 1,453
wastrix is on a distinguished road
Default

@Fanie: If you'd be doing the whole thing in PDS anyway, that's debatable.

@Bill: Maybe, but in statistics range is defined as xMax - xMin, not inclusive.

@DaOne: You should probably start a new thread for this.
wastrix is offline   Reply With Quote
Old 8th February 2010, 10:43   #9
fanie
Licensed User
 
fanie's Avatar
 
Join Date: Oct 2005
Location: Crime riddled ZA
Posts: 7,495
fanie is on a distinguished road
Default

Easy if you use a PWM pic and a 4017 devide by 10.

If you run the PWM at 500Hz / 10 (4017) you have 50HZ. This is the easiest and most convenient way.
It will free the pic up to do other things while the PWM is maintained in the backround.

You can do it using interrupts if the 25c for the 4017 is too expensive
fanie is offline   Reply With Quote
Old 8th February 2010, 10:44   #10
DaOne
Licensed User
 
Join Date: May 2009
Location: Oregon
Posts: 82
DaOne is on a distinguished road
Send a message via AIM to DaOne
Default

Quote:
Originally Posted by wastrix;92172.@DaOne:
You should probably start a new thread for this.

Will do... patiently waiting for your answer

Last edited by DaOne; 8th February 2010 at 10:46.
DaOne is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scaling Math Confusion thetrueman Proton Plus Compiler v3 6 27th September 2009 17:55
External I2C EEPROM table or float point math? pinko Proton Plus Compiler v3 0 24th July 2009 16:03
Help with MATH needed.. captainslarty The Lounge 85 21st February 2009 12:53
Interrupts and math spyder0069 Proton Plus v2.1.5.3 General Discussion 8 18th December 2004 08:31
Floating point math? 32 bit Math? AlienRelics Wish List / Product Feedback 0 4th July 2002 23:57


All times are GMT +1. The time now is 10:38.



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © Crownhill Associates Limited 2002 - 2009