Loading ...
Sorry, an error occurred while loading the content.

8254 programming

Expand Messages
  • hotguccio
    Hi gang. I just joined the group, in order to get the source code for CNCpro. Why? Because I m thinking of writing my own CNC control software, partly for
    Message 1 of 11 , Sep 4, 2009
    View Source
    • 0 Attachment
      Hi gang. I just joined the group, in order to get the source code for CNCpro. Why? Because I'm thinking of writing my own CNC control software, partly for fun, partly to make sure I understand how it works, and partly so that I'll only have myself to blame if it doesn't work right. So, I wanted to see an example.

      I'm going to put on my asbestos suit now, because I know I'm going to get flamed for what I say next - I'm planning on sticking with DOS, and using Quickbasic 4.5. I want the program to be as simple as possible, at least to begin with. All I want it to do is read the G-code, run the machine, and have a simple, nice-looking display, with big coordinates (I'm using a .bmp file, and Get and Put). I do my program development in the living room, and my milling in the garage, so I don't need tons of capabilities on the controller.

      One of the things I wanted to see was how he generated faster clock ticks to drive the steppers. Therefore, I was pleased when I saw the set_timer_freq() routine. However, I have to say that there could have been a lot more comments about why he was doing what he was doing. It's a given that one programmer is not going to be satified with another programmer's comments, but really! After looking at the code for a while, I can't see where he's actually changing the counting frequency of the chip. I keep seeing the number 18, which looks a lot like the normal 18.2 interrupts per second.

      Something that I read here suggests that what he's doing is resetting the 8254 interrupt to a faster value (I can't figure out what), and having his real-time routine, driven by that, call the BIOS clock routine 18 times a second. Is that right? It makes sense. Can anybody tell me what the new interrupt rate is? I'm sure many people have done studies how much real-time computing can be done at such-and-such a rate with such-and-such a CPU, etc.

      Any comments will be most appreciated.
    • Jerry Jankura
      ... You can exchange your asbestos drawers for your normal garments. Working in a DOS environment means that you can have almost complete control of your
      Message 2 of 11 , Sep 4, 2009
      View Source
      • 0 Attachment
        On Fri Sep 4, 2009, at 3:09 PM, hotguccio wrote:

        > I'm going to put on my asbestos suit now, because I know I'm going
        > to get flamed for what I say next - I'm planning on sticking with
        > DOS, and using Quickbasic 4.5. I want the program to be as simple
        > as possible, at least to begin with. All I want it to do is read
        > the G-code, run the machine, and have a simple, nice-looking
        > display, with big coordinates (I'm using a .bmp file, and Get and
        > Put). I do my program development in the living room, and my
        > milling in the garage, so I don't need tons of capabilities on the
        > controller.

        You can exchange your asbestos drawers for your normal garments.
        Working in a DOS environment means that you can have almost complete
        control of your computer without having to develop a specialized
        software driver. As for BASIC, I'm not a real proponent of that
        language for CNC primarily because programs written in BASIC do not
        execute as fast as programs written in some other programming
        language, such as C. But, if we're going to flame folks based on
        choice of language choice, we'd better begin by crucifying anyone who
        hasn't written a G-Code interpreter (that's what CNCPro is) in
        Assembly Language. I don't know how much research you've done, but
        you might want to visit this URL: <http://www.thegallos.com/
        stepster.htm>. Stepster is an old G-Code interpreter that is written
        in the "PowerBasic" dialect of the BASIC programming language.

        > One of the things I wanted to see was how he generated faster clock
        > ticks to drive the steppers. Therefore, I was pleased when I saw
        > the set_timer_freq() routine. However, I have to say that there
        > could have been a lot more comments about why he was doing what he
        > was doing. It's a given that one programmer is not going to be
        > satified with another programmer's comments, but really! After
        > looking at the code for a while, I can't see where he's actually
        > changing the counting frequency of the chip. I keep seeing the
        > number 18, which looks a lot like the normal 18.2 interrupts per
        > second.

        It sounds as if you've encountered one of the difficulties in reading
        someone else's code. It'd be nice if you'd document and post any
        analyses of the program that you make. That way, we'd all benefit.

        > Something that I read here suggests that what he's doing is
        > resetting the 8254 interrupt to a faster value (I can't figure out
        > what), and having his real-time routine, driven by that, call the
        > BIOS clock routine 18 times a second. Is that right? It makes
        > sense. Can anybody tell me what the new interrupt rate is? I'm
        > sure many people have done studies how much real-time computing can
        > be done at such-and-such a rate with such-and-such a CPU, etc.

        This tutorial: <http://www.decisioncards.com/io/tutorials/
        8254_tut.html> might help you figure out what the 8254 is programmed
        to do. Of interest to you is the number that's programmed into the
        register that divides the input clock frequency. The input clock rate
        is 1.19 Mhz.

        One other program you may wish to consider for study is TurboCNC. <www.dakeng.com
        > Source code written in Pascal (Borland Pascal, V7) is available to
        those who register the software. I used this program for quite a while
        before moving to EMC and Ubuntu Linux. At one time, I was part of the
        development team, but am no longer.

        Hope this helps out. Good luck on writing your own software.

        Jerry Jankura
        So many toys.... So little time....
      • hotguccio
        Jerry: Thanks for the quick and cool response ;-) Which development team were you on? I ve thought seriously about getting the Turbocnc source code, and I may
        Message 3 of 11 , Sep 4, 2009
        View Source
        • 0 Attachment
          Jerry:

          Thanks for the quick and cool response ;-) Which development team were you on? I've thought seriously about getting the Turbocnc source code, and I may very well do that.

          I was hoping that somebody out there could just tell me what value is being put into the 8254 count-down value to replace the 65,536 (aka 0) that is normally there. I could spend more time looking at the cncpro source code, and who knows, I might get lucky.

          Were you aware that Quickbasic 4.5 allows compiling to an executable? How good the executable is, I don't know. But, FreeBasic's executables are supposedly very close in speed to those of C, and it is supposed to be fairly compatible with Quickbasic, from what I understand.

          I guess I should give my credentials, so people don't waste their time instructing me in the basics. I have an M.S. in mechanical engineering from UCLA, specialising in dynamics and control. I won't claim to be to be great at that subject, but at least I got some instruction in it. As to programming, I've done quite a bit of it, although not a lot recently (I did write a g-code to Anilam conversational code converter in Quickbasic recently, and it worked on the file I tried. The Anilam 'visualizer' liked it, anyway).

          Back in about 1988, the company I was working for wanted a PC-based display system for the PLC controller they decided to use, and they handed me the programming job. It was written in C, and I used the clock tick interrupt to keep track of things. So, although I didn't need to re-program the 8254 then, at least I did successfully re-direct the interrupt.

          Somewhere in there, I also got a certificate in microcomputer circuit design, and the company let me design a simple ROM-memory board programming device. I think it used an Intel 8751. The ROM board was from an existing controller, and in order to program it, first I had to figure out how its programming circuitry worked. It turned out to be very complicated. I wrote a very wordy description of exactly how it worked for my boss, and I included the comment that whoever had designed it should be shot. He wrote on my description: "Whoever wrote this should be shot!"
        • Jerry Jankura
          ... I worked with Dave Kowalczyk on TurboCNC V4. That was right around the turn of the century. I haven t been actively involved with TurboCNC for at least a
          Message 4 of 11 , Sep 4, 2009
          View Source
          • 0 Attachment
            On Fri Sep 4, 2009, at 8:25 PM, hotguccio wrote:

            > Thanks for the quick and cool response ;-) Which development team
            > were you on? I've thought seriously about getting the Turbocnc
            > source code, and I may very well do that.

            I worked with Dave Kowalczyk on TurboCNC V4. That was right around the
            turn of the century. I haven't been actively involved with TurboCNC
            for at least a good half dozen years.

            > I was hoping that somebody out there could just tell me what value
            > is being put into the 8254 count-down value to replace the 65,536
            > (aka 0) that is normally there. I could spend more time looking at
            > the cncpro source code, and who knows, I might get lucky.

            I doubt that anyone's done that thorough of an analysis.

            > Were you aware that Quickbasic 4.5 allows compiling to an
            > executable? How good the executable is, I don't know. But,
            > FreeBasic's executables are supposedly very close in speed to those
            > of C, and it is supposed to be fairly compatible with Quickbasic,
            > from what I understand.

            I knew it was a compiler; I understood (but did not verify) that the
            resultant code was not as tight as the code that C or C++ might
            compile to.

            > I guess I should give my credentials, so people don't waste their
            > time instructing me in the basics. I have an M.S. in mechanical
            > engineering from UCLA, specializing in dynamics and control. I
            > won't claim to be to be great at that subject, but at least I got
            > some instruction in it. As to programming, I've done quite a bit of
            > it, although not a lot recently (I did write a g-code to Anilam
            > conversational code converter in Quickbasic recently, and it worked
            > on the file I tried. The Anilam 'visualizer' liked it, anyway)

            I've got a similar background, although my degrees are in electrical
            engineering from Cleveland State University and my work experience was
            in the field of factory automation of lampmaking equipment. I spent
            some time writing a program that ran on a TI DSP based frame grabber
            that would find a spot of light and edge trace around it. I wrote that
            code in Borland's TurboC and then ported it to the C compiler that
            supported the DSP chip once the algorithm was checked. I also wrote
            the interface software using Borland's Delphi.

            As for programming languages, each has its own unique syntax for doing
            the same thing that every other language does. I've come to believe
            that the most difficult computer language to learn is the second one
            you learn, whatever it is. That's because you've ingrained yourself to
            the syntax of the first language and haven't had enough experience to
            look for the commonalities and then simply check the manual for the
            appropriate syntax and exceptions. I was fortunate that I had only one
            employer once I left college; that job lasted 32 1/2 years. It was
            interesting to see how different folks (including me) had different
            language preferences. The last team I worked with had one fellow who
            loved Visual Basic to the exclusion of everything else. But he got the
            job done and kept everyone happy.

            Currently, I've moved over to Apple products for my own computing
            needs; I'm using Ubuntu Linux + EMC V2 as an appliance computer to run
            my Sherline mill. I run Windows on the Apple using Parallels V4 to
            provide a virtual environment for Windows XP. I'm finally starting to
            look at a couple of languages - RealBasic and X Code's objective C -
            for the Apple. It certainly stimulates the brain. :)

            Jerry Jankura
            So many toys.... So little time....
          • hotguccio
            ... You must know all kinds of things about TurboCNC. If I get the source code, may I ask you questions about it? I looked at the startup info for TurboCNC,
            Message 5 of 11 , Sep 5, 2009
            View Source
            • 0 Attachment
              >I worked with Dave Kowalczyk on TurboCNC V4. That was right around
              >the turn of the century. I haven't been actively involved with
              >TurboCNC for at least a good half dozen years.

              You must know all kinds of things about TurboCNC. If I get the source code, may I ask you questions about it?

              I looked at the startup info for TurboCNC, and it said "Mean 8254 timer latency is 5.40 microseconds, max if 39.00, min is 5.00. Frequency where jitter approaches 10% is: 22081.2 Hz." This is very interesting. I wonder what sorts of methods were used to obtain this information? Unfortunately, I'm not really sure exactly what `timer latency' is.

              I decided to try a little analysis of the timing requirements, just in case anyone has thoughts on the subject. I may completely screw this up, but here goes. I think my Bridgeport Series 1 Boss 5 can rapid at something like 300 ipm, or 5 inches per second. Maybe it's not really that fast, but that'll do for starters. The drive works out to 1000 steps/in, so we would need 5000 steps per second. The 8254 is normally set up with a count-down value of 65536. 1193180 Hz / 65536 = 18.2065 Hz, which is the rate at which the BIOS' bell gets rung. If we had a real-time routine that ran 5000 times a second, then the countdown value should be 119310/5000 = 238.6. The nearest integer is 239, which would give a rate of 1193180/239 = 4992.4. 4992.4/18.2965 = 274.2. So, the timer handling routine would need to call the BIOS clock routine once every 274 times, so it can do its thing. Any comments?

              I looked at the code some more. I `m rather rusty on C, but I think the following statement:

              new_timer_number=(freq==18) ? 0 : ((unsigned int) (1193180L/freq))

              means:

              if freq = 18 then
              new_timer_number = 0
              else
              new_timer_number = 1193180/freq
              end if

              This is in set_timer_freq(), which gets called by begin_realtime(). But, I can only find the definition of begin_realtime() in Kernel.c, no call to it. So, where does it get called? Maybe I'm just missing it, but I can't find any other source code, except for ACE.
            • Jerry Jankura
              ... You can ask, but you ll probably get better results if you join the TurboCNC yahoo list and post your questions there. I haven t looked at the source in
              Message 6 of 11 , Sep 5, 2009
              View Source
              • 0 Attachment
                On Sat Sep 5, 2009, at 6:38 PM, hotguccio wrote:

                > You must know all kinds of things about TurboCNC. If I get the
                > source code, may I ask you questions about it?

                You can ask, but you'll probably get better results if you join the
                TurboCNC yahoo list and post your questions there. I haven't looked at
                the source in years while others are still puttering around with it.
                We quit plucking the chicken and turned off the fire under the tar a
                long time ago on that list so your questions will be met with
                reasonable responses. Dave hasn't posted any updates to that list in
                quite a while so I think that anyone who shows an active interest in
                the program will be met with outstretched arms.

                > I looked at the startup info for TurboCNC, and it said "Mean 8254
                > timer latency is 5.40 microseconds, max if 39.00, min is 5.00.
                > Frequency where jitter approaches 10% is: 22081.2 Hz." This is very
                > interesting. I wonder what sorts of methods were used to obtain
                > this information? Unfortunately, I'm not really sure exactly what
                > `timer latency' is.

                I'm not sure how Dave figured this out. My part was mostly in the area
                of the human interface.

                On CNCPro, the initialization code should set up the timer for CNC and
                replace the vector for the time of day clock with a pointer to a new
                routine; the exit code should return both to their original values. I
                would expect that the interrupt service routine would be responsible
                for maintaining the TOD clock, incrementing a counter, and calling the
                CNC routine that sets up step & direction when the count would reach
                the appropriate value. I would expect that timer latency is the time
                that the interrupt service routine requires to do its thing. Since
                this is not necessarily a fixed value, there's some variability in it.
                I'm guessing that with TCNC, the ISR takes a max of 5.4 usecs. I'm not
                sure where the 22Khz comes from; my calculation would be the frequency
                whose period is 54 usec. This is about 18 khz. In any event, it sounds
                as if you'll be running way below that value.

                Jerry Jankura
                So many toys.... So little time....
              • Eddie Joubert
                Tom Guenther has put his translation of TCNC for win32 in the files section of theTCNC yahoo group. It is in files/rel4-users/tcncwin32.rar and it is also
                Message 7 of 11 , Sep 5, 2009
                View Source
                • 0 Attachment
                  Tom Guenther has put his translation of TCNC for win32 in the files section of theTCNC yahoo group.
                  It is in " files/rel4-users/tcncwin32.rar" and it is also written in Pascal the same as TCNC but he has good coments about the 8254 Timer.
                  I hope this helps!
                  I would like to keep in your discussion group as I am having similar thoughts for programong for Vista and am trying to figure out how the MACH3 works




                  ----- Original Message -----
                  From: hotguccio
                  To: CNCPro@yahoogroups.com
                  Sent: Sunday, September 06, 2009 12:38 AM
                  Subject: [CNCPro] 8254 programming


                  >I worked with Dave Kowalczyk on TurboCNC V4. That was right around
                  >the turn of the century. I haven't been actively involved with
                  >TurboCNC for at least a good half dozen years.

                  You must know all kinds of things about TurboCNC. If I get the source code, may I ask you questions about it?

                  I looked at the startup info for TurboCNC, and it said "Mean 8254 timer latency is 5.40 microseconds, max if 39.00, min is 5.00. Frequency where jitter approaches 10% is: 22081.2 Hz." This is very interesting. I wonder what sorts of methods were used to obtain this information? Unfortunately, I'm not really sure exactly what `timer latency' is.

                  I decided to try a little analysis of the timing requirements, just in case anyone has thoughts on the subject. I may completely screw this up, but here goes. I think my Bridgeport Series 1 Boss 5 can rapid at something like 300 ipm, or 5 inches per second. Maybe it's not really that fast, but that'll do for starters. The drive works out to 1000 steps/in, so we would need 5000 steps per second. The 8254 is normally set up with a count-down value of 65536. 1193180 Hz / 65536 = 18.2065 Hz, which is the rate at which the BIOS' bell gets rung. If we had a real-time routine that ran 5000 times a second, then the countdown value should be 119310/5000 = 238.6. The nearest integer is 239, which would give a rate of 1193180/239 = 4992.4. 4992.4/18.2965 = 274.2. So, the timer handling routine would need to call the BIOS clock routine once every 274 times, so it can do its thing. Any comments?

                  I looked at the code some more. I `m rather rusty on C, but I think the following statement:

                  new_timer_number=(freq==18) ? 0 : ((unsigned int) (1193180L/freq))

                  means:

                  if freq = 18 then
                  new_timer_number = 0
                  else
                  new_timer_number = 1193180/freq
                  end if

                  This is in set_timer_freq(), which gets called by begin_realtime(). But, I can only find the definition of begin_realtime() in Kernel.c, no call to it. So, where does it get called? Maybe I'm just missing it, but I can't find any other source code, except for ACE.





                  [Non-text portions of this message have been removed]
                • Jerry Jankura
                  ... Have you downloaded and unarchived this file? I was able to download it, but could not open it because it did not recognize the usual password that Dave
                  Message 8 of 11 , Sep 6, 2009
                  View Source
                  • 0 Attachment
                    On Sat Sep 5, 2009, at 11:44 PM, Eddie Joubert wrote:

                    > Tom Guenther has put his translation of TCNC for win32 in the files
                    > section of theTCNC yahoo group.
                    > It is in " files/rel4-users/tcncwin32.rar" and it is also written in
                    > Pascal the same as TCNC but he has good coments about the 8254 Timer.

                    Have you downloaded and unarchived this file? I was able to download
                    it, but could not open it because it did not recognize the "usual
                    password" that Dave used to protect his source code.

                    Jerry Jankura
                    So many toys.... So little time....
                  • Eddie Joubert
                    Hi Jerry I received the password from Dave some years ago after registering with him. Although I use C and Assembler I found his Pascal source code very
                    Message 9 of 11 , Sep 7, 2009
                    View Source
                    • 0 Attachment
                      Hi Jerry
                      I received the password from Dave some years ago after registering with him.
                      Although I use C and Assembler I found his Pascal source code very useful in spite of my applications not using G code.
                      Eddie


                      ----- Original Message -----
                      From: Jerry Jankura
                      To: CNCPro@yahoogroups.com
                      Sent: Sunday, September 06, 2009 4:24 PM
                      Subject: Re: [CNCPro] 8254 programming



                      On Sat Sep 5, 2009, at 11:44 PM, Eddie Joubert wrote:

                      > Tom Guenther has put his translation of TCNC for win32 in the files
                      > section of theTCNC yahoo group.
                      > It is in " files/rel4-users/tcncwin32.rar" and it is also written in
                      > Pascal the same as TCNC but he has good coments about the 8254 Timer.

                      Have you downloaded and unarchived this file? I was able to download
                      it, but could not open it because it did not recognize the "usual
                      password" that Dave used to protect his source code.

                      Jerry Jankura
                      So many toys.... So little time....





                      [Non-text portions of this message have been removed]
                    • doug6949
                      ... I wrote a lot of code in Quickbasic 3.5, 4.0, and some in 4.5. It was IMO one of the best development tools from MS at the time. It was not at any
                      Message 10 of 11 , Sep 12, 2009
                      View Source
                      • 0 Attachment
                        --- In CNCPro@yahoogroups.com, hotguccio <no_reply@...> wrote:
                        >

                        > I'm planning on sticking with DOS, and using Quickbasic 4.5. I want the program to be as simple as possible, at least to begin with. All I want it to do is read the G-code, run the machine, and have a simple, nice-looking display, with big coordinates (I'm using a .bmp file, and Get and Put). I do my program development in the living room, and my milling in the garage, so I don't need tons of capabilities on the controller.

                        I wrote a lot of code in Quickbasic 3.5, 4.0, and some in 4.5. It was IMO one of the best development tools from MS at the time. It was not at any disadvantage to early versions of the MS C compilers. I knew programmers who insisted QB was faster than either Quick C or MS ANSI C.

                        The biggest disadvantage of the MS compilers back then was that they imported the entire runtime library at link time. Borland and others only linked the called functions which made for much smaller exe files.

                        While QB probably cannot compare to the speed and compactness of Borland compilers of that era, you should be able to develop a working control. QB 4.5 fixed all stability (memory related) problems from previous versions.

                        QB 4.5 allows you to develop modules in assembler and link them to your program. This should enable you to perform the necessary tricks with the 8254.

                        I had a few discussions with Doug Yeager about documentation for cncpro. While it is hard for me to believe that anyone could write such a great program without comments, he assured me what he released was all there was.

                        To date, several talented people have started and abandoned the task of cleaning up the code. It is just too convoluted to bother with.

                        Cncpro has the smoothest step/dir output of any software-based gcode interpreter. Match that accomplishment with structured, readable code and you will have many interested followers.

                        Doug Harrison
                      • doug6949
                        ... Mach3 is an adaptation of EMC which was originally developed by NIST. Art Fenerty modified it to compile under MS C (currently a Visual C++ 7.0 overlay).
                        Message 11 of 11 , Sep 12, 2009
                        View Source
                        • 0 Attachment
                          --- In CNCPro@yahoogroups.com, "Eddie Joubert" <edtronix@...> wrote:

                          > I would like to keep in your discussion group as I am having similar thoughts for programming for Vista and am trying to figure out how the MACH3 works
                          >

                          Mach3 is an adaptation of EMC which was originally developed by NIST. Art Fenerty modified it to compile under MS C (currently a Visual C++ 7.0 overlay). He wrote a Ring-0 system driver to get around Microsoft's claim that realtime wasn't possible.

                          The problem with realtime programming isn't that it can't be done - it certainly can. The problem is that the folks who understand it aren't going to divulge what amounts to a cash cow.

                          While Art does not share details about the Ring-0 code, there are a few examples of the technique floating around the web. Hadcon RTM is one example.

                          I have for several years been prodding code writers to come up with an open source version of EMC for windows. So far, no takers.
                        Your message has been successfully submitted and would be delivered to recipients shortly.