Mini IR Theremin

Questions and Comments on All Projects
ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Mini IR Theremin

Postby ThePyroElectro » Thu Jul 07, 2011 6:31 am

The Mini IR Theremin Project Write-up

If you're a music lover, this Pyro Electro project is for you. Today I show you how to build your own IR Theremin. This style of theremin uses an infrared proximity sensor, a headphone speaker and a PIC micro to create an off-the-shelf style of instrument. The article includes demo vids of me playing simple songs on the theremin.



Questions & Comments?

slavikol
Newbie Pyro
Posts: 1
Joined: Fri Mar 09, 2012 3:38 pm

Re: Mini IR Theremin

Postby slavikol » Sun Mar 11, 2012 4:50 am

Hi. I tried doing this project but I can't seem to make it work.

When I tried to load the hex (downloaded from the IR theremin page) into the PIC, it said that the config bits are missing so I set the oscillator to XT and disabled watchdog timer and low voltage programming. Is this correct?
I then used a 9V battery with LM7805 for the supply. I've connected everything but nothing happens. Not even the start up test sequence. Anything I did wrong? Thanks.

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: Mini IR Theremin

Postby ThePyroElectro » Sat Mar 17, 2012 11:44 pm

Hi slavikol,

That's correct.

It's really weird that the start-up sequence isn't working, that tells me there is a deeper problem somewhere. I would verify that you can load program successfully onto the PIC using MPLAB first, and then try to recompile the .c file for this project, generate your own .hex and re-program the PIC.

If that start-up sequence isn't heard it means either the power supply is messed up, the clock is messed up or the firmware .hex wasn't loaded properly (or I messed up when generating the .hex haha >_<)

harneys
Newbie Pyro
Posts: 3
Joined: Sat Jun 02, 2012 9:49 pm

Re: Mini IR Theremin

Postby harneys » Sat Jun 02, 2012 9:56 pm

hi.. i have read about this project.. as in an example of calculating the timer value per tone, for c4 we will get 9555 counts, may i know in which part in the coding tell about the timer value per tone? and how we can decide the distance range for each note? help me answer, im a very beginner.. thank u thank u thank u..

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: Mini IR Theremin

Postby ThePyroElectro » Sat Jun 02, 2012 10:50 pm

harneys wrote:hi.. i have read about this project.. as in an example of calculating the timer value per tone, for c4 we will get 9555 counts, may i know in which part in the coding tell about the timer value per tone? and how we can decide the distance range for each note? help me answer, im a very beginner.. thank u thank u thank u..


Hi Harney,

The distance is converted into centimeters:

Code: Select all

            //Calculate The Distance Using The Formula: (3027.4/ad_value)^1.2134
         result = pow(3027.4/ad_val,1.2134);   
            //Convert The Distance From Float to Integer
         distance = (int) result;


Then I put that distance value into a switch() statement and evaluate for ranges of distances, for example 5cm-15cm trigger a certain tone.

A digital timer is used to generate the tone you hear from the speaker. A value like:

Code: Select all

timer0_val = 0xED56

is put into the digital timer and then it counts up to 0xFFFF. Every instructions cycle (Fosc / 4) where Fosc is your crystal oscillator (I used 20 MHz). The timer0 is used and a prescalar is set at 1:2, which means the timer counts up +2 at a time instead of +1. For example....if we set the timer to 0xED56....
0xFFFF - 0xED56 = 0x12A9 (or 4777)....divide by 2 = 2388.5 <- because of 1:2 prescalar
Now...we are using a 20 MHz clock....1/(20 MHz / 4) * 2388 = 0.0004776 Seconds
Finally:1/0.0004776 Seconds = 2093.8 Hz which is approximately C7 on a piano.


Hope that helps....

harneys
Newbie Pyro
Posts: 3
Joined: Sat Jun 02, 2012 9:49 pm

Re: Mini IR Theremin

Postby harneys » Sun Jun 03, 2012 9:02 am

thank u.. its help.. but i have one more concern, as what i read here, http://www.pyroelectro.com/projects/mini_ir_theremin/speaker_tone_theory.html 4777 counts is for note C4 how can it be 2093.8Hz which is approximate to C7 note? and is the timer is certainly will count until 0FFF as maximum, or we set it so that it will count 0FFF as maximum? thank u..

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: Mini IR Theremin

Postby ThePyroElectro » Sun Jun 03, 2012 4:18 pm

harneys wrote:thank u.. its help.. but i have one more concern, as what i read here, http://www.pyroelectro.com/projects/mini_ir_theremin/speaker_tone_theory.html 4777 counts is for note C4 how can it be 2093.8Hz which is approximate to C7 note? and is the timer is certainly will count until 0FFF as maximum, or we set it so that it will count 0FFF as maximum? thank u..


Hi Harney,

Wow! How nice I am...I didn't realize I provided the calculation for tones on the article page.

When I explained before:
0xFFFF - 0xED56 = 0x12A9 (or 4777)....divide by 2 = 2388.5 <- because of 1:2 prescalar
Now...we are using a 20 MHz clock....1/(20 MHz / 4) * 2388 = 0.0004776 Seconds
Finally:1/0.0004776 Seconds = 2093.8 Hz which is approximately C7 on a piano.


I forgot to multiply by 2, which represents 1/2 the tone or 1/2 the tone's frequency since a 50/50 -- on/off PWM signal is sent to the speaker. The signal is +5v for 1/2 the frequency length and +0v for half the frequency length. And I also made a mistake...the prescalar acts as a multiplier not divider when working our way backwards....Re-doing the calculation:

0xFFFF - 0xED56 = 0x12A9 (or 4777)....multiply by 2 = 9555 <- because of 1/2 Tone
9555 * 2 = 19110 --- multiply by 2 because of 1:2 prescalar
Now...we are using a 20 MHz clock....1/(20 MHz / 4) * 19110 = 0.003822 Seconds
Finally:1/0.003822 Seconds = 261 Hz which is approximately C4 on a piano.


When the timer reaches 0xFFFF, the timer sets a Flag (or 1 bit) that tells the microcontroller an interrupt has occured. Then special interrupt code runs to tell the speaker output whether it should be +5v or +0v. Really, the code is just switching the output back and forth between +0v and +5v at the current timer0_val setting.

You can connect the speaker output signal to an oscilloscope and change the timer0_val value to see the effect first hand.

harneys
Newbie Pyro
Posts: 3
Joined: Sat Jun 02, 2012 9:49 pm

Re: Mini IR Theremin

Postby harneys » Sun Jun 03, 2012 6:11 pm

thank u.. :)


Return to “Projects”

Who is online

Users browsing this forum: No registered users and 3 guests