Dirty Encoder Emulator

Hardware questions and issues with the FV-1

Moderator: frank

Post Reply
igorp
Posts: 21
Joined: Tue May 19, 2015 6:10 am
Location: RU

Dirty Encoder Emulator

Post by igorp » Thu Aug 31, 2017 7:31 am

My little contrubution.
Often beginners has no idea how to make program change easy, so this is little snippet to.

It is part of my old AL3201B project
Image

1 potentiometer, 1 MCU Atmel Attiny13.
R20 oftenly not needed, any resistor 1K-20K.
Total budget about $1


Software is pretty dummy

Code: Select all

;************************************************************************
;***           Encoder Emulator v1.2               **********************
;************************************************************************
; by Igor P, nov-2011
;
; PB 0,1,2,3 - out
; pin3 = ADC2 in


; AVR = Z80 Macros
.MACRO di  
        cli
.ENDMACRO  

.MACRO ei  
        sei
.ENDMACRO  


.MACRO jc
        brcs @0
.ENDMACRO  

.MACRO jnc 
        brcc @0
.ENDMACRO  

.MACRO jz  
        breq @0
.ENDMACRO  

.MACRO jnz 
        brne @0
.ENDMACRO  

.MACRO jr  
        rjmp @0
.ENDMACRO  

.def		ZERO=r1		;
.def		ADCbase=r2
.def		ADCtemp=r3	;+ что считали с АЦП

.def		temp=r16	;
.def		temp1=r16	;
.def		temp2=r17

.include "tn13def.inc"

		.cseg
		.org 0
		rjmp RESET 	; Reset Handler
	 	reti			; rjmp EXT_INT0 ; IRQ0 Handler
		reti			; PCINT0 Handler
	 	reti 			; Timer0 Overflow Handler
	 	reti			; rjmp EE_RDY 	; EEPROM Ready Handler
	 	reti			; rjmp ANA_COMP ; Analog Comparator Handler
	 	reti			; Timer0 CompareA Handler
	 	reti			; Timer0 CompareB Handler
 		reti			; rjmp WATCHDOG ; Watchdog Interrupt Handler
 		reti  			; ADC Conversion Handler

;***********************************************
;***********************************************
RESET:	
;***********************************************
;***********************************************

		di	; Main()

;stack setup

		ldi temp1, low(RAMEND)
		out SPL,temp1 	; Set Stack Pointer to top of RAM

		clr ZERO

;clock scale
		ldi temp, 128+6 ;set clock prescale==64  150kHz
		clr temp2
		out CLKPR,temp
		out CLKPR,temp2 ;скорость 0.15 mhz

; delay if PSU buzzing

		clr temp2
dummy2:
		clr temp1
dummy1:
		dec temp
		nop
		nop
		nop
		nop
		nop
		nop
		jnz dummy1
		dec temp2
		jnz dummy2


;port B bits 0,1,2,3 ==output
		ldi temp1,0b00001111	;
		out DDRB,temp1


;bit 4 - ADC2

;ADC Setup	
; no interrups, etc
		ldi temp1, 0b00101111; ain/adc digital inputs off, 
		out DIDR0,temp1		;;;;

    	ldi temp1, 0b00100010 
    	out ADMUX,temp1; внутр опора, left ajust, channel 2

    	ldi temp1,&#40;1<<ADEN&#41;|&#40;1<<ADSC&#41;|&#40;1<<ADATE&#41;|&#40;0<<ADIF&#41;|&#40;0<<ADIE&#41;|&#40;0<<ADPS0&#41;      
		; ADEN = 1 - ADC enable
		; ADIE = 0 no ints 
		; ADSC = 1 auto
		; ADATE = 1 continueous
		; ADPS2..0 = 0 - divider 150Khz/2=75 kHz,
		; ADIF - int flag
    	out ADCSRA,temp1
		ei


;   start main prog ;############################################
;============================---- main loop

MainLoop&#58;	rcall delay
		rcall scan_ADCbase
		jr		MainLoop       ;2

scan_ADCbase&#58;
		in 	ADCtemp,ADCH	;1
		cp ADCbase,ADCtemp	;1	;&#1077;&#1089;&#1083;&#1080; &#1080;&#1079;&#1084;&#1077;&#1085;&#1080;&#1083;&#1072;&#1089;&#1100; &#1073;&#1072;&#1079;&#1072; - &#1087;&#1077;&#1088;&#1077;&#1089;&#1095;&#1077;&#1090;
		mov ADCbase,ADCtemp	;1	

		jz ScanReturn		; &#1077;&#1089;&#1083;&#1080; &#1076;&#1072;&#1085;&#1085;&#1099;&#1077; &#1085;&#1077; &#1080;&#1079;&#1084;&#1077;&#1080;&#1083;&#1080;&#1089;&#1100;, &#1085;&#1080;&#1095;&#1077;&#1075;&#1086; &#1085;&#1077; &#1087;&#1077;&#1088;&#1077;&#1089;&#1095;&#1080;&#1090;&#1099;&#1074;&#1072;&#1077;&#1084;, &#1074;&#1099;&#1074;&#1072;&#1083;&#1080;&#1074;&#1072;&#1077;&#1084;&#1089;&#1103;

		mov temp,ADCbase

		ldi temp2,6		; if &#40;adc < 7&#41; then out_b&#40;6&#41;;
		cpi temp,7
		jc ScanFound

		ldi temp2,2		; else if &#40;adc < 39&#41; then out_b&#40;2&#41;; ...
		cpi temp,39
		jc ScanFound

		ldi temp2,10		; else if &#40;adc < 68&#41; then out_b&#40;10&#41;; ...
		cpi temp,68
		jc ScanFound

		ldi temp2,14
		cpi temp,100
		jc ScanFound

		ldi temp2,15
		cpi temp,128
		jc ScanFound

		ldi temp2,11
		cpi temp,156 ;;;173 ;;;156
		jc ScanFound

		ldi temp2,9
		cpi temp,186
		jc ScanFound

		ldi temp2,13
		cpi temp,215
		jc ScanFound

		ldi temp2,0
		cpi temp,246
		jc ScanFound

		ldi temp2,4	;last
ScanFound&#58; 
		out PORTB,temp2
ScanReturn&#58;
		ret

delay&#58;	; Fcpu ~150 kHz. About 50-100 scans per sec, pause needed abut 1500-3000 tacts.

		ldi temp2,4
dly2&#58;
		clr temp1
dly1&#58;
		dec temp
		jnz dly1	;256x3 tacts
	
		dec temp2
		jnz dly2
		ret
EOP&#58;
;end

"encoder table" is calibrated for 9 effects, but could be reconfigired to 16
(FV-1 ROM and FV-1 external ROM for example)

Compiled with AVR studio or codevision AVR.
I set fuses to 150kHz CPU frequency, to slow down power consumption

Could be flashed via LPT port or cheap programmer like this
https://ru.aliexpress.com/item/1pcs-New ... 87143.html


Next time I can provide another schematic, on STM32F030 to replace both , encoder and i2c EEPROM with one chip

igorp
Posts: 21
Joined: Tue May 19, 2015 6:10 am
Location: RU

Post by igorp » Thu Aug 31, 2017 7:36 am

for example Encoder.hex

Code: Select all

&#58;020000020000FC
&#58;1000000009C018951895189518951895189518956C
&#58;1000100018951895F8940FE90DBF112406E81127DB
&#58;1000200006BD16BD112700270A950000000000003C
&#58;10003000000000000000C1F71A95A9F70FE007BB08
&#58;100040000FE204BB02E207B900EE06B9789425D0AE
&#58;1000500001D0FDCF35B02314232CF1F0022D16E092
&#58;100060000730C8F012E00732B0F01AE0043498F01C
&#58;100070001EE0043680F01FE0003868F01BE00C3909
&#58;1000800050F019E00A3B38F01DE0073D20F010E089
&#58;10009000063F08F014E018BB089514E000270A9505
&#58;0800A000F1F71A95D9F7089554
&#58;00000001FF

Post Reply