' ########### start ########### ' avr:tiny13 ' ########### end ########### ' ' ****************************************************************** ' A program to test Stepper Motors with a motor Breakoutbox ' 2017-12-19 (c) Paolo Iocco ' ****************************************************************** ' ' Circuit diagram ' --------------- ' ATtiny 13/45/85 Pin map ' +--\/--+ ' +5V>--/100k/----Reset---|1° 8|---Vcc----------------<+5V ' DIR (PB3)<--|2 7|<--TRIMMER (PB2/ADC1) SCK ' STEP(PB4)<--|3 6| NC PB1 MISO ' GND>--------------GND---|4 5|-->LED PB0 MOSI ' +------+ ' ' ------------------------------------------------------------- ' 9.6MHz: ' LFuse: 0x7A; HFuse: 0x1F; ' AVRDude: avrdude -B 10 -c USBasp -p attiny13 -U lfuse:w:0x7a:m -U hfuse:w:0x1f:m ' ' ****************************************************************** ' Chip model #chip tiny13, 9.6 ' pins & direction #define led PORTB.0 #define direzione PORTB.3 #define passo PORTB.4 #define trimmer PORTB.2 dir led out dir direzione out dir passo out dir trimmer in ' variables dim valore as byte dim counter as byte 'Startup routine Startup: valore=0 counter=0 'Main routine Loop: valore=ReadAD(ADC1) ' determinazione della posizione, calcolo della velocità e del senso di rotazione select case valore case <= 120 SET direzione OFF counter=121-valore case >= 135 SET direzione ON counter=valore-134 case else SET passo OFF set direzione OFF counter=0 end select if counter>0 then SET led ON pulseout passo, counter ms SET led OFF wait counter ms end if 'Jump back to the start of the program goto Loop