by on
Drawing Machines

This really isnt a new drawing machine. It is a replacement of the simstick in dm1 with a dt107 and an atmel Mega8. This is my first crack at the avr servo driving.

 
/*$Revision: 1.3 $

 timings

 The idea here is that the maximum pulse is about 2ms.
 if we map the timings so that 255=2ms then the usable
 servo pulse is between 

 */

#include <io.h>
#include <interrupt.h>
#include <signal.h>

#define NSERVOS 3

uint_8 servodelay[NSERVOS+1]; /* max of 8 */
uint_8 currentservo=0;
uint_8 servoport=0;
uint_8 servoportmask=0x07;
uint_8 skipbeat=10-(NSERVOS/2);

SIGNAL(SIG_OVERFLOW0)        /* signal handler for tcnt0 overflow interrupt */
{
    if (currentservo==NSERVOS) {
        if (!(--skipbeat)) {
            skipbeat=10-(NSERVOS/2);
            servoport=1;
            currentservo=0;
            outp(servodelay[currentservo],TCNT0);
            outp(servoport,PORTB);
        }
    } else {
	servoport<<1;
	currentservo++;
        outp(servodelay[currentservo],TCNT0);
    }
}

int main(void)
{
    outp(0xff,DDRB);         /* use all pins on PortB for output */
    outp((1<<TOIE0), TIMSK); /* enable TCNT0 overflow */
    outp(0,   TCNT0);        /* reset TCNT0 */
    outp(5,   TCCR0);        /* count with cpu clock/1024 */

    led = 1;                 /* init variable representing the LED state */
    sei();                   /* enable interrupts */
    for (;;) {}              /* loop forever */
}

One Response to “Drawing Machine #11”

Leave a Reply

  • (will not be published)