|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Strange Problem, varible not subtracting?
Quote:
Here's what's going on. In your "right_velocity" function the variables are all implicitly declared as auto storage class. long enc_Right_Old_Count = 0; What this means is that the variables are allocated as the function is entered and deleted when it exits. This is the default in C to save space - temporary variables in one function can use the space of variables in another function. And in your case you initialize them to 0, so that subtraction of 100-enc_Right_Old_Count will always be 100 since enc_Right_Old_Count is initialized to zero each time the function is entered. Fortunately the fix is easy - you need to make "enc_Right_Old_Count" not get reinitialized each time. You can do this by declaring the variable as a global in the main function. That way it will only be initialized once when the program starts and not every time the function is declared. To do this, go to the main function, and double click on the "Globals" block and add it there. Be sure to remove it from the right_velocity funtion otherwise the local declaration will override the global for that function and you'll still get the same results. There might be better ways of doing this without global variables if you were hand coding in C, but this will solve the problem easily in EasyC. Hope this helps. |
|
#2
|
||||
|
||||
|
Re: Strange Problem, varible not subtracting?
Quote:
Thanks again guys. I dunno how we got through last year. We must have used all globals and didn't know it. I don't remember this "rule" when programming in C. But now I will never forget and neither will my programmers. BTY, it works like a champ now using globals. Looks too messy to try and do with an array in EasyC, or even doing your own structures...It doesn't look like EasyC support structures, but I did see something in the help on Arrays, we need to read up on that... Again, thanks a bunch. |
|
#3
|
||||
|
||||
|
Re: Strange Problem, varible not subtracting?
Arrays work fine in EasyC. The problem is the complier limits the program to 250 "char" slots total in the program. Int is limited to 120.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need a realistic Statics Problem | sanddrag | Technical Discussion | 10 | 05-12-2005 15:07 |
| Strange system problem | Bill Becker | Control System | 16 | 12-04-2005 17:19 |
| Strange Multi-Turn Potentiometer Problem | Yellow Eyes | Electrical | 10 | 24-02-2005 13:53 |
| Strange Encoder Problem | AIBob | Electrical | 3 | 20-02-2005 22:20 |
| Strange Auto Problem | NotQuiteFree | Programming | 6 | 20-02-2005 17:12 |