View previous topic :: View next topic |
Author |
Message |
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Fri Jan 27, 2023 5:57 pm |
|
|
temtronic wrote: | The PIC like every other computer with just one ALU, can only do ONE operation at a time.
It cannot do ANYTHING 'inside' of a delay_ms(xxxx). it literally just decrements a counter (or two) wasting time, until the count is zero.
Again, would have to see main() to understand WHY there's an inline delay. |
I know what you mean but i would have said, maybe this isn't good for the pic to calculate constantly without a delay between every hard operations (I know that my thoughts look stupid but I'm just looking for an answer ^^) i will show you the code tomorrow i don't have it now.
And more, i had a problem on same code last time, i would have used a negative value in a if condition but the compiler says "condition always TRUE" (or false) even if i add parenthesis around the number like this:
Code: |
If (variable <= (-1200))
{
Do things
}
|
I know i already have done that in a previous code but i don't remember if there is a special syntax for negative value in if condition. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Sat Jan 28, 2023 2:45 am |
|
|
obviously 'variable' must be signed. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Sat Jan 28, 2023 7:33 am |
|
|
and...
CCS historically defaults int8 and int16 as unsigned
if memory serves me right... |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Sat Jan 28, 2023 8:04 am |
|
|
temtronic wrote: | and...
CCS historically defaults int8 and int16 as unsigned
if memory serves me right... |
im not sure, but this morning i tried again i declared the variable as a "int" and it magically worked so i m confused...
but if one day i've got this problem again i will think about your advices thank you. |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Sat Jan 28, 2023 8:18 am |
|
|
So, this is my main with the delay that i talked about :
Code: |
void main()
{
Setup_mpu6050();
while(TRUE)
{
Get_Accel_Values();
Get_Accel_Angles();
printf("accel_xangle = %7.0f \n\r", accel_xangle);
printf("accel_yangle = %7.0f \n\r", accel_yangle);
printf("\n\r");
delay_ms(2000);
}
|
do you think that the purpose is only to print every 2 seconds on terminal then? |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Sat Jan 28, 2023 9:42 am |
|
|
Yes, the purpose is exactly that. 2 seconds between two readings of the sensor and prints. It would work even without this delay (if the sensor supports consecutive readings at that speed), only the printouts would come out way faster. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Sat Jan 28, 2023 9:47 am |
|
|
well the MPU6050 is listed as NOT for 'new' designs....so I couldn't get the datasheet from the MANUFACTURER. However considering the chip is I2C, it must be reasonably 'fast' so the only reason for the 2 second delay in main() IS to slow the 'update to display' for us humans to easily read it.
You can reduce it to 1 second, 1/4 second , even less if you want. How short a delay time period depends on what you do with the data in the PC. If just displaying it,using a terminal program, delay_ms(500) would be fine. If using it for some kind of 'real-time' control, delay_ms(1) might be appropriate. |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Sat Jan 28, 2023 10:08 am |
|
|
PrinceNai wrote: | Yes, the purpose is exactly that. 2 seconds between two readings of the sensor and prints. It would work even without this delay (if the sensor supports consecutive readings at that speed), only the printouts would come out way faster. |
Thanks for your answer, i think i will try with 500ms then to be sure that there is no problem, it should be enough for my project. |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Sat Jan 28, 2023 10:14 am |
|
|
temtronic wrote: | well the MPU6050 is listed as NOT for 'new' designs....so I couldn't get the datasheet from the MANUFACTURER. However considering the chip is I2C, it must be reasonably 'fast' so the only reason for the 2 second delay in main() IS to slow the 'update to display' for us humans to easily read it.
You can reduce it to 1 second, 1/4 second , even less if you want. How short a delay time period depends on what you do with the data in the PC. If just displaying it,using a terminal program, delay_ms(500) would be fine. If using it for some kind of 'real-time' control, delay_ms(1) might be appropriate. |
The goal is to drive 4 actuators that support a plank and then make it flat. So i will do some tests with differents delays and see what happen.
But first i will check tonight the code library about the function atan to optimize it. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Sat Jan 28, 2023 10:25 am |
|
|
Please remember that the delay_ms(2000) does NOTHING with respect to getting the raw sensor data or any 'mathematics' the PIC is asked to do.
You'll probably see that the CCS coding for ATAN is already optimized, same as the other 'trig' functions. You can compare their code to some Microchip Application Notes' on the subject.
As we've stated though to get faster and more accurate response, use scaled integers.
BTW using 3 actuators instead of 4 for the 'level a plank' is easier. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Sat Jan 28, 2023 11:09 am |
|
|
Quote: |
BTW using 3 actuators instead of 4 for the 'level a plank' is easier. |
Well, as they showed me at mathematics class decades ago: 3 points define a plane :-) |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Sat Jan 28, 2023 11:12 am |
|
|
That is why a 3 legged bar table never rocks, while a 4 legged always does :-) |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Sat Jan 28, 2023 11:37 am |
|
|
Let's presume the plank doesn't bend. I'd place two sensors aligned on the plank border along x axis, and one on the opposite side, in a triangle formation, all sensors having x and y axis facing the same directions. Here I noticed you actually need only two actuators, one corner can be fixed. Then lift or lower the actuator on x axis so that both sensors there read 0 degrees. You are done with leveling on that axis. Than you lift or lower the actuator on the opposite side of the plank so that y axis reading from that and any other sensor reads 0 deg. You have a leveled plank.
I'm not sure if I explained it good enough, but that is the way we level cylinders in the casino, only instead of actuators we use a technician.
Can of course be done with only one sensor, it's just my one-track thinking you'd need three :-) |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Sat Jan 28, 2023 3:49 pm |
|
|
PrinceNai wrote: | Let's presume the plank doesn't bend. I'd place two sensors aligned on the plank border along x axis, and one on the opposite side, in a triangle formation, all sensors having x and y axis facing the same directions. Here I noticed you actually need only two actuators, one corner can be fixed. Then lift or lower the actuator on x axis so that both sensors there read 0 degrees. You are done with leveling on that axis. Than you lift or lower the actuator on the opposite side of the plank so that y axis reading from that and any other sensor reads 0 deg. You have a leveled plank.
I'm not sure if I explained it good enough, but that is the way we level cylinders in the casino, only instead of actuators we use a technician.
Can of course be done with only one sensor, it's just my one-track thinking you'd need three :-) |
I understand don't worry, but the thing is that i can't modify the project even though what you said was very interesting. I m forced to use one sensor and 4 actuators ^^. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Sat Jan 28, 2023 3:54 pm |
|
|
Sorry, I over complicated my previous post. One sensor, two actuators would do. I have a question, since you have to use four actuators: how will you know that the plank sits on all four? With three points there is no other way, but with four...
Last edited by PrinceNai on Sat Jan 28, 2023 3:56 pm; edited 1 time in total |
|
|
|