help with a small project - precise 1rpm motor & circut

bance

Joined Aug 11, 2012
315
Have you tried to plug the header from bitsbox into the one from the kit?

I'd be surprised if it fits!

Anyway if all else fails you can de-solder the IDC header and solder the wires directly to the board.

Where about's are you in London? I live in Stokenewington, Hackney.
 

THE_RB

Joined Feb 11, 2008
5,438
Yeah that header will fit fine, they are all standard 0.1" pitch, and I use those same cheap headers (cut down to length) for many projects.

Bance made a real good point that switch might be flimsy! I'm not a fan of push on-push off switches, they have tiny latching hooks etc internally and can be a common source of failure. But if you like it, and are gentle...

I have attached all the source code, everything you need to edit is in ONE file called "Lini_telescope.c". Just unzip all the files and put in a folder called "Lini_telescope".
In the file "Lini_telescop.mcppi" you may need to edit the SEARCH PATH (PATH2) to show the correct folder (where it is on YOUR computer).

That code is tested on MikroC PRO and should be fine. There are two constants (numbers) you edit near the top of the code, these set the speeds for the two available speeds. Just set them the same if you don't need two different speeds.

The number is the "microstep period" in "nanoseconds per microstep" with 6 microsteps per motor full step. On your motor the rotation is 64 full steps, so there are 64*6 = 384 microsteps per motor rotation. As a starting point just run the motor at 1 rev per second, where it should start turning fine, and check your wiring and motoro torque etc.

math for 1 sec/rec;
ustep period = 1sec / usteps per rev
= 1sec / 384 usteps
= 1billion nanosecs / 384
= 1000000000 / 384
= 2604167
So set those 2 numbers to 2604167
:)

I have no experience with that K150 PIC programmer, but generally you need to run the install software on your PC and probably reset your PC, and after that the PC should recognise the programmer and allow you to program a HEX file into it.

The MikroC PRO compiler will "compile" the instructions in the source file "Lini_telescope.c" and make a HEX file "Lini_telescope.hex" which is simply the file you program into the PIC.
 

Attachments

Last edited:

Thread Starter

danstar10

Joined Jan 9, 2013
70
Yeah that header fits just fine bance. I am in Mornington Crescent in London, just between Euston and Camden.

Thanks for the code Roman :)
On lines 44 - 47 there is the following code and comments

// set the value of the XTAL you are using with the PIC
// value is in Hz, so a 16MHz XTAL = 16 million
#define XTAL_HZ 8000000 // tested with 8MHz xtal

As the XTAL I got to replace the resonator is 16MHz, should I change the '#define XTAL_HZ' value to 16000000?

Also, I had a look at making a new project, and in that you need to define the device clock, so was this project built using a 8MHz device clock when I need it to be 16MHz? I dont really know what I am talking about here, just trying to reverse engineer what I can see and catch any problems!

So to make the hex file I just need to use build > Build from the menu? When I do so I get the following in the messages pane:

0 1501 Specified search path does not exist: 'C:\PROGRAM FILES\MIKROELEKTRONIKA\MIKROC PRO FOR PIC_WASNOV28_2011\defs'

0 1501 Specified search path does not exist: 'C:\PROGRAM FILES\MIKROELEKTRONIKA\MIKROC PRO FOR PIC_WASNOV28_2011\Uses\P16'

Does that matter? It still seems to write the hex file fine.

The software I get with is seems self explanatory enough. It seems to recognize the chip. It looks like there is already some code on the chip as when I go to program the hex onto it, it has the following warning - I am guessing it is ok to erase and write onto the chip?

Cheers

 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
You're a quick learner Danstar, I wish everyone on the forum could take on something new and do as well you do! :)

1. YES just change that line in the C file to match your xtal labeled value, so set to 16000000.

2. You don't really need to make a new project, I gave you a full set of project files. However;

3. The "SEARCH PATH" items in the .mcppi file (the project file) were all set by my computer, so you need to change those to match where things are on your computer, like your project files, and the MikroC compiler files. Like you said it might just be easier to make a new project.

4. Remember if making a new project that the PIC CONFIGs are set in Edit->Options, these configs control PIC details that are NOT SET in the source code, like MCLR and XTAL osc type etc. They are also listed in the .mcppi file I supplied and listed again in the source code as a comment.

5. The code supplied on the PIC will be the standard Linistepper stepper driver code. Just erase and overwrite it. :)

6. It can be a good idea to delete an older HEX file before you compile the source code. That way, if it compiles correctly it will make a new HEX file and there is no chance you had a compile error and then mistakenly used the old HEX file!

7. That programmer software looks simple enough. :) It's a good idea to manually check "FUSES" and compare with the CONFIG fuses in the Edit->Project box for your project. I also listed the CONFIG fuses in the top of the source code.

And I must say it's a pleasure to help someone who asks simple clear questions about issues, then solves the issues instantly when you get the answer.
 

Thread Starter

danstar10

Joined Jan 9, 2013
70
Cheers, I am pretty pedantic with details when it comes to this kind of stuff so I certainly try to ask clear questions! :D

Ok, I have changed the oscillator freq in the edit project box to 16 MHZ, and also in the code, and also sorted all the path dependencies so no need to make a new project as far as I can see.

I am not sure if I am encountering a problem putting the HEX on the chip. I am setting the fuses to the following on the PIC programmer software



Which I think matches the settings in the project.
If I then use the 'Blank' setting to erase the chip, then load in the hex file and try to 'Program' it, I get this error



I am pretty sure at one point it said something like 'rom error at 0x0000' at the top line instead of fuse error, then similar good / bad lines.
If I then click 'Program' again straight away, I get this confirm box



And sometimes after that it will write to the chip successfully, other times I will get the same error(s).

Any ideas where I am going wrong :confused:

Cheers
 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
I don't think you are doing anything wrong. If that programmer is like other ones, then "blank" does not erase the chip, but just "checks IF it is blank" and gives a report. :)

Normally to program new code it is very simple, you just load the HEX file and press "program" and it is done!

If the programmer software seems to be fussy, I would just shut it down, then open it again as new, load the HEX file, and press "program".

I have never used or seen that programmer before, so that's all guesswork based on other programmers that I have used.

If anyone uses that same programmer, PLEASE speak up guys! :)
 

Thread Starter

danstar10

Joined Jan 9, 2013
70
Yeah there are two options with the blank button - check and erase, both of which I have tried.

Well it seems to say it successfully programs the chip one in every five or so times I try it, so hopefully it is just a little buggy but when it says it works, it does... I guess we will soon find out with a test!

Back to the circuit design, I have a couple of questions:

  1. I am still unsure about how to go about the grounding. Like I mentioned before, I much prefer the idea bance had of grounding the wires to the 7805 via solder tags through the bolt, seems tidier and easier for me, is there any reason you advised against this Roman?
  2. How can I found out what order to insert the 4 coil wires for the motor into the header on the linistepper? I assume it matters for the step sequencing and cannot be random.
  3. Regarding the LED switch, does it matter which way around I solder the positive / negative wires onto the switch tags? I.e. are they polarity sensitive? I know the LED pins are, with the longer one being positive, but am unsure about the actual tags on the switch. It is SPST if that makes a difference.
Cheers,
Dan
 

bance

Joined Aug 11, 2012
315
Glad you managed the programming, should work, but there probably will be no harm done if not....

Re your questions:-

  1. Sometimes it is important to keep runs as short as possible, but I don't think that is an issue here.
  2. From the datasheet you posted, if you compare that with the schematic for the Linnistepper, you'll see how to connect the wires. (Blue>A1, Yellow>A2,Pink>B1,Orange>B2 and Red>M+)
  3. No it doesn't matter which way around you do it. There shouldn't be a positive, negative just a break in the positive!
Don't forget to heed the warnings in the instructions about not having the battery connected, and making sure all pins are connected to some thing!

HTH Steve.
 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
For question 1, it's a matter of preference. I like to solder wires and all the other wires are soldered so adding screwdown lugs to one point doesn't really gain much. And if that screw gets loose or corrodes (dissimilar metals etc) you can get a bad connection between the different lugs. But it's a perfectly normal and common way of doing things so if you prefer it then do it that way. :)

Regarding connecting the 4 stepper motor coil wires, your motor is a 5-wire unipolar type. There is some info on stepper wiring here;
http://www.piclist.org/techref/io/stepper/wires.htm

Based on your datasheet's diagram of the motor wires in your post #63;
PINK, ORANGE = phase A
YELLOW, BLUE = phase B

The Linistepper "PCB layout" diagram shows the A and B terminals.

Don't worry about which A wire is A+ or A-, that does not matter! The only result is that the motor will turn in the opposite direction.

If, after it is all running, you want to reverse the motor it can be done as easily as reversing JUST the two A wires. (And of course the DIR input pin allows you to change motor direction at any time with a control switch.)
 

Thread Starter

danstar10

Joined Jan 9, 2013
70
Ok thanks guys. I am still waiting on some slow post items to arrive which I need before I finish up the circuit - I will keep you posted.

When you say I need to make sure all the pins are connected to something, do you mean the the header pins on the 10 pin IDC cable connector? Is having it wired up like in the wiring diagram from this forum not sufficient??

Also I meant to ask about replacing the 16MHz resonator with the 16MHz xtal I bought. It is the SV1 component on the linistepper diagram.

Do I just need to unsolder the resonator and replace it with the xtal? Which way around does the xtal need to be soldered? I cannot see anything on it which suggests positive or negative. It says 'ACT b2 16.00 SCB' on the top of the xtal. If I look at the text the correct way, will that help me locate the polarity of it?

Also the caps for the xtal, i got two 15 and two 22 caps. Does it matter which ones I use at all? Again there is no obvious polarity markings, so how do I tell with these?

Cheers
 
Last edited:

bance

Joined Aug 11, 2012
315
I was just quoting from the assembly/usage instructions from the Linnistepper website, but if you remember the circuit was designed to act as an interface between a B/O board and the stepper motor.

Often steppers are used in CNC machines, which are controlled by a PC. Therefore the board is designed to accept an input to control it.

The header goes directly to the PIC pins, since in your user case no additional input is required, these pins are left NC (not connected).

Digital circuits only respond to definite highs or lows, anything in between can cause the chip to act in unexpected ways. An un-connected pin can be prone to stray inductance, capacitance or worse, which may take the pin to a voltage level that is in this grey area. Therefore it is usual to tie an NC pin either high or low. This can be dealt with in software, and although I haven't looked at the code, I'm sure RB has done this. For more info on this see here.

Ceramic caps and crystals are not polarised components, they can go in anyway around.

Looks like the two pins of the crystal go in the outside holes, and each cap goes between an outside hole and the middle. I had a look for the datasheet for the crystal to see which value was recommended, but drew a blank. In my experience either will do, so take your pick. Perhaps RB can confirm?

If you haven't de-soldered before it might be a good idea to practice on an old board first. Don't try to de-solder surface mount parts, start with resistors or caps.

Do you have a solder sucker or solder wick? Try not to apply too much heat in case you lift the pads. Use some flux it will help to make the solder run. If you don't have solder wick, coax shielding can be used as a substitute. Practice on an old board first.

HTH Steve.
 

THE_RB

Joined Feb 11, 2008
5,438
The 16MHz xtal and caps he got are fine, no problems there.

To desolder the 3 pin resonator from a "plated through hole" PCB, my technique would be to get the soldering iron tip nicely tinned and shiny and holding some excess solder, then apply it to ALL 3 pins at once on the PCB bottom. Within 2 or 3 seconds the resonator can be pulled straight out. You might burn your fingers a bit but that is perfectly normal. :D

Then to solder in the crystal it does not have an orientation. I would trim its legs a bit shorter, then heat each pin on PCB bottom one at a time and push it down through the holes, that will work ok even if the holes still have some solder in them. It might take a couple of goes to "work" it down, one leg at a time. Leave the xtal 2mm above the PCB, don't push it down all the way.

For the two caps, I would use the 15pF ones with a 16MHz xtal. Add the caps on the bottom of the PCB, each caps goes between an outer pin and middle (gnd) pin. Trim and bend the cap leads short and neat first (and tin them!).

For the 10pin header, just connect the couple of wires as shown in the diagrams we made. :) The Linistepper circuit has pull-up resistors on the digital inputs, which holds them in a "safe" pulled-up state when not connected to anything.

Re soldering and overheating, a good rule is to ALWAYS make sure the iron tip is freshly tinned and shiny before touching it to anything. And soldering/melting etc should always happen in 2 or 3 seconds after toughing the iron tip to the PCB joint. If anything takes more than 3 seconds it's likely your tip is dirty and not transferring heat properly, so clean it and tin with fresh solder again.

And if all soldering events happen within <3 secs or so there's practically no chance of overheating parts or the PCB. Based on all your nice shiny looking solder joints earlier I think you are doing it all correctly and getting a good result. :)
 

Thread Starter

danstar10

Joined Jan 9, 2013
70
Hey guys, So I finally got everything in the post - I was waiting for the correct drill bit to set my switch in the case - and now I have (hopefully) finished soldering everything :)

So as far as I can tell, I have hooked everything up as in the diagram we settled on. I also replaced the resonator with the xtal and caps. That didn't go as smoothly as it could have, but I think (hope) that it has ended up ok. I soldered one of the legs of one cap to the other for the GND connection as they did not both fit through the PCB hole - assume that is ok?

I have made a few burn marks on the bottom of the PCB removing the resonator so it does not look too pretty - let me know what you think.



Hers is a video so hopefully you can get an idea of what is connected to what. The only thing that is not connected here is the positive input from the battery via the inline fuse, as I want to wait until I know the length of the leads before I solder that connection.

http://www.youtube.com/watch?v=Ft_J9txOe08&feature=youtu.be

Roman, do you think I am ready to test 'with the power on'? Are there any things I should double check first? I have checked for shorts between the legs on C3 and C1, and the transistors to the heat sink as per the build instructions. Should I continue to the checks listed where the power is on?

Also, where should the DIP switch 2 switches be set to for my purposes before testing?

For testing, if I were to follow the instructions:
IMPORTANT! Check that PIC socket pin 14 is +5v, and pin 5 of the socket is Ground. Double check this!

I would not really know how to put this into practice. I can find the pin numbers easily, then I should set the multimeter to V on the 20 notch, but where should I put the probes to test the above?

I can see a glimpse of light at the end of the tunnel, not holding my breath yet tho :p

Cheers
 

bance

Joined Aug 11, 2012
315
All looks good to me, de-soldering is not as easy as you think, if you haven't done it before, which is why I suggested a bit of practice..... but what you've achieved is fine.

The reason they suggest testing for 5V on the MCU is so it doesn't get fried. They suggest testing before the MCU is in place. If you want to test,without the MCU be careful when you remove it, the pins are delicate. Then its just a matter of placing the -ive (black) lead on a ground point and the +ive (red) lead on the point you want to test.

As to which jumper should be set I'm not sure, although it shouldn't matter,for testing.

I'm sure RB can put you right!

Well done it looks excellent, you should consider posting to the completed projects section!!!

HTH Steve.
 

THE_RB

Joined Feb 11, 2008
5,438
Bance already hit it on the head. Just stick the red probe in the empty IC socket on PIN14 and the black probe on pin 5 (which is connected to the common ground).

I think if you have your 1A fuse in line with the battery all should be safe, in the event of a wiring fault it should just blow the fuse and the other stuff should be safe, as both the 7805 regulator and the power transistors on the PCB are all rated for >1A.

Once that is ok, then you can insert the IC. Obviously it's important to put it the correct way around!

For future reference when soldering caps etc on the bottom of a PCB you don't need to twist the wires around other wires or put them "through" a hole. Just tacking them on the bottom to the pads is fine. :)

The two jumpers/switches are not used in the telescope code, so they will not matter.

Overall it's looking good. Just make sure when putting stuff in that metal box that nothing will short out, especially the metal wires/pins etc on the bottom of the PCB. I often use a square piece cut from tough plastic with scissors, the plastic of an ice cream container lid etc is easy to cut and thick enough to take some abuse without perforating.
 

Thread Starter

danstar10

Joined Jan 9, 2013
70
Well I powered her up and it seems to be running nicely :D I was totally expecting some hurdles before I got it turning, but it worked first time!

Strange thing is, with the current code on the PIC, it rotates at a seemingly random speed. It take approx 5:18 to rotate approximately 10 times, so seems to take approx 31-32 secs to do one rotation. Could the value you told me to set in the code be incorrect Roman? I have it set to:
#define SPEED1 2604167
#define SPEED2 2604167
In the post where you gave that number, you mentioned the motor has "6 microsteps per motor full step" - In the motor datasheet, it says Number of Phase - 4. Is that the same thing, so your calculation should be using that? Or is it a different thing altogether...
I found a post about this motor on an arduino forum. One user wrote:
for your motor and gearbox you have a 64 step motor with a 64:1 gearbox so you have 4096 Steps per rev.
Not sure how directly that applies, I am sure you have included that in your calcs already...


Also, does the below bit of code need any altering for my 16MHz xtal perhaps? I guess not as 'XTAL_HZ' is a constant which was assigned a value of 16000000 rite?
// DO NOT CHANGE this define below! it calculates the nanoseconds of 1 interrupt
#define PERIOD_INT (1024000000 / (XTAL_HZ/4000))

Also, as I was having problems writing to the PIC, could it be a writing error? The last time I programmed it, it said it was successful...

Exciting stuff! :D
 
Last edited:

bance

Joined Aug 11, 2012
315
The figures RB gave you should turn the motor at 1 rev per second... which means after the gearing it should take the cog 64 secs to complete one revolution.

You're saying it does so in 32 secs.... sounds like 2X speed... 8Mhz-16Mhz?

Are you sure the xtal is set correctly in the code?
 

Thread Starter

danstar10

Joined Jan 9, 2013
70
Ah I see, of course. For some reason I thought I was expecting a 1 rpm shaft speed with this code. I was worried that what I was seeing was not a division of 60, but it seems to be a division of 64 which is good.
I have set the XTAL_HZ to 16000000 in the code yes, and the project settings.

Is there anywhere else in the code, or indeed the hardware that this 2x error could be creeping in?

Cheers
 

Thread Starter

danstar10

Joined Jan 9, 2013
70
Bugger, looks like I have just blown the fuse. I am pretty sure the temporary croc clip I have on the positive lead from the battery to the switch just touched the aluinium case and so shorted out. Do you think I could have damaged anything else in the process? :(

Just looking to get some replacement fuses as I stupidly only bought 1 from bitsbox - are 'quick blow' fuses the same as 'fast blow'?

http://www.maplin.co.uk/20mm-glass-quickblow-f-451

Cheers
 

bance

Joined Aug 11, 2012
315
Should be OK the fuse is there to protect the circuit... quick blow/fast blow are the same thing, but check the size some are 20mm some are 32mm.

I bugger things up all the time so I usually get two or three of anything I order, but it's how you learn... Magic smoke!

I don't use C to programme so I can't really help - code wise. There shouldn't be anything in the hardware to cause a 2X error, if that's what it is!

HTH Steve.
 
Top