A2 ELEC6 CW

2016-11-04 15:42:00 +0000, 1 year and 9 months ago

Circuit diagram:

+-----+   +----------------+
|Motor+->-+Binary code disc|
+--+--+   +--------+-------+
   |               : +----------+      +---------+   +-------+
   |               +-+Photodiode+--*---+7 bit DAC+->-+Astable|
   |                 +----------+  |   +---------+   +---+---+
   |     +----------+      +-------+-------+             |
   +--<--+3 Bit DAC +---<--+Microcontroller|       +-----+-----+
         +----------+      +---------------+       |Loudspeaker|
                                                   +-----------+

The song is “Cruel Angel Thesis” from Evangelion, it’s in C Minor, 4/4 time signature (alternates to 2/4 in one section), the segment I’m using is at 76BPM.
The notes in C Minor are:
C, D, E♭, F, G, A♭, B♭

Their associated frequencies:

All in hertz.

At 76BPM each note lasts:

27 notes, 360 degree disc, gives us a resolution of:

~13 degrees.

7 different notes, 2 different speeds (1/8, 1/16) , 9 bands.
9 bands, 27 sectors, segments

Using Codewheel V1.1.1 made by Tom Lackamp to generate BCD.
http://www.mindspring.com/~tom2000/Delphi/Codewheel.html
Limitation is we are only allowed 8 bands maximum.

Most of the time the song will be using 1/4 notes, therefore, to overcome the 8 band limit, we can use programming to reset the motor speed back to 1/4 note speed, thus dedicate a single band to 1/8 notes, however, we there must also be a band for 1/16 timing, which must be added manually, this is not much of an issue since there are only 4 1/16 notes in the 27 note segment.

The outmost band will be dedicated to 1/16 note speed.
The second outermost band will be dedicated to 1/8 speed.

           +-----+
           |Start+-----------------<-------------------+
           +--+--+                                     |
              |                                        ^
    +---------+--------+ Yes /----------------------+  |
    |High on 1/16 note?+-->--+Increase motor to 1/16+--+
    +---------+--------+     +----------------------/  |
              |                                        |
              v No                                     |
              |                                        |
     +--------+--------+ Yes /---------------------+   |
     |High on 1/8 note?+-->--+Increase motor to 1/8+---+
     +--------+--------+     +---------------------/   |
              |                                        |
              v No                                     |
              |                                        |
/-------------+-------------+                          |
|Decrease motor speed to 1/4+------------->------------+
+---------------------------/
;================== INIT ===================;
;====== Gets output of BCD, rings 8/9 ======;
;== If not 1/16 or 1/8 then speed is 1/4  ==;
;===========================================;
MOVW 0X03    ; move 1 & 2 to be inputs
MOVWR TRISB  ; set 1 & 2 as inputs

LOOP:
 MOVW 0X00   ; move 0 into W
 MOVWR PORTC ; reset outputs

ON16:
 MOVRW PORTB ; move inputs to W
 ANDW 0X01   ; poll if 1/16 high
 JPZ ON8     ; if low, test if 1/8
 JMP SPEED16 ; if high, inc. mot. to 1/16 spd

ON8:
 MOVRW PORTB ; move inputs to W
 ANDW 0X02   ; poll if 1/8 high
 JPZ SPEED0    ; if low, loop back
 JMP SPEED8  ; if high, inc. mot. to 1/8 spd.

SPEED16:
 MOVW 0X01   ; move 1 into W
 MOVWR PORTC ; put speed to 1/16 note
 JMP LOOP    ; repeat polling loop

SPEED8:
 MOVW 0X02   ; move 2 into W
 MOVWR PORTC ; put speed to 1/8 note
 JMP LOOP    ; repeat polling loop

SPEED0:
 MOVW 0X00   ; move 0 into W
 MOVWR PORTC ; put speed to 1/4 note
 JMP LOOP    ; repeat polling loop

With this, bands:

7 Bit DAC

Range of =

7 bit DAC has binary values up to 128, therefore 1 bit = 519/2^7=4.05Hz, so we have an accuracy of where n is the actual frequency.

Using GXSCC I can find the frequencies of each note:

Using this I found that:

Therefore,

Note Frequency Calculation n location Binary
C 519-519 0 000-0000
D 617-519 24 001-1000
E♭ 692-519 43 010-1011
F 777-519 65 100-0001
G 824-519 76 100-1100
A♭ 925-519 102 110-0110
B♭ 1038-529 128 111-1111


So the score with the frequencies looks like:

Note Frequency Binary Comment
C 519 000-0000  
D 617 001-1000  
E♭ 692 010-1011  
D 617 001-1000  
D 617 001-1000 – Tied to above
E♭ 692 010-1011  
E♭ 692 010-1011  
A♭ 925 110-0110  
G 824 100-1100  
F 777 100-0001  
E♭ 692 010-1011  
F 777 100-0001  
F 777 100-0001 – Tied to above note
A♭ 925 110-0110  
B♭ 1038 111-1111  
E♭ 692 010-1011  
E♭ 692 010-1011 – Tied to above note
D 617 001-1000  
A♭ 925 110-0110  
A♭ 925 110-0110  
F 777 100-0001  
A♭ 925 110-0110  
A♭ 925 110-0110  
B♭ 1038 111-1111  
B♭ 1038 111-1111 – Tied to above note


Downwards is sector, therefore 27 bits on each (No Code) line
Across bits are bands, these go on each new (No Code) line

| 1|1|0|-|0|0|0|1 --> bands
V 0|0|1|-|1|1|0|1
  ... 25 more times.

So the whole song on the BCD is:

0000000111011110001111111
0010011100100111101101111
0101100000000010010000011
0111111010100011110000011
0000000110000110001101111
0010011100100111101101111
0010011001111011100010011

And so the BCD looks like:

The first design of the system:

There are two main systems; analogue voltage to alter frequency, and motor speed controller.

Analogue voltage to alter frequency
Using 7 Photodiodes arranged with an op-amp to amplify output voltage; for the INPUTS to the 7-Bit DAC, 7BD output is analogue, and is used to vary the frequency of the loudspeaker

Motor speed controller
Using 2 more Photodiodes arranged in a similar fashion to the above 7, the output of these 2 PD’s will go into a PICAXE, using the software compiled onto it will change the output depending on the outputs of the PD’s if there is no outputs then it will change the output voltage to a set normal voltage. i.e.

if input == 01 then
  output = 1/8 note speed voltage
elseif input == 10 then
  output == 1/16 note speed voltage
else
  output == 1/4 speed voltage
end
Return?