[Color Computer] [coco] Learning MW C

James Diffendaffer jdiffendaffer at yahoo.com
Sun Aug 13 20:32:02 EDT 2006


--- In ColorComputer at yahoogroups.com, "George's Coco Address"
<yahoo at ...> wrote:
>Should I wish to step these motors faster, I need to also use
> a modified sine wave. I figure four bits per coil could do this. Of
course,
> this takes more time for the computer to do and speed is getting more
> serious.
Can you precalculate a table for the sine wave and then just figure
the starting point in the table to start sending values from?


>  The reason for my desire to learn "C" is so I can build a
subroutine in C
> to do the stepping of the motors. This is why I want to discover a
way to
> use the equivalent of Peek and Poke in C.

The posted PEEK() and POKE() routines will do fine to begin with but
they aren't very "C" like once you learn the language.
The other method where you are actually thinking in pointers is the
norm.  

If it helps any, the following line reads something like this.  Set
the memory location (or address) StepperA points to equal to stepValue. 
*StepperA = stepValue;

If you use a table for a sign wave it would look more like:
*StepperA = stepTable[offset];
 
Then you just put it in a for loop to step through the array. 
Calculation of the sign array is done when you set up the array or
predefined at compile time.  Unless the sign values somehow vary that is.

>  It won't be a large subroutine by any means. My B09 subroutine is,
maybe
> fifty lines of code. I figure C would be a lot faster once it's
compiled.
I don't think B09 is blindingly fast but the compilers that run under
OS9 don't optimize really well either.  Still, it should be up to the job.

Do you need floating point numbers and doest the compiler support them?


>  If it's fast enough, I intend to add some feedback from the
steppers. The
> usual way is with optics. This would require some more peeks, would
slow it
> down and make the process more time consuming. After that, I can begin
> learning to do the math in C and therefore, start migrating from B09
to C
> completely.

Peeks and Pokes are pretty fast and you are only talking about a few
clock cycles.  I'd say the implementation will have a greater impact
on speed.


>  If I could wrap my head around assembly, I would work with that.
But I've
> tried ASM and keep failing. If I knew what I was doing wrong I could
> probably ask a question but I don't have a clue how to work it.
>  I figure maybe C would be easier for me.

Perhaps you should write some assembly and pass it on to someone that
is familiar with the 6809 along with an explanation of what you are
trying to do.  Then they can tell you where you are going wrong.

The problem with assembly is there are a lot of things you need to
learn to piece the entire picture together.  How a processor works,
the instruction set, hexadecimal, controlling hardware and breaking a
project down into small pieces.

When I first started with assembly I didn't really know what I was
doing either.  I modified a BASIC USR routine from a book but that was
about all I could handle until I took an assembly class in college.  
 1hr into the first class (it was 2 1/2 hrs long) it all came together
and I was off doing cool stuff while the rest of the class struggled.  
 
>  Can a C routine be called upon from an interrupt? That would be
great, as
> the optical position sensor could call on the routine. I can solder
that one
> up too.

Yes it can but you want to keep interrupt handlers small and some
assembly is usually required anyway.  A better option would be to set
a flag from the interrupt and test the flag in the main program loop
to see if it's time to update.

>  It seems if it isn't B09, I'm lost
> 
>  I NEED ....."AN IDIOT'S GUIDE TO 6809/OS9 ASSEMBLY( HOW TO WORK THE
> THING)"
> 
>  Then I could begin to learn the microprocessor.
> 
> George

Actually, spending about a half hour with someone that knows assembly
would probably get you off and running.







Brought to you by the 6809, the 6803 and their cousins! 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ColorComputer/

<*> To unsubscribe from this group, send an email to:
    ColorComputer-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the Coco mailing list