BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Mon Jan 22, 2018 1:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: struggling with control of a stepper motor
PostPosted: Sat Feb 22, 2014 3:07 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Hi all, having some issues controlling a small stepper motor on a nano28. i am using pins 14-17 as all the others are taken up by lcd, switches and rtc. the motor driver board has leds on the output so i can see what im outputing. I think i can set the pins to outputs as by using high and low i can turn them all on or off. The test program is the one that comes with basicmicro studio, the driver board stepper. It works but only turns on pins 14 &15. doesnt matter what i do i cannot get pins 16 & 17 to come on. Only by switching them high not by using the loop.

using dirA how do you assign pins 14-17 as outputs?
using outA how do you set pins 14-17 as low or high?

this combo does not work for me
0101
0110
1010
1001
only the first two work, is it something about pins 16 & 17?

thanks


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 12:51 am 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Normally I will do the follow command at the beginning of the program. This will turn the pin as output. If you want to do input input pin#.
output P14
output P15
output P15
output P16

Hoped it worked for you.


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 12:56 am 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
Oooopps
I forget to change the pin number after paste. Should read as follow:
output 14
output 15
output 16
output 17.


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 1:10 am 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Thanks I thought that was the most obvious and one of the first things I tried but did not work.


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 5:12 am 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
I think that for you to be able to output a group of 4 bits they must be in sequence like P12,13,14,15. If you want to output P14,15,16,17 you need to split the byte in two. Like to output P14 and P15 = OUTN3 = 0xC and P16 and P17 = OUTN4 = 0X3. You need to do two outputs. Also you need to do the OUTPUT PX to the output to work.

Try this program

'output P14 : output P15 : output P16 :output P17
'OUTN3 Output port P12 P13 P14 P15
'OUTN4 Output port P16 P17 P18 P19

main

OUTN3 = 0xC 'output port 14,15 --- 1100 = C
OUTN4 = 0x3 'Output port 16,17 --- 0011 = 3
pause 1000
goto main


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 1:45 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Thanks for your suggestion, I shall try it. First question i have is.
I have part of a rtc on p12 & p13 so by making them an output i guess it will have an effect?
How did you come up with the N3 in OUTN3, is there some sort of pattern as ive tried from outA to outE and i think it didnt like outE.
Is there a list of what ports are related to the various letter eg dirA and outA relate to the first 4 ports, but how does it continue?
If it works in groups of 4 does that mean both groups have 2 ports now redundant?
thanks again


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 3:47 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Sorry if I am stating the obvious:
But if you do outputs (and the commands actually work :lol: ) OUTN3 and OUTN4 - You will not only be potentially changing the 4 IO lines you mentioned, but 12,13, 18, 19 as well. So if they are hooked up to your LCD... They may have their values changed on you as well. Also not sure what DIRA/OUTA are? Directly go to registers on chip? The table of Pin/groupings.
Looking at Data sheet, it looks like pins 14,15 are on Hardware PortC and 16,17 are on hardware PortA

I have also found in the past that I needed to directly do the OUTPUT commands for each of the IO pins to get it to work properly... If it were me, I think I would first try doing the simple ways. That is to directly tell each pin to go high or low. My guess is that should be sufficient speed wise, but if not, then start to look at being tricky. That is you may be able to directly set the IO registers directly...


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 4:33 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
You can find the outputs in page 40 of the Sintax manual. I ran into a problem like your and I have to use the OUTNX command and group the pins as shown on page 40. You can try doing it in a single command but it is too slow. The best it is to try to group them. Also it is the best to send data to a parallel data display. You can use the then the OUTB command. this will send a byte to a port or 8 bits.
I try the small routine and it worked OKAY.
Remember like KurtEck mentioned you will destroy the other bits when you send the output.


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 5:16 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Thanks for all your replies.
This is what ive decided to do. I was working my way up through the pins starting at P0 leaving no gap, which is how i came to P14,15,16,17. Since everything above is free, it was easier to leave a gap and move up a group to P16,17,18,19. I have at this point notice in the manual it relates to OUTEA which works.

Although i still cant see where OUTN3, OUTN4 or OUTNX came from.

so for the moment have some sort of working result. thanks


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 5:55 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
Look in page 40 the following line "INN4,OUTN4 Nib 4 P16 - P19" If you use P16 -P19 then you need to use the command OUTN4 = 0xX. This will output the 4 bits P16-P19 out. They are in the Syntax manual page 40 under the title Variable Names in the table " Pin and Port IN/OUT Variable Names" . This is an important table because it tell the pins assignments by groups.


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 6:07 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
thanks, now i see it i was looking at page 223 reserved words in the manual which is were i found OUTEA. i guess with OUTNX, X is the number?


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 6:45 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
The X means which nib you want to output. If you want to output group bits P16-P19 You need to use then OUTN4 = data or OUTN4 = 0XC. where 0xC = 1100 as an example.
If you want to output your data to group bits P16-P19I will do it like this:
OUTN4 = 0x5 '0101
OUTN4 = 0x6 '0110
OUTN4 = 0xA '1010
OUTN4 = 0x9 '1001


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 6:55 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
thats what i thought, and i guess outN4 is the same as outEA just a different route.

thanks again, other than a jerky stepper motor as it rotates, all is working, now just trying to understand.


Top
 Profile  
 
 Post subject: Re: struggling with control of a stepper motor
PostPosted: Sun Feb 23, 2014 7:06 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
I am glad you was able to making worked. If it is jerking it is possible that you have to send the right phases A B C D depending how many coils you have..


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO