Jump to content

SkySurveyBanner.jpg.21855908fce40597655603b6c9af720d.jpg

Arduino controlled focussing


Gina

Recommended Posts

So I have a continuous servo running using the sweep demo program - all of 5 minutes work (mainly changing the servo signal pin around in the plug).

I also have a finger board for a door that I can cut up and bend to make a holder - then it's literally adding a timing belt + pulley and the hardware is done.. it should be simple enough to create a controller program for the ardunio to take commands from a application.

The annoying thing is that the ardunio uses a virtual serial modem, it's so much easier to use direct block i/o with USB these days..

Link to comment
Share on other sites

  • Replies 180
  • Created
  • Last Reply

True, it seems that none of those parameters are actually memory locations for hardware.

There are no hardware interrupts so there should be no change to the register outside of the software. It´s directing the compiler to load from RAM instead of using the registry.

So really the variables should be non-volatile in that code although I imagine that either will work fine in the code even if technically incorrect.

Link to comment
Share on other sites

so there should be no change to the register outside of the software.
So really the variables should be non-volatile in that code

Hi guy's,

Not sure I totally agree with your last statements Neil.

volatile long NoOfSteps = 1000; //required number of steps to make

volatile long Position = 0; //used to keep track of the current motorposition

volatile long MaxStep = 200000; //define maximum no. of steps, max travel

volatile int SPEED = 500;

Surely these 4 Variables can be changed outside the programme by e.g. the stand alone focuser test interface.

And, presumably, any other interface using the ASCOM driver.

Whilst the values assigned by the above declarations are a good basic starting point, not all focussers would use the same values. (mine certainly does not)

The whole point of declaring them as volotile prevents the compiler from optimising them out or doing some other dastardly thing with them (as they often do) just to make the code more compact.

I agree that the others could be made non-volatile since they are only ever assigned a final value by the programme once.

Please correct me if I am wrong in this thinking.

Best regards.

Link to comment
Share on other sites

I would suggest you are wrong but would like to add a get out of my ignorance sometimes knows no bounds :D

Volatile - variable may have been changed by a parallel thread in the processor, in the arduino case it would be an interlock. This means you can't gaurentee that what you have loaded in the register matchs what is in Ram, one may be an old value, so force a load from ram each time.

Non-volatile - trust what we have in the register.

The code, as it is written, is the only thing changing the value there are no interupts. Even though there is code on the pc sending new values these values are handled in the arduino code in a sequencial manner so at no time do we have the possibility for a conflict of values internally in the arduino. There is the possibility of conflict between the pc and arduino but the pc side can always be improved to handle it better if its a critical problem.

So i would say that as the code stands it doesn't matter which we use.

Link to comment
Share on other sites

As an aside which programming language do people prefer in the pc?

I used vb but i have just been programming a few things at work in c++ and c# and quite frankly I love curly brakets now...they're wonderfull :D

But which is best to rewrite it to? I quite enjoyed c# so i'm edging to that but i'll check to see if the ascom templates are easier in one or other.

Let me know what you all think is best.

Link to comment
Share on other sites

Neil, I would suggest rebasing against c# as that's MS's preferred language.

I take it Ardunio uses it's own hardware independency layer for handling IO interrupts of the ATMeg328 or other CPU type? I see that the mega has interrupts but in the instance of the code, unless there's an interrupt being executed to update the memory location for the stepper variables, it would probably be easier to simply run a loop to read the command and then execute it.

From the Blackfin work I've done, we coded directly onto it with a C GNU compiler chain and used hardware transfers using IRQs for the SPI transfers etc. Also the same for the work with 6502 (old BBC assembler) and ARM assembler.

Link to comment
Share on other sites

Neil, I would suggest rebasing against c# as that's MS's preferred language.

Thanks Nick,

I quite like c# so its a good excuse to get practising on it. Love the try...catch routines...sad isn't it?

With registers i remember doing some old 6800 coding and using LD to load a registry then perform a mv or and then shift etc so you had to be carefull you didnt use an old value or rewriten value in the wrong place.

On the PLCs it was indexed addressing that caused a problem as if you used a second indexed address it over wrote the registry so if you jumped back to the first it suddenly had an incorrect value. That one caused me problems when a fellow programmer stuck a new indexed address in the middle of the code without saving the old value first...nightmare.

Link to comment
Share on other sites

Hehe, the advantage of using a gcc compiler chain is that it maintains a separation between code and data segments. That way it makes the best out of the CPU caches.

I've not had the chance to look into the ardunio compiler/IDE/libraries or how it structures the runtime so it could be that it does things that could cause issues.

Link to comment
Share on other sites

I nearly have my focussing unit working correctly. All working fine on the dining room table using ex-PC CPU for power and running the steppers and their drivers from the 5v. In position on the mount with a 4m wire to the warm room control unit, I'm getting interference on the control line I think as operation is erratic. Works fine on the FF with 5v direct from the PSU and I think it's alright with other buttons pressed but with no button pressed the source resistance is 22K. I've now reduced that to just under 4K and about to test it.

Link to comment
Share on other sites

That's fixed it - working perfectly now :) And that includes the widefield. Found the delrin spacer I had put on the M42 thread to get focus at infinity was slightly too thick so I've swapped it for a thinner one. Instead of getting focus on the distant horizon (about a mile away) it's been focussing on trees about 100m away with the lens focus on infinity. The focussing on my 105mm f2.8 lens which I'm using to image the Heart and Soul Nebulae seems to move about half a mm between 30m and infinity so I'm hoping to have the spacing right to be able to get focus just a fraction off infinity setting. I've swapped the 1.2mm one for a 0.6mm one. Now we just need some clear sky tonight to test everything :D

Link to comment
Share on other sites

I think I should be alright at least for NB. Ha one mile focus is at 15m on the focus scale, OIII is at 30m. So the bluer the nearer to infinity. So I tried the blue filter and that focuses just short of the infinity mark. Anyway, I can't think of any DSO that I would want LRGB for with this large a FOV.

Link to comment
Share on other sites

If you do go down the C# route and use VC# 2010 express I would be interested to know if you manage to build the driver DLL on one machine and register it on another successfully. You can use gacutil.exe to register the DLL with .NET but it doesn't register with ascom. I ended up installing C# on the obsy computer and rebuilding there just to get around this problem.

Link to comment
Share on other sites

  • 2 weeks later...

uno has come , stepper on a slow boat for China , so cant get on with trying anything , loaded the SGL focus control whot code do i need with the stepper listed at the start of the thread ,got it to blink thats all i can do

Lenny

Link to comment
Share on other sites

  • 2 weeks later...

If you do go down the C# route and use VC# 2010 express I would be interested to know if you manage to build the driver DLL on one machine and register it on another successfully. You can use gacutil.exe to register the DLL with .NET but it doesn't register with ascom. I ended up installing C# on the obsy computer and rebuilding there just to get around this problem.

That´s good to know I´ll check it out by building a test version.

Link to comment
Share on other sites

  • 1 month later...

Hi

Just adding an image of my finished project for my Megrez 72.

Basic setup, audrino nano , stepper motor and easy driver board.

All contained in a project box below an aluminium bracket.

All working fine.

Thanks to all file source providers.

Regards

Neil

PicsArt_1370529458300.jpg

Link to comment
Share on other sites

  • 4 months later...

It works very well when you get it setup but there are still a few bugs kicking around. (needs backlash compensation, the VisualStudio VB user parameters keep reseting, park has never worked properly....which has annoyed the heck out of me)

The Ascom driver is written in VisualBasic 2010 express, I keep meaning to move it to 2012 and see what improvements MS have made. I also plan....one day...to do a C version.

I've just started reading this thread, which is quite old so you may have moved on already but:

You're not messing with the assembly/file versions are you? In the assembly info there's 2 versions 1 is more or less a build version the other is more like an API version and should only be changed when you introduce  major/breaking change.  I forget which is which as I leave these alone and version using different methods.

2010 vs 2012? I prefer 2010,  2012 is a bit weird though I do have 2010 profession freeze up 2-3 times a day at work (I'm a VB.net developer by trade.)  At home I have 2012 express as A) it's free and B) you can't get 2010 from MS any more.

For the VB vs C# question later on, it doesn't matter much in reality as they compile to the same MSIL code in the end. But given a choice C# seems to make certain jobs less of a headache and is better supported by the community.

I look forward to helping out on this idea but I need a mount, scope and Arduino first!  Arduino to be ordered on pay day.

Link to comment
Share on other sites

Sorry, this is too much for me to read at once, so I'll comment anyway - it may have been said before.
 
Buttons...
Use an R-2R ladder. It lets you map the resulting resistance to bits in a byte, thus enabling multi-button presses. I also opted to opto-isolate buttons as they do go outside of the board and can be exposed to static and what not. Like this:
 
 
 
post-9361-0-36664600-1383036498_thumb.pn
 
Buttons short to ground on the four leads in the upper right corner. I use 12V and opto couplers to isolate. The outputs drive the ladder, which is then routed through 40106 inverters in order to get clean logic signals for the processor. Cheap components. The ladder can easily be extended to eight stages.
 
Here's the code to decode them:
 

 

byte s = (byte)((analogRead(Roof_AD)+5)/60);  //tested to yield proper bit mappingrSense1 = ((s & 1) > 0);                      //first switch ends up in bit 0rSense2 = ((s & 2) > 0);                      //  bit 1rSense3 = ((s & 4) > 0);                      //  bit 2rSense4 = ((s & 8) > 0);                      //  bit 3

 

If the first two switches are pressed, the result is 3, second switch only yields 2, all switches yield 15. Easy to use. Do not forget to debounce them!
 
Stepper driver.
Yes, you can drive a micro-stepped stepper from software, but you will still need an H-bridge. Said bridge is just as expensive as using a stepper driver with built-in H-bridges. I chose the one used in the board mentioned above, A3967. It is about £3.50 so no great expense. Capable of about 750 mA total bridge drain, this will perform nicely. It will be able to use both bipolar and uniploar steppers and micro-step 1/2, 1/4 or 1/8, selected via two pins. That way, you reduce your code to issuing step pulses on a purely logic level, something that is easily implemented in the main loop of the Arduino.
 
A3967 is easily integrated in your design. Here's my version:
 
post-9361-0-10040900-1383037282_thumb.pn
 
The code to drive the stepper consists of two integers, focuserDesired and focuserPosition. Needless to say, the command to step to a new position is given by just setting desired to where you want it to go. The code below is called about once every 10 ms from the main loop. Since I have the lines to the A3967 wired via external shift registers in order to extend the I/O of the processor, the corresponding lines are manipulated by setting an array of booleans (shiftContent[])which is then shifted out and finally latched. That is what "writeShiftRegisters" does below.
 


 

/* ------------------------------------------------------------------Focuser action. Step in or out depending on the desired value.---------------------------------------------------------------------*/void processStepper(){    if (focuserDesired > focuserPosition) //step out needed    {        shiftContent[focusEnable] = false;  //inverted signal to A3967 enable pin        shiftContent[focusDir] = false;     // set direction        writeShiftRegisters();              //send pins to shift register        shiftContent[focusStep] = true;     //step pulse high        writeShiftRegisters();              //send it to hardware        shiftContent[focusStep] = false;    //step pulse low        writeShiftRegisters();              //send to hardware        focuserPosition++;                  //keep track of position!        focuserMoving = true;    }    else if (focuserDesired < focuserPosition)    {        shiftContent[focusEnable] = false;        shiftContent[focusDir] = true;        writeShiftRegisters();        shiftContent[focusStep] = true;        writeShiftRegisters();        shiftContent[focusStep] = false;        writeShiftRegisters();        focuserPosition--;        focuserMoving = true;    }    if (focuserDesired == focuserPosition)    {        if (focuserMoving)        writeBlock();        focuserMoving = false;        shiftContent[focusEnable] = !focuserLocked;  //if focuser release is desired, let it go        writeShiftRegisters();    }}

Where to store the focuser position?

The EEPROM cells of the Atmega 328P has limit write cycles. There are 1024 cells and I cycle my focuser position through them incrementally by using a signature byte. This increases the life of the memory to tens of years with 50 re-focuses per night. In a future design I will incorporate a proper NVRAM in order to get rid of this problem. They go for less than a pound, so...

Choice of Arduino

Here's one for you: NONE.

Why? Well, they are expensive. I used the Nano in order to do testing, then I bought a bunch Atmega 328P (28-pin DIL) and burned the Arduino boot-loader into them. After that they act as Arduino boards. They go for a frightful £1.40 in quantities of 10 ;)

Implementation

I put it all in my Astrobox (http://stargazerslounge.com/topic/196355-astrobox-controls-my-obsy/). It is currently running my Balcony Observatory and will soon run our new remote observatory in southern France. No hickups, stady operation.

I hope you get some nifty ideas from this. You are free to use and implement the technology, of course. 

All the best,

Per

Link to comment
Share on other sites

On the VS matter...

I find VS2012 Ultimate the best environment to date. I have used it extensively for about half a year and written all my ASCOM drivers and many other projects in it. Never failed, never glitched, and the work day gets so much easier with the new darker themes. The old whitewash one eventually gave me sore and dry eyes... ;)

vs2012.PNG

Link to comment
Share on other sites

On the VS matter...

I find VS2012 Ultimate the best environment to date. I have used it extensively for about half a year and written all my ASCOM drivers and many other projects in it. Never failed, never glitched, and the work day gets so much easier with the new darker themes. The old whitewash one eventually gave me sore and dry eyes... ;)

Guess I need to spend more time getting used to the weird look then.  I've been a fan of the dark look for years and have been using it pretty much since I left uni now.

Link to comment
Share on other sites

I am aslo trying to motorize my focuser but i would like some advice on the gears i should use

i have the standard skywatcher crayford focuser. My intension is to change one of the focus knobs with a belt gear. Its diameter is 4cm and a full revolution of the knob moves the drawtube about 1.2cm. My initial thought is to use a small gear of 2cm diameter to drive the focuser with a stepper motor i bought, it has 1.8 degrees/step. should i consider a direct coupling of the motor with the focuser? Since engineering was not my forte i would like some advice on the subject

Link to comment
Share on other sites

I am aslo trying to motorize my focuser but i would like some advice on the gears i should use

i have the standard skywatcher crayford focuser. My intension is to change one of the focus knobs with a belt gear. Its diameter is 4cm and a full revolution of the knob moves the drawtube about 1.2cm. My initial thought is to use a small gear of 2cm diameter to drive the focuser with a stepper motor i bought, it has 1.8 degrees/step. should i consider a direct coupling of the motor with the focuser? Since engineering was not my forte i would like some advice on the subject

I tried the direct coupling route with a stepper motor but couldn't achieve the torque required to move my imaging train, the motor stalled.

I changed to a belt drive and it works perfectly.

cheers

Steve

post-12560-0-98682000-1383293616_thumb.j

Link to comment
Share on other sites

I use a reduction timing belt & pulleys on my MN190 with a 5:1 reduction (the MN190 doesn't have reduction focussing knob) but on the ED80s I use the small knob with 11:1 focuser reduction and near 1:1 timing belt drive with the timing belt actually driving the knob.

Link to comment
Share on other sites

Stepper Motors.

Getting a little confused on which stepper motor to use. I have seen focuser projects using motors rescued from scanners & printers and those costing a few pounds on Ebay. Other projects are using stepper motors (with/without gearbox) costing £50 plus.

So for the new to arduino/diy projects like myself are there any rules/guidelines to follow?

If I understand correctly a motor that has say 200 or 400 steps should either be used with a pulley & belt to change the ratio, or have a built in gearbox to make the steps more like  2000, 4000 or 6000.

Next is voltage. Is 12v recommended as we usually have a 12v supply on hand for most things astro related? 

I've joined the Yahoo group for the SGL Focuser project (not related to SGL forum) and have a Arduino nano with a Motor Shield which now controls a 12v 200 step motor on my desk, next step will be to add some buttons for manual control (and sort out any gearing) then the brackets.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.