BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 12:06 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: coding critique and newbie questions
PostPosted: Tue Jan 03, 2012 7:41 pm 
Offline
Guru

Joined: Wed Nov 30, 2011 7:56 pm
Posts: 52
Location: Ontario Canada
I wanted to do some motor control stuff. No purpose other than to do something on the bench using microcontrollers and learn (or try to recall theory from 1984!). It seemed too easy so I am looking for input on to how to improve it, ie if I really needed to use a motor in something, what would I do to improve this?

1st question...if I wanted to submit a sketch of the circuit, what is the easiest program to do it up in to post here?

The circuit reads a pot value (ADIN16) (coding basically from Syntax manual), then outputs relative HPWM to a small NPN to drive a large PNP (cause that is what I had in stock) to supply 12 volts to a small hobby motor and vary its speed. (no load) :roll: It seemed to work relatively well, I was surprised. I played around with the duty cycle to see how it affected speed control so values there are just the last ones I plugged in. The motor seemed to vary well from zero to almost max. It did not ever see 12 volts and that is most likely that I did not fully saturate the transistor(s). good enough for this lesson, I figured.

I would suspect MOSFet's would be better but have not done much with them. I have a bunch but not sure if they are suitable so thought I would start with the power transistor.

2nd question, when would you use a Mosfet over a bi-polar transistor?

This is pretty simple stuff compared to some of the postings I have been reading so that is part of the reason for posting it, just to give some real newbies something to read that doesn't need interpreting.... :?

3rd question...when you techs start a project, does anyone use flowcharts anymore? How do you get started? I figured a flowchart,leading to roughing out loops in Studio, then filling in coding, dealing with the duty of each loop,...sound reasonable? Sounds like a good way to learn, then you use commands as you need them. but maybe times have changed....?

; Nano 8
; this program is the first motor control circuit
; it uses the a/d practice program from the syntax manual for ADIN16
; and I added the HPWM command to vary 12 vdc hobby motor speed according to a/d value on p0
; motor current is handled with 2SB554 PNP power transistor driven by 2N3904
; Nano is on 5 volt supply while motor runs on 12 volts
;
temp var word
main
adin16 p0,temp ;adin16 is a higher resolution conversion
temp = temp>>4 ;temp will hold a 12bit decimated A/D conversion.
serout s_out,i9600,[0, "Conversion = ",dec temp,13]
hpwm p2,temp, 500 00
; pause 200
goto main


Top
 Profile  
 
 Post subject: Re: coding critique and newbie questions
PostPosted: Tue Jan 03, 2012 8:28 pm 
Offline
Guru

Joined: Wed Nov 30, 2011 7:56 pm
Posts: 52
Location: Ontario Canada
So after typing the last post, I decided to try a MOSfet, 2N7000. specs say 400mA, up to 2 A pulsed. The motor states 1.2A so sounded good. I connected it directly to P2, (didn't work) then tried a pull up resistor (didn't work). I then looked at the specs more, (remember I said I have not done much with MOSfets?)

Datasheet is http://www.fairchildsemi.com/ds/2N/2N7000.pdf
The motor only whines and it only sees a few volts.
I had connected the motor between the source and gnd. Moved it to Vcc and Drain and it works very well.
Lesson learned. :)

I did notice the fet gets quite warm at lower speeds. (ouch) Why? If the Nano is "pulsing it" then it should not get warm, no? :?



Should a pull up/pull down resistor be used? Can a small Mosfet like this be driven directly from the Nano?


Top
 Profile  
 
 Post subject: Re: coding critique and newbie questions
PostPosted: Wed Jan 04, 2012 11:31 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Reason mosfets get hot:

1. not on all the way
Check the voltage at the mosfet gate. Is it above 3v(gate threshold in the datasheet).
2. Switching too fast. Try slowing the PWM rate. Faster switch has high switching losses
3. Rds(on) is pretty high(from 1.2 to 5.3ohms). A good motor driver mosfet will have less than 10 milliohms for Rds(on).

Questions.
1. Not sure what would be the best program to draw the schematic in but uploading it as a PDF or as a JPG would be best.
2. Mosfets are mainly for driving power loads. Bi-polars can do this too but mosfets do it much more efficiently in most cases.
3. Basically. I don't actually draw up a flow chart but I'll work it out in my head before hand and then rough in the programs main loop and then either fill in the peices as code blocks in the main loop(testing each peice that I can one at a time) or write subroutines depending on the complexity of each peice of the program.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: coding critique and newbie questions
PostPosted: Thu Jan 05, 2012 2:19 pm 
Offline
Guru

Joined: Wed Nov 30, 2011 7:56 pm
Posts: 52
Location: Ontario Canada
Thanks Acidtech. Sounds like I am on the right track. I will probably still use flowcharts till I get a little more experience. Sounds like you skip this on paper but do it automatically in your head. ;) I am not there yet...... :roll:

Off to look up some other command... ;) I have an interest in displaying data on a 2x16 display. I have found a few threads on this...

Cheers,


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO