By continuing to use this site, you agree to our use of cookies. Find out more
Forum sponsored by:
Forum sponsored by Allendale Jan 24th

Arduino /C++ Questions...

All Topics | Latest Posts

Search for:  in Thread Title in  
SillyOldDuffer05/06/2020 10:46:41
5765 forum posts
1226 photos

Thinking about Neil's precision problem kept me awake last night. What a sad life I lead.

  • It's not necessary to calculate SIDEREAL_RATE on the Arduino, it could be done offline with an arbitrary precision calculator and plugged in as a constant. With Neil's example (1273000 and 1.002737909) the answer to 50 places of decimals is1276485.358157000
  • Looking it up, I found Neil's 1.002737909 is an approximation. When astronomical accuracy is needed further corrections are made, as per the 'Relationship between solar time and sidereal time intervals' section of the Wikipedia Article. An arbitrary precision calculator could factor that in too if necessary.
  • But what level of numeric accuracy is needed? Neil mentions his 1273000 figure will be fine tuned to compensate his rubber rollers. I suspect roller error will dwarf the floating point problem! No reason why reasonable effort shouldn't be put into improving calculation accuracy, but lots of precision is hard work.
  • Part of the hard work involves the inaccuracies inherent in float point even when lots of bits are available. Under the bonnet there's a conversion between decimal and binary that also causes problems when extreme precision is essential. For example, on my 64 bit laptop a long double (128 bits) stores
    • 1.002737909 as
    • 1.00273790899999992731750353414099663
  • Computers use native binary for speed, but if memory space and performance aren't critical Alan's recommended Bignumber library is a good solution. C++ on big machines have Decimal types, which guarantee digit accuracy as needed by accountants, but no-one's made them available for 16 bit microcontrollers.
  • Lastly, it's not difficult to do timer interrupts with μs accuracy in the range 1 to a tad over 8 seconds (in so far as the computer clock is accurate!) Although Arduino lets the programmer get close to the machine when needed, it's usually quicker to use a library. In this case TimerOne should do what Neil wants with interrupts, without requiring any low-level setting up. Let someone else do the hard work.

Dave

John Haine05/06/2020 10:50:28
3080 forum posts
162 photos

I think the Arduino cycle time is 4 us - at least when I've uses "micros" for clock timing that's the resolution. The Nano uses a ceramic resonator for its clock so not too accurate. May not be an issue.

Graham Stoppani05/06/2020 11:00:32
avatar
71 forum posts
12 photos
Posted by Neil Wyatt on 04/06/2020 16:45:15:

I'm a died in the wool lover of assembly language, just because...

Back in the dim and distant past when I was doing my Computing degree, one of the things we dabbled with was VAX assembly language. I remember students commenting on how friendly it was compared to some other languages. Where they would refuse to compile due to the smallest of errors 'String and string' being a good example the assembler would really try to execute your code however mangled it was. smiley

Nick Clarke 305/06/2020 11:44:39
avatar
760 forum posts
25 photos
Posted by Graham Stoppani on 05/06/2020 11:00:32:
Posted by Neil Wyatt on 04/06/2020 16:45:15:

I'm a died in the wool lover of assembly language, just because...

Back in the dim and distant past when I was doing my Computing degree, one of the things we dabbled with was VAX assembly language. I remember students commenting on how friendly it was compared to some other languages. Where they would refuse to compile due to the smallest of errors 'String and string' being a good example the assembler would really try to execute your code however mangled it was. smiley

Students learning C after Pascal told me the same thing - Pascal demanded far more accuracy or the program wouldn't run while C would produce some amazing, if nonsensical results from mistakes in the code. Similar to your VAX assembler C really tried to execute your code however mangled it was. .

After leaving us several went on to one of the local universities where their first programming was in ADA - That taught them to be rigorous in their coding as it was totally unforgiving.

Edited By Nick Clarke 3 on 05/06/2020 11:45:41

SillyOldDuffer05/06/2020 12:13:12
5765 forum posts
1226 photos
Posted by John Haine on 05/06/2020 10:50:28:

I think the Arduino cycle time is 4 us -

That's right!

Joseph Noci 105/06/2020 12:39:05
671 forum posts
890 photos
Posted by Graham Stoppani on 05/06/2020 11:00:32:
Posted by Neil Wyatt on 04/06/2020 16:45:15:

I'm a died in the wool lover of assembly language, just because...

Back in the dim and distant past when I was doing my Computing degree, one of the things we dabbled with was VAX assembly language. I remember students commenting on how friendly it was compared to some other languages. Where they would refuse to compile due to the smallest of errors 'String and string' being a good example the assembler would really try to execute your code however mangled it was. smiley

Hah! I have fond memories of the VAx - esp the VAX11-780...Spent many hours writing code on that machine, also on a Micro-VAX...In the good old days of embargo...My masters was the development of a Bit-Slice emulation of the 11-780 and I wrote lots of code to verify the Bit-Slice version executed identically to the actual VAX11-790..Also did a bit slice version ( copy?..) of the HP-1000 with RAM (!) instead of ferrite core memory...it ran 40X faster than the real one..

I think Neil's Arduino makes the HP-1000 look really old..

Those were the days..

Joe

Ian P05/06/2020 12:41:49
avatar
2380 forum posts
100 photos

I know Neil's request is for assistance with the software, but something in his post puzzles me.

Its the rubber rollers and unknown gearing ratio.

I'm presuming that the software will be progressively tweaked by trial & error once the mount is is mechanically assembled and running. If the characteristics of the rubber components are going to determine the drive ratio then I suppose they could change over time so requiring ongoing software tweaking.

If there was no rubber in the drive and the ratio was known would the software problem go away?

Ian P

IanT05/06/2020 14:03:11
1532 forum posts
144 photos
Posted by Neil Wyatt on 05/06/2020 10:26:33:

It's always interesting to hear about other alternatives.

It's worth pointing out that, in principle, the controller for this could be replaced by a 555 timer controlled with a potentiometer to fine-tune the rate and pulse the stepper driver.

Some people just use geared DC motors and speed controllers.

If I want 32-bit I'd probably go for the Arduino Due which has an ARM processor (a sort of piritual successor to the BBC Micro ) which is available for £12-15.

Neil

In my minds eye Neil - I saw you building something rather like (a mini) Jodrell Bank which needed a mini Cray to control everything - but I have no real idea of what is required in this area.

It wasn't the 32 bit aspect I was thinking of though (although they do offer amazing performance) but more the ease of interactive development. I simply prefer the immediate nature of MMB. For someone like myself without a formal or professional background in programming it really helps. BTW - My 28 pin DIL PIC32 chips cost about £3 and only need one external component (a ceramic capacitor) to build a usable Micromite system.

However, I'll shut up now and get back to re-building the vertical head on my mill (replacement bearings etc).

Regards,

IanT

Neil Wyatt18/06/2020 09:39:38
avatar
Moderator
17886 forum posts
705 photos
77 articles

I've just realised the stepper I'm using has 200 not 48 steps, plus I can get a 32-microstep controller.

I can make use of this additional precision*

But it means my delay between steps will only be about 68ms. Right in the nasty transition between the ms and uS counters.

But the relative in accuracy of microsteps isn't a big deal in proportion, its more about keeping the platform in steady motion than absolute precision and it always averages out per full step.

I have come up with a 'simplified Bressenham' algorithm to apply a sub-microsecond correction to any arbitary accuracy that just uses integers:

  • The theoretical duration between pulses is 68.341 milliseconds.
  • Every 68milliseconds I apply a pulse and add 341 to a counter.
  • If the counter exceeds 1000, I wait an extra millisecond and subtract 1000 from the counter.

What is really neat about this is that I can fine-tune the platform speed just by changing the value added to the counter. It's also easy to make a routine to allow for the counter value reducing below zero.

Delays of 68.34 will follow the sun, and 68.53 the stars. If you have the wrong rate it's visible as drift of the star field so being able to adjust to 0.01 ms at least shoudl be aimed for.

Adrian Purser18/06/2020 15:43:30
2 forum posts

On the subject of the STM32 Arm cpu (Nucleo etc), the STM32 'Blue Pill' boards are quite popular. They can be found for less than £2. They are similar form factor to the Arduino nano and can even be used with the Arduino IDE, although the free ST CubeIDE is rather good. I often feel that a 32bit CPU is a bit overkill for some of the projects I make but when they are so cheap and accessible, why not.

All Topics | Latest Posts

Please login to post a reply.

Magazine Locator

Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!

Find Model Engineer & Model Engineers' Workshop

Latest Forum Posts
Support Our Partners
cowells
Eccentric July 5 2018
emcomachinetools
ChesterUK
Warco
Allendale Electronics
Eccentric Engineering
Subscription Offer

Latest "For Sale" Ads
Latest "Wanted" Ads
Get In Touch!

Do you want to contact the Model Engineer and Model Engineers' Workshop team?

You can contact us by phone, mail or email about the magazines including becoming a contributor, submitting reader's letters or making queries about articles. You can also get in touch about this website, advertising or other general issues.

Click THIS LINK for full contact details.

For subscription issues please see THIS LINK.

Digital Back Issues

Social Media online

'Like' us on Facebook
Follow us on Facebook

Follow us on Twitter
 Twitter Logo

Pin us on Pinterest