Top octave generator on avr (all twelve) has been done

Started by ~arph, August 26, 2018, 03:35:49 PM

Previous topic - Next topic

~arph


anotherjim

I've not seen that, so thanks for the heads up. Might come in useful someday.

Mark Hammer

I still have an unused MK50240 in my parts drawer, waiting for duty, but the AVR approach is clever and one whole hellluva lot cheaper than the original.  If I can get my ass in gear to either use or sell the Mostek chip, I may take a stab at the AVR approach.  Thanks.

MaxPower

What lies behind us and what lies before us are tiny matters, compared to what lies within us - Emerson

Mark Hammer


ElectricDruid

That's clever coding.

I had a go at this problem myself some time ago and realised that looking at *just* the top octave generator chip is the wrong way to approach it. Since you're going to hang twelve divider chips off your top octave generator, you're really building a thirteen-chip solution.
If instead of trying generate all the frequencies, and then produce all the octaves, you generate a single note at all the required octaves (which is far simpler) you can do the whole thing in twelve chips, and run it faster. That AVR solution had to drop the clock rate to 1MHz to make it work, whereas I was able to run at 8MHz. Details here:

https://electricdruid.net/adventures-in-top-octave-generation/

Although I think that AVR is very impressive coding, I think it's solving a problem which doesn't really need to be there.

Incidentally, the other way people have done this is to put the whole lot on an FPGA...that's really using a sledgehammer to crack a nut, but very effective nonetheless!

anotherjim

I think the intention is to replace hens-teeth TOG chips.
However, I don't see that it runs to the instruments master oscillator? If it doesn't, you can't tune it *. Also, many instruments implement vibrato at the master oscillator.
Smaller "spinet" organs and some string machines did run the TOG at around 1Mhz.
Many TOG's were PMOS, and run on 12V or higher supplies, which could be positive ground. Some level shift transistors will be required.
There is perhaps a bit more work to it than programming a cheap AVR?

* Well, you can tune a crystal oscillator on an MCU using a trimmer cap instead of one of the ballast caps, but it's not easy to implement as a convenient panel control.



amptramp

National Semiconductor published a MOS IC catalog that had top octave generators in it.  The problem is, with everything in phase and going through divide-by-2 stages down to the lower octaves it sounds like a Thomas organ - devoid of the slight frequency shifts that give the sound character.  One way to generate a top octave is to do what Hammond did - establish a 185/196 divider which gives you almost the 12th root of 2 frequency separation between adjacent notes.  This can be done with ordinary counters of the 74HC161 or 74HC163 series.  Since you need 185 and 196, you use two 4-bit counters for 185 and two more 4-bit counters for 196 to generate the subsequent frequency.  This replaces the tone wheel generator on a Hammond organ.


If you are still wedded to the idea of a divide-by-2 chain, here is a suggestion: add a phase unlock loop.  That's right, use a PLL chip like a 4046 to generate an output that is nominally divide-by-2 but add in pulses or voltages that make the frequency slightly different.  That way, you get a sound like an analog instrument rather than a digital divider.

One other possibility is to do what I did with an old Minshall Model E organ: replace the dividers with a set of 12 Fairchild UA2240 oscillator/dividers.  This device is internally a 555 oscillator with an 8-stage divider with open-collector outputs:

https://www.datasheetarchive.com/pdf/download.php?id=26chs3ad7a1d5df26b06f97b96ed5be51c30e6&type=M&term=uA2240

It works but you have to maintain tight regulation on the power supply so the oscillators don't influence each other by forcing them into lockstep.

ElectricDruid

Quote from: anotherjim on August 27, 2018, 10:19:18 AM
I think the intention is to replace hens-teeth TOG chips.
For that, there are FPGA-based daughter board solutions. They're not cheap though.
There are two potential applications as I see it - repair of original instruments you might want to keep running, and creation of new instruments using this retro technology. The first requires matching of pin-outs and voltage levels and so forth, whereas the second doesn't.
Personally, I was thinking a modern DIY string synth project, but a combo organ would be cool too.

Quote
However, I don't see that it runs to the instruments master oscillator? If it doesn't, you can't tune it *. Also, many instruments implement vibrato at the master oscillator.
The PIC I used accepts an external clock, which can be variable. I had more trouble with the high frequency VCO than I did with the divider/octave code. A simple tuneable HF oscillator isn't too difficult, but I wanted to be able to add a Pitch Modulation CV.



anotherjim

The AVR/Arduino could be externally clocked too, but I don't know if you can change the internal fuses to do that from the Arduino environment as in this project. Could a 555 make a 20Mhz centred VCO? I've seen somewhere that 20Mhz AVR chips can reliably run up to 25Mhz from an external clock - so you could have a useful range of up & down pitch bend as well as vibrato.

PRR

Old-old thinking:

Philips Technical Review essay on computing musical intervals, 1965:
https://www.americanradiohistory.com/Archive-Philips-Technical-Review/60s/Philips-Technical-Review-1965.pdf
page 176 of PDF (original and PDF pages do not track)
Starts with summary of various tuning schemes. Problems of tuning. Then generation of intervals by digital means. Divisors of 720, 60, and 180 are analyzed.
  • SUPPORTER

anotherjim

I developed one (or have one in development) in an AVR Mega328. It's a modified form of an original idea for an Arduino TOG I found. I coded it all in assembler and along the way found some optimizations. The 13th note, a low C is automatically output from the 8bit timer making the high C since the output compare logic can toggle an output pin while It works set/clear of another.
I have built a 61 note divider board for it, but the keyboard project to test it properly goes slowly with only part of an octave key gating built. Hopefully, this coming winter will get me some free time.
; topoctave2
; guest - openmusiclabs - 4.24.16
; creates 13 squarewaves for the top octave of an organ
; Rewritten for AVR assembler by J W Yale Dec 2018
; For loading into a stock, not Arduino, Atmel Mega328P chip
; Fuses must be set for 16Mhz crystal or a suitable external clock source.
.DEVICE ATmega328
.INCLUDE "m328def.inc"
;Value equates
.EQU FREQ1=239 ; on 8b timer @ 2MHz
.EQU FREQ2=253 ; on 8b timer @ 2MHz
.EQU FREQ3=2145 ; using 16b timer @16MHz, so value is ~8x
.EQU FREQ4=27 ; the rest use the assembler loop
.EQU FREQ5=28 ; and are calculated as:
.EQU FREQ6=29 ; =2*loop_cycles*note_frequency*65536/16MHz
.EQU FREQ7=30 ; there are 34 cycles in the loop
.EQU FREQ8=31
.EQU FREQ9=32
.EQU FREQ10=33
.EQU FREQ11=34
.EQU FREQ12=35
.EQU F3TOP=(FREQ3-1) ; Pre-processed to ensure assembler uses correct High & Low bytes for timer 1
.EQU F3MID=(FREQ3/2)
;
;Begin code
.CSEG
.ORG 0
rjmp RESET
;No interrupts used.
RESET:
;Set stack pointer. However, the stack is not required.
ldi R16, HIGH(RAMEND)
out SPH, R16
ldi R16, LOW(RAMEND)
out SPL, R16
;Begin device setup
; setup t0 for FREQ1
F1:
  ldi R16,0
  sts TIMSK0,R16
  ldi R16,0x73
  out TCCR0A,R16
  ldi R16,0x0A
  out TCCR0B,R16
  ldi R16,(FREQ1-1)
  out OCR0A,R16
  ldi R16,(FREQ1/2)
  out OCR0B,R16
; setup t2 for FREQ2
F2:
  ldi R16,0
  sts TIMSK2,R16
  ldi R16,0x33
  sts TCCR2A,R16
  ldi R16,0x0A
  sts TCCR2B,R16
  ldi R16,(FREQ2-1)
  sts OCR2A,R16
  ldi R16,(FREQ2/2)
  sts OCR2B,R16
; setup t1 for FREQ3
F3:
  ldi R16,0
  sts TIMSK1,R16
  ldi R16,0x33
  sts TCCR1A,R16
  ldi R16,0x19
  sts TCCR1B,R16
  ldi R16,0
  sts TCCR1C,R16
  ldi R16,HIGH(F3TOP)
  sts OCR1AH,R16
  ldi R16,LOW(F3TOP)
  sts OCR1AL,R16
  ldi R16,HIGH(F3MID)
  sts OCR1BH,R16
  ldi R16,LOW(F3MID)
  sts OCR1BL,R16
; turn on output ports
  ldi R16,0x1f
  out DDRB,R16
  ldi R16,0xff
  out DDRD,R16
  ldi R16, 0x3F
  out DDRC,R16
  ldi r18,FREQ9
  ldi r19,FREQ8
  ldi r20,FREQ7
  ldi r21,FREQ6
  ldi r22,FREQ5
  ldi r23,FREQ4
  ldi r24,FREQ12
  ldi r25,FREQ11
  ldi r26,FREQ10
  clr r16
MAIN:
F9: subi r18,1
rol r16
sbrc r16,0
ldi r18,FREQ9
F8: subi r19,1
rol r16
sbrc r16,0
ldi r19,FREQ8
F7: subi r20,1
rol r16
sbrc r16,0
ldi r20,FREQ7
F6: subi r21,1
rol r16
sbrc r16,0
ldi r21,FREQ6
F5: subi r22,1
rol r16
sbrc r16,0
ldi r22,FREQ5
F4: subi r23,1
rol r16
sbrc r16,0
ldi r23,FREQ4
OUTC:
out PINC,r16
clr r16
F12:subi r24,1
rol r16
sbrc r16,0
ldi r24,FREQ12
F11:subi r25,1
rol r16
sbrc r16,0
ldi r25,FREQ11
F10:subi r26,1
rol r16
sbrc r16,0
ldi r26,FREQ10
OUTD:
out PIND,r16
clr r16

    rjmp MAIN
;
.EXIT




PRR

Another Philips essay on notes and intervals:
https://www.americanradiohistory.com/Archive-Philips-Technical-Review/70s/Philips-Technical-Review-1970.pdf
page 348 of PDF
Also some remarks on Bach's "Wohltemperirtes Clavier", doubting the idea that it was composed to support equal-temperment, we were not ready for that yet; but rather another system Bach favored.
  • SUPPORTER