Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Quick question from a newbie.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Rick-S

Bascom Member



Joined: 08 Jan 2009
Posts: 50

usa.gif
PostPosted: Sun Feb 08, 2009 1:48 pm    Post subject: Quick question from a newbie. Reply with quote

Is there any advantage to using an external crystal oscillator circuit on and ATtiny2313 or ATMega8 other than being able to achieve a higher clock speed? Just curious Confused

Rick
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sun Feb 08, 2009 2:06 pm    Post subject: Reply with quote

Hi,

With a crystal you can achieve any serial baud rate with almost 0% baud rate error
and the baud rate will be stable across a wide temperature range.
(Example a 11.0592MHz crystal).

The clock frequency will have the same accuracy of the used crystal.
When you need precise timing, you must use a crystal or an external
clock source.

Best regards,

Luciano
Back to top
View user's profile
Rick-S

Bascom Member



Joined: 08 Jan 2009
Posts: 50

usa.gif
PostPosted: Sun Feb 08, 2009 3:54 pm    Post subject: Reply with quote

Based on what you said, if my project isn't using serial communications and isn't timing dependent, then the internal oscillator is fine. However, if I need to do serial or have a timing dependent application I need to go with an external oscillator circuit to provide accurate timing and temperature stability.

Here's the project I'm working on and a bit of background.

I'm nearly 44yrs old and while I've been a computer enthusiast since the early 80's, I've only had limited formal training in electronics. Don't get me wrong, I can read a schematic, know what the various components are, and have no problem assembling circuitry and even designing simple circuits.

My programming knowledge comes from years ago and was self taught in GW-Basic, QuickBasic, and Visual basic for DOS. I have dabbled in current visual basic, 80's era borland pascal, and 90's era C+ (although very little in the pascal and C+).

The project I have at hand:

I have an inductive industrial joystick that provides an analog output of approximately 3.5vdc at the lower extreme, 4.5 at the center, and 5.5 at the upper extreme.

The joystick needs to control 2 things:

1) Provide 6 output lines at 24vdc to move the X, Y, and Z axis of a CNC milling machine. (These are on/off signals 24vdc toggles an input on the CNC control that moves the Axis 0vdc means no movement)

2) Provide an interface to a windows based PC to act as a mouse.

The two modes will be toggled by a single button. Press the button and the CNC output becomes active and all PC lines go low. Press it again and the CNC lines go low and the PC lines go active.

Currently I am reading the joystick into the ADC of an ATmega8. The plan is to simulate a quadrature output for X & Y and run that into a usb "mouse" board that is used in home brew arcade machines to hook up trac-balls. This seemed to work 'OK' when I tested it on an AT89c2051 but not great. I don't know how to get the quadrature signal to be consistent enough to avoid and occasional jitter. It was functional though. I'm making the move to the AVR's because of the true ADC and I need more than one channel. I haven't yet tried the quadrature on the Mega8,

Anyone have any good ideas for a project like this? Am I going about it in a method that will work? I know I don't have the expertise to program an HID device into a micro controller that is the reason for the secondary board to do this.

Sorry for the long post. This seems to be such a friendly forum I'm hoping someone can offer some insight or suggestions.

Keep in mind though... the simpler the better Wink I am quite the newbie at this.
Back to top
View user's profile
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 519
Location: Cleveland, OH

usa.gif
PostPosted: Mon Feb 09, 2009 4:07 am    Post subject: Reply with quote

Sounds like a fun project.

If you are new to AVR's and such I would be inclined to take it a step at a time.

I would interface the joystick first, and either an LCD or an S-232 serial line to upload data to a PC Hyperterminal terminal emulator to read the joystick data. Do this until you have your joystick working as desired.

It wasn't clear to me why you need an analog input on the joystick if it is just being used for course positioning of the CNC head. Is the joystick just for course positioning, with the operator watching the head, and no position sensing? With simple On/Off output to the CNC controller it would be easier to use a simple joystick. On/Off for the various directions.

I don't recall how many AtoD inputs the Tiny2313 has...

Getting the uC USART to Max232 chip to Serial to PC Hyperterminal will be a big step in itself, and a good experience. You will use this knowledge in the future.

You can use a USB to Serial port converter if your PC doesn't have a true serial port.

You could go uC USART to FTDI chip to do logic level serial to USB prot on PC to Serial Com Port within PC software, if desired.

The uC to 24 V logic switching is a separate task unto itself.

JC
Back to top
View user's profile Visit poster's website
Rick-S

Bascom Member



Joined: 08 Jan 2009
Posts: 50

usa.gif
PostPosted: Mon Feb 09, 2009 1:35 pm    Post subject: Reply with quote

Quote:
It wasn't clear to me why you need an analog input on the joystick if it is just being used for course positioning of the CNC head. Is the joystick just for course positioning, with the operator watching the head, and no position sensing? With simple On/Off output to the CNC controller it would be easier to use a simple joystick. On/Off for the various directions.


The reason for the analog joystick is because the same stick is also used as a mouse on a pc connected to the CNC to transfer programs (Shared Monitor). These joystick are currently being used where I work. They were developed by a company that had custom programmed an 8031 with a bunch of supporting chips to act as a on/off joystick for the CNC as well as a serial mouse. The problem arose when we discovered his serial mouse protocol is off just enough to not work on Windows Vista and the company that developed them is no longer around. Then I stepped into the picture.

Quote:
I would interface the joystick first, and either an LCD or an S-232 serial line to upload data to a PC Hyperterminal terminal emulator to read the joystick data. Do this until you have your joystick working as desired.


So far I have interfaced an LCD with a mega8 and have written a simple program to poll the 1st 4 channels of the ADC and display the results. I have used potentiometers to simulate an analog input and as such can see the value on the 4 ports change from 0 to 1023.

I also have an attiny2313 board (from futurlec) that I have interfaced the RS-232 with my pc so I don't think that it would be a problem with the mega8 if I needed to for some reason.

Quote:
I don't recall how many AtoD inputs the Tiny2313 has...


I don't think it has any, just a comparator. That's why I'll probably opt for the mega8 or mega16. (trying to keep in the dip family not too good with SMC's yet Smile )

I have written a program that I used with one axis of the joystick on an AT89C2051. With this program being fed into my "mouse" board I was able to control the mouse movement on one axis on a PC. Bascom 8051 has a special command to use the comparator of the 2051 as a converter. With it I got usable results. However, I need more ADC inputs and more outputs to do the tasks I need to do.

I'm confident I'll be able to figure it out. And it'll be a fun journey getting there. One plus to it all, it's sparking my son's interest in electronics as well.

I'm open to suggestions and very glad to take any advice I can from those more experienced than I. Thank you so much for your information.

Rick
Back to top
View user's profile
mattcro

Bascom Member



Joined: 03 Oct 2007
Posts: 324
Location: Scotland

uk.gif
PostPosted: Mon Feb 09, 2009 9:05 pm    Post subject: Reply with quote

If you have a spare COM port on the CNC PC (or a USB>RS232 adapter), you could use the AVR to emulate a serial mouse instead of generating 2 sets of quadrature outputs. The protocol for a standard (Microsoft) serial mouse is fairly simple and Windows should recognise it automatically. I can't remember the details offhand. You just need an RS232 level converter like the standard MAX232 to drive the serial port.

You can use the AVR hardware timer(s) to trigger an ADC read at a set interval (typically 40 per second), scale the ADC values to mouse coordinates (you'll have to experiment with the scaling values) and send the mouse position packet to the PC, plus set the CNC drive outputs according to the stick position.

_________________
If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.2
Back to top
View user's profile
Rick-S

Bascom Member



Joined: 08 Jan 2009
Posts: 50

usa.gif
PostPosted: Mon Feb 09, 2009 9:38 pm    Post subject: Reply with quote

Quote:
If you have a spare COM port on the CNC PC (or a USB>RS232 adapter), you could use the AVR to emulate a serial mouse instead of generating 2 sets of quadrature outputs. The protocol for a standard (Microsoft) serial mouse is fairly simple and Windows should recognise it automatically. I can't remember the details offhand. You just need an RS232 level converter like the standard MAX232 to drive the serial port.


I had thought of that originally but wasn't quite sure how to handle the program end. The protocol seems somewhat simple except the x/y coordinates are broken into two bytes of data with certain bits being button status. It seemed somewhat complicated and I'm not too clear on the use of the timers... Though I have been reading the forum here a lot about them.

The other "Main" reason for going the route of generating quadrature and piping that into the "mouse" board is the owner of the company I work for wants to get away from the serial mouse thing as he sees legacy ports fading fast in modern pc's. He feels USB will be around for a while thus the use of the USB Mouse board we're using (simple board used in home brew arcade machines that has headers for quadrature input on x/y/z axis and a header for the switches with a USB connector for the pc)

So, as a result I'm kinda locked into the quadrature thing. Sad

If I had a serial protocol working that would work 100% on Windows Vista and be recognized (would send the proper handshake) I might be able to convince him because we wouldn't need to do any re-wiring in the machine's harness for a new mouse style.

Unfortunately I haven't even pursued that due to his push away from the serial mouse.

I'd be thrilled to see any examples code wise of how one might implement a 3 button microsoft serial mouse protocol though. I think I could handle the ADC scaling... Might even be able to handle the timer thing after some more reading... I'm just not sure how one goes about assembling the bytes in the packets to send. If I were to show him this working, I might be able to sway him away for now. Not to mention it'd be a great learning experience for me! (You know you only get old when you quit learning!) Very Happy

Any suggestions, links, sample code, would be greatly appreciated.

Thanks
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum