[Swlug] Further interesting calculations
Colin Law
clanlaw at gmail.com
Sun May 28 21:14:38 UTC 2023
Are there any interrupts running? if so then they will add a random factor.
How does it know what the time is and what code is involved in maintaining that?
If you took the time code (and library out) and drove an led instead,
and measured that with an oscilloscope you might get a better figure.
Colin
On Sun, 28 May 2023 at 20:22, Rhys Sage via Swlug
<swlug at mailman.lug.org.uk> wrote:
>
> I just programmed my Arduino Nano Every with a similar program to the Pi Pico test I did the other day. Yeah, OK, I modified somebody's sample code.
>
> unsigned long time;
> unsigned long time2;
> unsigned long time3;
> unsigned long calcu;
> void setup() {
> Serial.begin(9600);
> }
> void loop() {
> Serial.print("Time:");
> time = micros(); //prints time since program started
> Serial.println(time); // wait a second so as not to send massive amounts of data
> calcu = (time * 2);
> time2 = micros();
> time3 = (time2 - time);
> Serial.println(time3);
> delay(1000);
> }
>
> The end result was very interesting. I didn't need to write a program to combine the outputs of 100 repetitions of the code to find a maximum, minimum and average. The variation in the output went from 340 microseconds to 440. Again, a 100 microsecond variation.
>
> I updated my Arduino IDE by deleting the IDEs that are in the Linux Mint app store and downloading straight from Arduino's website. Their IDE works and seems to have my ATTiny88 listed unlike the IDEs on the Linux Mint app store. It can't seem to sense it on the correct port though. That doesn't show up.
>
> All rather interesting and in a few days just to add spice to the mix I have an ESP32 arriving.
>
> I need to beat this 100 microsecond variation into the ground. I'll be switching a set of LEDs on for a fraction of a second using an SBC to control triggering. I'd like to use the same SBC to control the length of illumination. I'm hoping to get a bright flash of around 25 microseconds on demand.
>
> Rhys Sage
>
>
>
>
>
>
> On Sunday, 28 May 2023 at 08:00:06 GMT-4, <swlug-request at mailman.lug.org.uk> wrote:
>
>
>
>
>
> Send Swlug mailing list submissions to
> swlug at mailman.lug.org.uk
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mailman.lug.org.uk/mailman/listinfo/swlug
> or, via email, send a message with subject or body 'help' to
> swlug-request at mailman.lug.org.uk
>
> You can reach the person managing the list at
> swlug-owner at mailman.lug.org.uk
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Swlug digest..."
> Today's Topics:
>
> 1. Re: Interesting variations (Neil Greenwood) (Rhys Sage)
> Out of curiosity, I modified the code and ran it several times with a stand=
> ard deviation of about 100 microseconds. I did wonder about assigning the c=
> ounter to the second core but I'm not 100% sure how to do that.=C2=A0
>
> Average 944.77
> Maximum 1076
> Minimum 942
>
> That's pretty interesting and changes every time I run the code - even thou=
> gh it goes through a thousand iterations. The usual deviation from the aver=
> age seems to be on the high side, indicating something within the OS is def=
> initely gobbling random amounts of CPU time.=C2=A0
>
> Putting it into context, 100 microseconds does not sound much. In this part=
> icular instance I'll do a quick calculation.
>
> A .223 bullet travelling at 3200 feet per second will travel well over half=
> an inch (0.64) in that amount of time.=C2=A0
>
> This has me now wondering whether I can do better in terms of speed and acc=
> uracy with an Arduino Nano Every (I have some). I would love to try it on a=
> ATTiny88 but I can't get the blessed things to perform (I have some of tho=
> se too).
>
> The code used for testing....
> #test counter versus counting
> import time
> Min =3D 0
> Max =3D 100
> Tix =3D 0
> TimTot =3D 0
> MiniTot =3D 100000000000
> MiniMax =3D 0
> TempTot =3D 0
>
>
> for y in range(Min,Max):
> =C2=A0 =C2=A0 tim1 =3D time.ticks_us()
> =C2=A0 =C2=A0 for x in range(Min, Max):
> =C2=A0 =C2=A0 =C2=A0 Tix +=3D 1
>
>
> =C2=A0 =C2=A0 tim2 =3D time.ticks_us()
> =C2=A0 =C2=A0 TempTot =3D tim2 - tim1
> =C2=A0 =C2=A0 TimTot =3D TimTot + TempTot
> =C2=A0 =C2=A0 if (TempTot < MiniTot): MiniTot =3D TempTot
> =C2=A0 =C2=A0 if (TempTot > MiniMax):=C2=A0 MiniMax =3D TempTot
> =C2=A0 =C2=A0=C2=A0
> print("Average", TimTot/100)
> print("Maximum",MiniMax)
> print("Minimum", MiniTot)
>
>
> _______________________________________________
> Swlug mailing list
> Swlug at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/swlug
>
> --
> Swlug mailing list
> Swlug at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/swlug
More information about the Swlug
mailing list