## A2 ELEC6 CW - Part 4

##### May 06, 17 - 23:29pm, 1 year and 1 month ago

Apologies for no updates since last year - I was busy.
I’ve finally finished it. Sort of. I decided to call it quits after spending too much time tinkering and trying to get the system to work the way I wanted to. Needless to say I’ve spent more time - and effort, than what was really required. Here’s a video showing what it does.

I know it sounds nothing like a song, mostly because remaking the disc over and over was such a chore I just decided not to do it anymore. It shows the proof of concept so that’s enough.

I would explain how it works in detail, but after reading 20,000 words (exactly) on this thing I’d prefer to keep it succinct. The only interesting thing about it is the binary to frequency set-up - at least to anyway.

Data is read from a binary coded disc ( yes I actually made one, good luck finding a video on one elsewhere ) by a series of photo-diodes linked into a 741 op-amp comparators - pretty basic set up of a set level and analog input to create a digital output depending on which voltage input is greater than the other, this data is sent through an AND gate for to drop / raise the voltage to the supply (since a comparator saturates +/-2V of the supply) which also includes a bit of capacitor filtering to stop some unwanted hysteresis.

The data from this logic gate is then sent into the PICAXE micro-controller, the micro-controller takes the data, and iterates through a loop checking if the input is x, if x then output y. This operation is done by ANDing the inputs so, thus selecting the ones you want and then XORing a combination, i.e.

#DEFINE CN  0XAC

POLL:
CNOTE:
MOVRW   PORTC   ; get the inputs
ANDW    OXO7    ; we only want inputs 0, 1, 2
XORW    0X01    ; check if inputs 1 is high and 2, 3 low
JPZ     CFREQ   ; if true then goto CFREQ
JMP     DNOTE   ; else check if next note

CFREQ:
MOVW    CN      ; move predefined value into register
; which results in a frequency of 261Hz
MOVRW   PORTB
JMP     POLL    ; check again to see if there is a change in inputs

DNOTE:              ; next note ...
...


So now you must be wondering, “How the heck does 0xAC give out 261Hz?”, well here’s how.
This value is sent into an 8-bit DAC, the AD557JN, the DAC converts the digital value into an analog voltage, due to a design choice, the DAC outputs a voltage linear to the input value, so 255 (OXFF) should give out 2.55V. Through testing I found out that this voltage wasn’t high enough to give me the higher frequencies I wanted.

To solve this I interfaced the DAC with a non-inverting amplifier with a gain of 2, so 0xFF was now equal to about 5.1V. To find out what voltages made what frequencies I experimented by incrementing a value to the DAC, and recorded the output frequencies - from there I derived the equation of the line.

The amplifier voltage is passed into a 4046 phase-locked loop, whose function I still don’t really understand, all I know is, voltage in, frequency out. So passing variable voltages into the 4046 gave me variable frequencies, from there I just interfaced the frequency output of the PLL to a MOSFET (IRF630) and then finally into a loudspeaker.

I also added a crude kind of rests system by simply sending a high signal to the IN_H (like a NOT chip enable) pin of the 4046 to turn it off, thus no frequency.

Here’s the schematic:

If you want, you can read my full report which includes 50+ pages of my awful prose testing, design process and source code amongst other things at here.

I’ve learned a lot from this project, mainly that I shouldn’t deal with trying to use sensors, interference and noise is just a pointless pain in the ass - at least programming does exactly what you ask and nothing more. Designing things methodically also helps too, I spent far too much time re-writing things that didn’t work out, next time I’ll write up reports after I’ve made whatever it is I’m trying to do works. Binary disc sucks as well.

I thought about doing an EPQ next year since it’ll mean I’ll only need AAA (as opposed to A*AA) to get into Southhampton Uni., I was thinking of making a sort of SID, just something basic, like a square, saw-tooth, triangle and noise wave generator and then hard-coding some song into an EEPROM chip PWM’ing data into some latches and joining it all together with a summing amp.1, perhaps I’ll have some use for these 16-bit analog multiplexers I have lying around my room after all.

?