Quantcast
Channel: Sound - Audio Projects - PIC Microcontroller
Viewing all 110 articles
Browse latest View live

LED-Guided Piano Instruction using pic microcontoller

$
0
0

[Kay Choe] can’t play the piano. Rather, he couldn’t, until he converted his keyboard to include LED-guided instruction. [Kay] is a microbial engineering graduate student, and the last thing a grad student can afford is private music lessons. With $70 in components and a cell phone, however, he may have found a temporary alternative.

The build works like a slimmed-down, real-world Guitar Hero, lighting up each note in turn. We’ve seen a project like this before, with the LEDs mounted above the keys. [Kay]‘s design, however, is much easier to interpret. He embedded the LEDs directly into the keys, including ones above each black key to indicate the sharps/flats. An Android app takes a MIDI file of your choice and parses the data, sending the resulting bits into an IOIO board via USB OTG. A collection of shift registers then drives the LEDs.

LED-Guided Piano InstructionFor a complete novice, [Kay] seems to benefit from these lights. We are unsure whether the LEDs give any indication of which note to anticipate, however, as it seems he is pressing the keys after each one lights up. Take a look at his video demonstration below and help us speculate as to what the red lights signify. If you’re an electronics savant who wants to make music without practicing a day in your life, we recommend that you check out [Vladimir’s] Robot Guitar.
Filed under: Android Hacks, led hacks, musical hacks

Reposted by RK

September 22 2013

The post LED-Guided Piano Instruction using pic microcontoller appeared first on PIC Microcontroller.


One-chip sound player.

$
0
0

The purpose of this project was to create a sound player that can play high quality sound using nothing but a single chip (plus an SD card for data storage).

The chosen microcontroller was the PIC12F1840. It was chosen because of its fast clock rate (up to 32 MHz). Since microchip PICs have this atrocious property of executing one instruction every four clock cycles, this results in 8MIPS performance.

One-chip sound player.The second reason for the choice was the hardware SPI module – bit-banging SPI is not hard, BUT doing it fast enough to sustain the sound playback would be – the hardware SPI module helps by allowing the SPI clock to be as high at 8MHz without using nearly as much CPU time as bit-banging would. The reset of the circuit design was easy: the PIC outputs a PWM waveform to drive the speaker, which is amplified by a MOSFET, PIC’s SPI controller talks to the SD card, and another GPIO is used to provide power to te SD card allowing it to be powered off and thus letting the circuit sleep in very low power mode (nanowatts of power used). The pic is overclocked using the OSCTUNE register to 33MHz from the stock speed of 32MHz.

The SD card driver is my own work, and supports SD/MMC/SDHC/RS-MMC/HS-MMC/miniSD/microSD/transFlash and whatever others are in that family. Card is initialized at 375KHz (which is within spec), and then the bus is clocked at 8MHz for data reads/writes. The driver is peculiar for a few reasons, mainly because it does not try to be an abstraction between the SPI bus and the caller, thus the driver will init the card, and set it up to stream sectors to the caller. The caller then calls spiByte() directly to read sector data. Every 512 calls, a call to sdNextSector() is needed to notify the SD driver that we want the next sector & properly wait for it to start.

Since there is some time between the end of streaming of one sector and beginning of streaming the other, buffering is used for audio data. The buffer is a simple circular buffer that the audio thread reads from, and the SD thread writes to. When buffer is full, SD thread busy-waits for a slot to open to write data into. Since SD cards do not care how much time passes between clock ticks, this wait can be as long as needed.

One-chip sound player.

The filesystem driver (uFAT) is also my own work, and is a tiny tiny FAT16 implementation. It supports only: short filenames, only FAT16, only read, only root directory. It can: enumerate files’ names/sizes/flags and return the set of sector extents a file occupies. A sector extent is defined as a contiguous range of sectors (a “fragment” in FAT terms). The caller then reads those sectors by itself (allowing the caller to thus avoid the needless layer of abstraction and thus time waste).

 

For more detail: One-chip sound player.

The post One-chip sound player. appeared first on PIC Microcontroller.

NJM2035 – HI-FI Stereo Encoder / Multiplexer using pic microcontoller

$
0
0
Part’s List:
2x 47K
1x 10K
1x 82K
1x 50K POT
1x 33uF
1x 10uF
3x
100nF (104)
1x 100pF (101)
1x 10pF (10)
1x NJM2035 IC
1x 38 KHz Crystal
  Technical Specifications:
Voltage Supply: 1.2V – 3.6V MAX
Current Draw: >3mA
Channel Separation: < 25dB
Signal to Noise Ratio: 67 dB
Operation Temperature: -20 – 75°C
Frequency Range: 20Hz – 15KHz
NJM2035 - HI-FI Stereo Encoder MultiplexerHI-FI Stereo Encoder / Multiplexer
This stereo encoder is the perfect solution for those looking for a high quality stereo sound transmission at a low cost. This stereo encoder produces an excellent crystal clear stereo sound and very good channel separation that can match with many more expensive stereo encoders that are available on the market. It is all possible thanks to a 38KHz quartz crystal that controls the 19kHz pilot tone, so you will never have to calibrate or re-adjust the circuit.
NJM2035 offers superb quality and is manufactured by NJR CORPORATION (JRC), a subsidiary of New Japan Radio, a company that is known as the world’s best manufacturer of high end professional audio semiconductors. This transmitter will work with any mono FM transmitter including TX300 and TX500 which are available on our website. The whole circuit may easily fit on a small 1” x 1.5” printed circuit board allowing to fit in places where space is limited. While building your stereo encoder please take your time and always double check with the schematic to make sure that all the connections are done correctly. If you have any questions, comments or suggestion we will be glad to further assist you.

How Does Stereo Encoder Work?

The stereo encoder consists of three main stages; pre-emphasis, digital encoder and mixer stages.

Pre-emphasis stage is achieved by using two 47K resistors and two 1nF capacitors. This helps to eliminate the noise that is produced during the FM transmission of your audio signal.

Second stage that is built around NJM2035 is a digital encoder. All of its internal blocks except for two audio amplifiers (pins 1 & 14) that act as separators are created using digital circuits. The first digital circuit is a 38KHz oscillator that is generated by using external 38KHz crystal (pin 7), 10pF capacitor (pin 6) and 100pF bypass capacitor (pin 5). Once 38KHz frequency is generated it is then buffered and divided into two 19KHz signals with a phase difference of 180 degrees. Once that is done these two frequencies are connected with two time division MPX digital alternating switchers ,one for each audio channel. Here audio channels are switched between each other with a total frequency of 38KHz. If you would be able to slow this frequency to 1Hz per second you would be able to hear that this all but a trick. During the first half of the second you would hear the left audio channel and during the second half of the second you would hear the right audio channel. Due to the fact that the channels are switched with a fast frequency of 38KHz per second our brain is unable to recognize that these channels are really switched and receives this as a continuous audio signal. At the same time another signal from the 38KHz oscillator is divided by half into 19KHz. This signal is called a PILOT tone because it will help a stereo decoder on the receiver’s part to slice the MULTIPLEX signal (mixed L and R audio channels) and separate them back into left and right audio channels.

The third stage is a mixer that consists of 33uF and 100nF capacitors and 82K and 10K resistors. The role of this circuit is to mix the multiplex subcarrier and pilot signals together. The multiplex subcarrier signal that is coming out from the pin 9 of the NJM2035 IC is the sum and difference of both left and right audio channels that are switched at 38Khz rate. The PILOT signal that is coming out of pin 8 is a 19KHz frequency that is used to distinguish what channel is currently being switched and without which stereo decoding would not be possible.

NJM2035 - HI-FI Stereo Encoder MultiplexerHow to Connect a Stereo Encoder to your FM Transmitter

1) First test your FM Transmitter and make sure that an audio signal is properly transmitted on your desired frequency. Once that is done turn off your transmitter and disconnect its audio inputs.

2) Connect left and right audio outputs from your audio source to the inputs of your stereo encoder.

3) Connect stereo encoder’s MPX output to your transmitter’s input (audio coax cable highly recommended).

4) Turn on your transmitter, FM receiver and audio source (making sure its audio volume is not too loud), and apply voltage supply from a single 1.5 battery cell to a stereo encoder.

5) By now you should hear a stereo sound. Adjust 50K potentiometer making sure your L-R balance is set to the middle and adjust the volume of your audio source making sure an audio signal is as clear as possible.

For more detail: NJM2035 – HI-FI Stereo Encoder / Multiplexer

Current Project / Post can also be found using:

  • hifi audio player using pic microcontroller
  • pic 16f628 program audio volume tone controller

The post NJM2035 – HI-FI Stereo Encoder / Multiplexer using pic microcontoller appeared first on PIC Microcontroller.

Project Ryu Lagger Guitar Pedal Take 3 using pic microcontoller

$
0
0

It has been a quiet period but a very busy period, very active and very fruitful. I will be launching the projectryu.com site soon with tons of free resources for the audio hobbyist.

Getting back to the title of this post, i would like to present a few improvements and a concrete design as a pedal unit.  If you don’t remember about the Lagger project let me put the links below in case you want to check it out.

Project Ryu Lagger – Guitar Effect

Project Ryu Lagger Guitar Pedal Take 2

As a quick summary, Project Ryu Lagger is  a guitar effect pedal that slows down the attack of the guitar (or any instrument for that matter) just like an automated volume pedal.

It does this with a VCA (Voltage Controlled Amplifier), based on the LM13600/LM13700. The fade in envelope is created with a ramp voltage generator that controls the VCA and this generator is triggered by a digital circuit created with a Microchip PI18F1320 MCU.

The digital signal conversion and rectification is explained in a previous article, please read it at the link below:

Project Ryu Lagger Guitar Pedal Take 3

Analog to Digital Signal Rectification

The new version i will present today was adapted as a real pedal with a 3 pole footswitch.

Another change was in the ramp generator replacing the 100k potentiometer with a 10k one since the other two pots in the circuit are 10k. This last change also implies changing some capacitor values. Please refer to the new schematics below:

Project Ryu Lagger Schematics

I am pretty satisfied with this pedal so i have created the PCB for this circuit. The PCB gerber files and the MCU firmware is available for free as usual to subscribers in the next newsletters. If you are not a subscriber yet please register in the form to the right.

Some things to consider if you plan to design your own PCB is good shield of the LM13600/13700 input pins. It is good to surround it with ground plane like below:

You can find the PCB artwork below:

Project Ryu Lagger PCB Art

With the new modifications on the ramp generator circuit the min – max values for attack control is 0.1s and about 1.4s. Below is the ramp waveform measured, this is actually the control voltage of the VCA:

1. full counter clockwise attack pot setting:

Horizontal resolution: 50ms/div

2. full clockwise attack pot setting:

Horizontal resolution: 200ms/div

Below is a screenshot that shows the triggering of the ramp generator, the red trace is the input signal:

As you can see modifying the attack control will adjust the length of the fade in effect. The trigger control adjust the input level above which the ramp generator is triggered. This is to prevent noisy pickups or other pedals used in front of the Lagger to trigger the effect.

The level control adjusts output gain from between +6dB to a max of +24dB so it is capable of a high amount of gain. In the measurement below voltage gain is 14 with an output voltage of 3.6V peak to peak (yellow trace). As you can see there is a bit of saturation happening.

Bellow are two videos showing signal traces using sine waves at 1kHz, one video triggering the effect manually and the other with the effect triggered by the input signal.

Project Ryu Lagger is one of my favorite pedals, i really like this effect and the latest version allows for a great deal of control for the guitarist in sustaining the effect or muting by simply applying muting effects with the palm for example.

 

 

For DIY-ers this project is of moderate complexity but you can subscribe or comment here and i will try to offer any assistance i can. Remember to read the Disclaimer though.

Here is the parts list for this project:

Quantity: References Value
3 C1, C8, C15 4.7u
2 C2, C3 22p
1 C4 10u
1 C5 100u
2 C6, C7 33u
1 C9 4700u
1 C10 10u
2 C11, C12 1000u
5 C13, C14, C16-C18 100n
2 R1, R21 2k
13 R2, R6-R12, R15, R22, R23, R26, R28 10k
1 R3 22k
1 R4 3.3k
4 R5, R29, R31, R32 2.2k
3 R13, R14, R24 100k
1 R18 1k
1 R19 470
2 R20, R25 200
1 R27 5.6k
1 R33 1M
1 U1 LM13700
1 U2 PIC18F1320
1 U3 78L05
1 U4 79L05
2 U5, U6 TL071
2 Q1, Q2 BC549
1 Q3 BC559
2 D1, D2 1N4001
1 D5 LED
1 J3 3 pole foot switch
3 POT1-POT3 10k
1 RV1 1k
1 X1 20Mhz Crystal

I hope you enjoyed reading this article as much as i enjoyed building this pedal and hope to hear from you. To the subscribers, the newsletter will be sent in a few days with Gerber files for PCB and MCU firmware and a couple more details about this construction.

CEATEC 2014 Audio Report, TAD, Pioneer and Technics

This sure was a pretty full period audio-wise. Lots of events all over the world and im glad to say i pushed forward new developments with Project Ryu.

CEATEC Exhibition as expected was held this month and i was looking forward to some new audio products. Looking around i found Tamura Booth showing off their transformers.  In a glass box they also had one of their vintage jewels. Take a look:

Next interesting booth was Pioneer’s. A lot of demo DJ setups and noise but in a corner i found TAD. Nothing new here but i could snap a couple of driver close-ups of the Reference One Speaker System. Also they displayed the Compact Reference CR1MK2 but i got to say i was more attracted by a TL-1601a they had in between.

Next to TAD, Pioneer Professional (… i know)  showed their PA speakers. GS-WAVE Series sure look promising and it is a pretty interesting move for Pioneer to go back to the old days of PA with the concept for this series. Pictured below is the WAV-LENS, mid-high speaker featuring acoustic lens and can do a whooping 145dB peak. Coaxial 2″ drivers, 250W MF and 160W HF and dispersion measures 110 deg H and 50 deg V.

Technics had a very nice room, showing a bit of their history, had 2 listening rooms and they presented their Reference System R1 Series. Products were displayed with inside view as well.

The R1 Series has 3 components, SU-R1 Network Audio Control Player (aka Preamplifier), SE-R1 Stereo Power Amplifier and SB-R1 Speaker System.

Technics SU-R1 Control Amplifier is a 17kg preamp featuring Technics Digital Link (a digital connection between Technics Components) and it is powered by two R core power transformers.

Project Ryu Lagger Guitar Pedal Take 3SE-R1 Stereo Power Amplifier sure looks like it can handle the work load. Normally Technics tried to come up with something different and even if IMHO they really lack imagination naming these technologies, i really appreciate their effort. So SE-R1 features JENO Engine (Jitter Elimination and Noise-shaping Optimization) … [great name guys!], GaN-Fet Driver, (now this is something worth looking into) and LAPC (Load Adaptive Phase Calibration).

The third component of the R1 Series is the SB-R1 speaker system. Now in the past Technics has proven its speaker design ability with some really amazing products. Now on this blog i don’t really want to write subjective impressions on sound so if you are curious about this system go ahead and find a place where you can listen to them. And this goes for any system from any brand, its your money, if your willing to spend it go and decide for yourself.

What i can do is give you some pictures and info on how these systems are built. So back to Technics SB-R1, these speakers claim 100kHz , and they reach that but at -16dB! Oh well… so lets just throw away the specs and look at what we have here.

We have 4 x 16cm drivers in 2 separated bass reflex enclosures (2 per enclosures), we have 1 coaxial MF/HF unit which looks pretty interesting in its own isolated closed enclosure.

Below you can see a cutout through the speaker and some details like crossover board. As you can see there are no exotic components in the crossover.

 

For more detail: Project Ryu Lagger Guitar Pedal Take 3

The post Project Ryu Lagger Guitar Pedal Take 3 using pic microcontoller appeared first on PIC Microcontroller.

Music player built on microcontroller AT91SAM7S256 with ARM core

$
0
0

1. The player allows:

  • playback wav files in stereo format, 22,500Hz freqfency, and 8 bits of resolution,
  • display the song titles,
  • display time of songs,
  • the possibility of stopping (pause) and switch songs,
  • the possibility of change volume (+, -),
  • read data from the MMC memory card inserted in the slot,
  • display current state on the alphanumeric LCD display,
  • the possibility set random order of songs

Music player built on microcontroller AT91SAM7S256 with ARM core

2. For the construction this system could be executed the following elements:

  • microcontroller AT91SAM7S256 from Atmel,
  • alphanumeric LCD display with HD44780 driver ,
  • keyboard with 4 buttons ,
  • memory-card slot,
  • memory card MultimediaMemory Stick (MMC) or optional SD card

Schematic Diagram

3. The principle of operation is quite simple.

a) data from the memory card
| SPI
b) uC SAM7S
| PWM
c) AUX

Ad. a) data from the memory card are reading by the module FatFS. It is necessery bacause on card is used FAT16, FAT32 format. We can playback a wav files, witch are stored on memory card. To store it you can use your PC. Read data are stored up to 2 buffers – it is required because the data may not interfere with the currently playing music.

FatFs module has been written in ANSI C, so it’s independent from the hardware layer and can be easily transferred to different types of microprocessors. Support for the card via the SPI is held by only 3 pins of the microprocessor – lines of data MISO, MOSI, and the clock CLK line. The card requires a power supply voltage of 3.3V, which is equal to the voltage of power processor SAM7S.

Ad. b) In microcontroller timer PIT is set to submit periodic interrupt reqest 22.5 kHz frequency – the frequency of sampling music files. The interrupt checking which data buffer is currently being used and the appropriate values of indexes are transmitted to the buffer registers PWM generator. These values representing 2 channels of sound (left and right). When the index of buffer reach the maximum length of the array the current buffer change, and the flag is set – to allow to write of the next portion data to another buffer.

Ad. c) The player uses 2 independent PWM channels, which are configured to work with a resolution of 8 bits, and the frequency of MCK / 8. The filling PWM generator is dependent on the data collected from the buffer, and is proportional to the voltage output corresponding to the I/O pin of the microcontroller.

The data are processing by uC AT91SAM7S256. It is a 32-bit architecture RISC processor type. SAM7S with ARM ARM7TDMI is one of most successful model.

Music player built on microcontroller AT91SAM7S256 with ARM core Schemetic

Some features of SAM7S256:

  • Internal High-speed Flash – 256 Kbytes Organized in 1024 Pages of 256 Bytes
  • Internal High-speed SRAM – 64 Kbytes
  • Reset Controller
  • AIC- Advanced Interrupt Controller
  • DBGU, 2-wire UART, 2 USART
  • PIT – 20-bit Programmable Counter plus 12-bit Interval Counter
  • RTT – 32-bit Free-running Counter
  • PIO – 32 Programmable I/O Lines
  • SPI – to 16-bit Programmable Data Length
  • One Three-channel 16-bit Counter
  • 1 Four-channel 16-bit PWM Controller
  • 1 8-channel 10-bit Analog-to-Digital Converter
  • Power Supplies – 3.3V

Downloads

Source code

pro-qwerty.com

 

For more detail: Music player built on microcontroller AT91SAM7S256 with ARM core

The post Music player built on microcontroller AT91SAM7S256 with ARM core appeared first on PIC Microcontroller.

Audio spectrum analyzer on PIC32 using pic microcontoller

$
0
0

This simple audio spectrum analyzer is based on PIC32 proto board on PIC32MX360F512L with 320×240px colour LCD (LVC75Z779 Eval Board).  The analyzer can be connected to unamplified audio source like PC’s sound card, MP3 player and so on.

Audio spectrum analyzer on PIC32SSD1928 Module Schematic diagram

The reference voltage of ADC is set to 1V with potentiometer connected to Vref+ pin of PIC32. Voltage of the audio signal could be negative but PIC’s ADC accepts only positive voltages. That’s why another pot is used to add 0.5V DC to audio signal. Finally coupling capacitor is used to isolate DC bias from audio source.

Software

PIC’s ADC is configured to take samples at ~48kHz frequency. When each sample is converted interrupt is generated and sampled value is placed to the buffer. Sampling is completed when 2048 point buffer is full. It takes about 42ms at 48kHz sampling frequency.

Since sampling is done automatically in background we have enough time to do all calculations to previous samples while sampling new ones. First fast Fourier transform is calculated, then the results of FFT are scaled to volts or decibels and finally spectrum is drawn on LCD. At 80MHz it takes about 35ms to do all calculations and draw image on the screen.

Audio spectrum analyzer on PIC32I found FFT algorithm for this project from here. It uses fixed point arithmetic and is written in pure C without any optimisations for PIC32. I have expanded it to be able to calculate 2048 point FFT. It takes about 9ms to calculate 2048 points but I think the performance could be improved by optimizing the code for MIPS architecture.

 

For more detail: Audio spectrum analyzer on PIC32

Current Project / Post can also be found using:

  • audio spectrum analyzer project
  • sound pic

The post Audio spectrum analyzer on PIC32 using pic microcontoller appeared first on PIC Microcontroller.

PIC16C63 Midi controlled Light dimmer

$
0
0

This is Ver2.0 of a finished project.

I usually do projects about the same way every time. Product definition (10 min), Code outline (10 min), Schematic generation, Build prototype, Write code all at one sitting (This one took about 6 hours), Take a copy of the above file, and delete all but a small section. Debug the section, and put it back into the original file. Repeat with other chunks of code until done. Test the program as a whole, Mass produce and be famous (never got to this last step yet).

pic16c63-midi-controlled-light-dimmer

Files in MIDI.ZIP

MIDI20.C Source code for Midi Light dimmer

MIDI.SCH Schematic in OrCad Version IV (Dos version)

MIDI.LIB Library file for OrCad Schematic

MIDI.DXF Schematic in DXF Format

MIDI_SCH.PDF Schematic in Postscript format…. Copy to postscript printer

Download “MIDI.ZIP” PIC16C63 C source code and schematics.

View Schematic for the MIDI light dimmer (PDF File).

View Photo of finished product.

MIDI Nomenclature is as difficult to describe as it is to spell.

Use the terms Port, Channel, Device, and Box like this. You can have lots of MIDI ports (Connectors) on a machine. Each MIDI PORT can have 16 CHANNELS of 127 DEVICES (notes) each. Each light dimmer box consumes 5 DEVICEs: 4 lights and one relay.

As it is, the box has a MIDI interface. There’s an input connector and an output connector. The boxes’ output connector goes downstream to the next boxes’ input connector. There’s a DIP switch in each box to select which of the 16 channels the box will respond to, and what device the first light will respond to. The four lights and the relay will respond to four consecutive device addresses. So… With the dipswitch, you can set a box to be on channel 5, and use devices 32 thru 36. The first light will respond to device 32, the next light device 33, the next 34, and the last 35. The relay will then use device 36. You can connect another box to the first box’s output connector, and set it to respond to channel 5 devices 37-41, (or any channel, any device).

Cakewalk is a MIDI sequencer / editor and it is good. You can just draw the desired intensity of a particular light by drawing a volume envelope of a single note. If you’re in a stage act, and already have Cakewalk doing the sound, that’s the way to go. The existing design can be modified to use standard baud rates, and the RS-232 Electrical interface. Then you can just fire off commands via RS-232. Cakewalk would be a little difficult to interface to if you just wanted to make a home lighting system that responds to opening doors and time of day. For that you just wip something up in Visual basic using standard com port commands.

PIC “Pinewood Derby” style race timer.

PIC based “Pinewood derby style” race track timer. One switch closure starts the race and initiates end of race process. That switch is mounted to the starting gate. When the gate snaps open, the cars start rolling. The gate stays open until the race is over. The act of closing the gate, clears the timers, sets the state machine, and process flags to be ready for the next race. Digital inputs to indicate finish line crossings, one for each of four lanes. A digital high is output by the track when a car shadows the light detector at the finish line. This timer detects the rising edge of this signal. 11 bits of output are consumed by the 8 bit interface to a 2 line, 40 char LCD. There’s plans for a RS232 output to squirt the race times out a serial port. The timer is a great use during car tune-up. It doesn’t seem to add much to a race.

 

For more detail: PIC16C63 Midi controlled Light dimmer

The post PIC16C63 Midi controlled Light dimmer appeared first on PIC Microcontroller.

Record+play fast 1bit sound on a PIC!

$
0
0

BTc “Binary Time constant” algorithm.

A system to record and/or play sound in a bitstream format using just one digital output pin.

This is a sound playback system for a PIC or any other
microcontroller. It uses a clever encoding system to
mathematically model the actual performance of the RC filter
when the signal is encoded. This allows playback of good
quality sound with the absolute minimum software and
hardware.
The RC filter modeling (encoding algorithm) has been
refined to be PIC friendly in binary math, giving the
ability to playback AND RECORD in real time even on
a PIC, even with high rates up to 150+ kbit/sec.

The playback hardware is:
1 PIC digital output pin
1 resistor
1 capacitor
This makes it suitable for adding to small and low-cost
products, providing speech or sound confirmation of
keypress, talking PICs, sound record/playback devices,
etc.

Record+play fast 1bit sound on a PIC!Playback theory:

With this system sound playback only requires an RC
filter, and speaker, earphone socket etc.

Sound playback is very simple and fast. Data is a
single stream of bits, at a constant rate. The PIC
only needs to output one bit, on one pin, at a regular
timed rate to make the sound or speech.
Sound can be added to an existing PIC project, if
one pin and a few instructions each interrupt are
available.

Of course a digital output driving a simple RC filter 
is a common system, used in a number of cheap
applications, but it has drawbacks due to the RC time
constant giving a non-linear waveform.

My BTc algorithm provides a simple fix, and is fast
enough that it can do real-time compensation during
encoding. The math modeling of my encoder maintains a
model of the RC filter with zero accumulated error. If
the bitrate is high enough this system will give
CD-quality audio, due to the PWM effect of the dithering
output, and the RC filter linearity problem is fully
pre-compensated by the math modeling in the encoder.
So the player doesn't need any math. :o)

Encoding theory:

Encoding the sound is the hard part. The stream
of bits must be chosen correctly so that the final
output waveform is as close as possible to the original
waveform.

But the actual output waveform depends on the electrical
characteristics of the RC filter, ohms, uF etc.
We can make the voltage on the RC filter rise by sending
a "1" bit, or fall by sending a "0" bit, but unfortunately
the voltage doesn't rise or fall by an equal amount for
each bit... A form of compensation is needed to make
the filter produce the correct waveform.
Encoding methods.
In order to make the final playback waveform the
closest reproduction of the original waveform I tried
some closed-loop encoding systems, starting with the
two most obvious types of encoding;

REACTIVE:
If sample is higher than math model make a 1 bit.
If sample is lower than math model make a 0 bit.

PREDICTIVE:
In math model, make both bits, "predicting" each
result. Then pick the bit that gives the output
closest to the desired sound sample.

Reactive is easier with only one model needing to 
be generated with each bit. Predictive works a lot
better with all the sound samples I tried. I only used
the predictive algorithm in my encoder program.
Actually, I did support the reactive algorithm too,
but deleted it later when it proved inferior.

The trick is getting a fast and accurate math model
generated, especially fast enough for high speed
bitstream recording/encoding on a PIC.

BTc Encoding Algorithm:

I haven't seen this BTc algorithm used or claimed by
anyone, it is basic encoding methodology, just done
in a clever way to make it very easy and fast on a PIC.

The use of "Binary Time constants" to make the filter
calculation easy is my idea, but as always some other
person may have thought of it before I did. I don't
read enough technical papers these days. :o)

Why BTc??

This was my solution to the problem of math modeling
the RC filter on a PIC, and allows high speed encoding.
To model the RC filter it requires using the "time
constant" or Tc=RC if you remember the math.

Tc=0.63208, and is not of much use to us when trying
to encode each bit in real time unless you have a
Pentium with floating point.

When I was testing different high speed encoding
solutions I came across a very simple idea. Instead of
calculating Tc as given and then doing more calcs to
reduce to a bit speed level suitable for encoding, I
could simply combine the whole lot if a specific Tc
could be assumed.

This allows ONE calculation, a simple binary division,
to do the entire RC math modelling!

If a SPECIFIC time constant is chosen, the TIME for
each bit matches the performance of the RC filter in
a very specific way, ie; the charge on C will rise by
exactly 1/4 or 1/8 or 1/16 during the time that it
takes for one bit! Magic.

Here are the binary time constants, which I have
provided for you;

BTc2  = 0.6931 x Tc   (voltage changes 1/2 each step) 
BTc4  = 0.2877 x Tc   (voltage changes 1/4 each step) 
BTc8  = 0.1393 x Tc   (changes 1/8th etc)                  
BTc16 = 0.0645 x Tc
BTc32 = 0.0317 x Tc
BTc64 = 0.0157 x Tc 

Real world example?
So if we choose the BTc8 system, we know that the
charge (voltage) on the C of our RC filter rises
or falls by 1/8th of the remaining voltage with every
bit in our playback bitstream.

To do this we just need to tune the RC filter values
to our required bitrate. Don't worry too much about
the math, at the bottom of this page I have provided
software that will display your sound wave, encode it
in the way you choose, and display the encoded "math
model" waveform so you can see the actual waveform
you will get on your RC filter. Then it will save the
bitstream as a data file or even as complete PIC code
with the sound data as RETLW table, ready to program
directly into a PIC chip and play the sound back.

The math stuff
Imagine a PIC with 16MHz crystal, giving 4,000,000
instructions/sec. Now using prescaler=0 the timer0
interrupt occurs at 15625 Hz. That is an ideal rate
for our sound playback on a PIC.

Bitrate: 15625 Hz
(We choose BTc8) = 0.1393

So BTc8 = 0.1393 @ 15625 Hz
Therefore Tc = 0.1393 x 15625
Tc = 2177 Hz
Tc = 1 / 2177 = 0.000459 seconds

Tc = RC
R = Tc / C
(let's assume 0.1uF for convenience)

R = 0.000459 / 0.0000001
R = 4595 ohms

Hope that doesn't look too scary, but what we have
done is found that for our desired bitrate at
15625Hz, we can use an RC filter of 4595 ohms and
0.1uF capacitor, and for every bit which occurs
at 15625Hz the voltage on our RC filter will rise
or fall by EXACTLY 1/8th.
Record+play fast 1bit sound on a PIC!Now we can encode in real time on a PIC, and the
main filter math is a couple of add/subtracts and
one divide by 8.

This means we only have to do a handful of very simple
calculations for each bit. We can do the entire
encoding process and produce the encoded bitstream in
real time on a PIC to be played back perfectly on any
other PIC with just a resistor and capacitor. How cool.

Below is an example showing the BTc8 algorithm
encoding a file which contains speech and background
music. This is the BTc8 1bit algorithm on a 19.5kHz
sound. 19.5kHz = 20MHz PIC interrupted every 256
instructions. The RED wave is the encoded waveform,
as you can see it is a decent reproduction of the
original sound waveform (green). The "spiky" points
of the wave are not really important as they will be
filtered by the speaker inductance, or a simple
post-filter if needed. The main thing is that the
AVERAGE of the wave is a decent reproduction of the
original, as that is how your ear will hear it. :o)

You can still see the non-linearity in the encoded
waveform, look anywhere there are a few 1s or 0s
in a sequence. However this does not matter as the
encoding process allows for all errors and still
produces an acceptable reproduction waveform.

 

For more detail: Record+play fast 1bit sound on a PIC!

Current Project / Post can also be found using:

  • audio microcontroller
  • sound by pic12f675

The post Record+play fast 1bit sound on a PIC! appeared first on PIC Microcontroller.


Project Ryu Lagger – Guitar Effect

$
0
0

Do you remember BOSS Slow Gear pedal? If your a guitarist you most likely do or at least you’ve heard of it. It was a great pedal sold from 1979 to 1982 and it was made in Japan. The pedal would cut the attack of your notes giving a swelling sound. It god famous for making the guitar sound kinda like a violin.

I always liked that effect and i even made a clone a few years back. It is based on a 2SK30 JFET and it was a pain getting these transistors. It was a lot of fun though and i though i should make a Project Ryu swell effect pedal and so LAGGER was born!

Project Ryu Lagger – Guitar EffectRecently i worked on a few projects with LM13600/LM13700, one of them is a nice noise gate / compressor unit which i will present at a later date, and i really like the VCAs that can be built with these chips.

To cut the attack of a note and then swell the volume basically we need a triggered fade in effect. This means that we need to control our VCA with a rising voltage using what i call a ramp generator.

In a previous article (Monitoring Amplifier モニターアンプ P3: Speaker Coupling Delay)   i described the circuit of such a ramp generator and it even has a command input. I will use this circuit with the LM13600 VCA all controlled digitally with a PIC18f1320.

The input is fed into an ADC channel to be rectified and averaged in order to detect when a note is played. Once it is detected, the ramp generator is triggered and provides the control voltage for the first VCA.

Project Ryu Lagger – Guitar Effect SchematicLM13600/LM13700 is a dual amplifier the second one is configured as a VCA with manually set control voltage. In the picture below you can see how the circuit works. The top signal is the input signal, the middle signal is the output of the ramp generator and the bottom signal is the trigger.

There is a problem with using the ramp generator circuit this way. The capacitor is discharged too quickly when the trigger is interrupted and this causes an audible thump noise when trigger goes off. Looking below at the schematic we can see the discharge current goes through CE junction of Q1.

 

For more detail: Project Ryu Lagger – Guitar Effect

The post Project Ryu Lagger – Guitar Effect appeared first on PIC Microcontroller.

Audio spectrum analyzer using PIC18F4550

$
0
0

Introduction

This project implements a real-time audio spectrum analyser using a PIC18F4550 8-bit microcontroller. The spectrum frequency analysis is performed by a highly optimised 16-bit Fast Fourier Transformation (FFT) routine coded entirely in C. The output from the FFT is displayed using a 128×64 graphical LCD to allow a real-time view of an audio signal.

Audio Spectrum Analyser

Hardware

In order to perform a FFT calculation on an audio signal it is necessary to prepare the audio so the PIC18F4550 can sample the signal. The PIC18F4550 provides several analogue to digital converters (ADCs) which can be used to measure a voltage from 0V to 5V with 10-bit accuracy (0-1023). A typical audio line-out signal is an analogue wave with a peak-to-peak intensity of 2V centred around 0V (i.e. it is an AC signal ranging from +1 to -1V) as shown by the following oscilloscope trace (from pin W2 of the demo board):

The picture shows a full-volume 5000Hz sine wave generated by a PC. If we were to feed this signal directly to the PIC we would only have a very small range of input voltage (0-0.5V) and also we would only be able to sample the top-half of the signal which would make the FFT incorrect.

In order to correctly sample the signal we have to do two things. Firstly we need to amplify the signal to ensure we can use as much of the 0-5V range as possible. Secondly we have to move the signal’s ground (of 0 volts) to a ‘virtual ground’ of 2.5Vs. This will allow the PIC to sample both the positive and the negative sides of the input signal. To do this the demonstration board uses a simple amplifier IC (the LM386-1). Since the IC is powered from a 0V and 5V power supply it has the handy side-effect of also moving the signal into the middle of our required power range. The LM386-1 was used because it is cheap and simple, however you could use a rail-to-rail opamp to achieve the same thing with a few more external components.

The following oscilloscope trace shows the output signal from the LM386-1 (for the signal shown above), the scope voltage range is set to 5 volts (from pin W3 of the demo board):

The hardware mixes the stereo line-in using two 10K resistors which act as a simple mixer. The signal is then passed to the LM386-1 via a 10K potentiometer which allows the signal strength to be adjusted. Next the LM386-1 amplifier output is passed through a simple RC Filter which rolls off the signal at about 10Khz. The resulting signal is then fed into an ADC pin on the PIC18F4550. The 10Khz filter acts as an ‘anti-aliasing’ filter for the FFT which cannot correctly detect signals with a frequency of greater than 10KHz. An RC filter is a very simple type of filter (and very ineffective) but it was chosen since it is easy to build and only requires 2 passive components. Typically a professional spectrum analyser would implement the anti-alias filter at 80% of the Nyquist frequency for the FFT (see below), but since we are so speed-limited with the PIC this is not possible to do in the design.

The demo board also controls a standard 128×64 dot-matrix LCD as well as 3 LEDs (for testing sound-to-light conversion). In addition there are 2 switches to allow the user to control the LCD’s output depending on what is being measured and how it is to be displayed. The second phono socket allows you to pass-through the input signal to another audio device such as headphones or speakers.

 

For more detail: Audio spectrum analyzer using PIC18F4550

The post Audio spectrum analyzer using PIC18F4550 appeared first on PIC Microcontroller.

Echo MP3 player using PIC18LF452

$
0
0

The EchoMp3 is a small DIY* MP3 player. It’s cheap and of excellent quality.

  • 64, 128, 256, 512MB and 1, 2, 4 GB MMC and SD(HC) cards used as storage.
  • FAT (FAT16) and FAT32 supported.
  • Low power operation with a single AAA (HR03) 1V2 Ni-Mh battery.
  • Runs on a 18LF452 or 18LF458 at 20 MhZ.
  • Up to 256 kBps bitrate at 44,1 kHz supported. VBR may peak at 320 kBps.
  • ID3 v2.3 tags supported.
  • Full user control (volume, track, pause, skip, directory) with a 5-way micro joystick.
  • Real time display of bitrate, sampling rate, elapsed time, songnumber, …
  • LCD contrast adjustable by user.
  • Directory scrolling and file fragmentation support. Directory depth up to 10 accepted.
  • Shuffle (random play) and extended character set enabled.
  • SDHC (High Capacity) Cards now supported. Here are some compatible cards.
  • New: Serial interface control.
  • High quality stereo DAC with a S/N ratio of typ. 87dB.
  • THD of only 0.1% typ.
  • On/Off pushbutton.
  • Software is 100% upgradeable through an RS232 bootloader connector.
  • Voice Recording in PCM-format with same hardware is now possible! Look here for the source code.

* Do It Yourself.

 Schematic & pcb (Eagle 4.11e), hex file available. Player Software Updated on November 24, 2009.

Discontinued as of Feb.2011. Check out our new EchoMp3 v3.1 instead.

Circuit explanation / Getting started:

 MP3 player

PIC18LF45x PLCC The 18LF452 or 18LF458 has to run at 20 MhZ due to the serial interface with the MMC. PLL cannot be used, cause it only works from 4V2. There’s a quarter of ROM-space left for additional applications.
VS1002D: MP3 decoder chip. Enhanced performance compared to the VS1001K. Sounds great! Future enhancements (equalizer and so on) are possible. Thanks to GBUF, no need for large capacitors at the earphone outputs. The chip also has a recording mode!
MMC/SD Royalty-free and open source protocol makes this a great memory to work with. Finding a socket was more difficult. Format the card as FAT (FAT16) or FAT32, then copy them (all at once) to the card (with a cardreader.) Directories may be used. Tagging of your MP3 files can be done with Mp3 tag tools (freeware) and Audio Tags Editor (evaluation period.)
LCDThe LPH7779 (Nokia 3310 LCD) does the job. First four lines are for Artist and Song Title. Fifth line is for songnumber and elapsed time. Sixth line shows sample rate, bitrate and total songtime. Contrast of the LCD can adjusted during boot: hold the vol+ or vol- pressed at power up and the contrast will change accordingly; Settings are stored into the onboard EEPROM. Note that the player will also work without any LCD attached.
ControlsWith the micro joystick, there are 8 user controls available. Two for volume (up & down) , track (left & right) , pause/play (short enter), skip (long enter) and directory scrolling (short enter, then up/down to scroll,  enter to go to the selected directory.) Shuffle is enabled/disabled during boot (hold right at power up, then release.) Serial interface: volume (+ & -) , track (b & n) , pause/play (p), goto tracknumber (ex: 14<ENTER> )
PowerOn/off pushbutton. The MAX1674 DC-DC step-up converter makes it possible to power the whole circuit from only one AAA battery. Some larger SD cards will not boot with a weak battery though. A 1.5V alkaline battery performs better than a 1.2V NiMh.
PCB: We used as much SMD-parts as possible. Number of vias reduced to 54, only the bottom pads of the PLCC-socket need to be soldered. The PCB from our shop is a double sided and 100% connection tested PCB with plated-through-hole connections. All holes are drilled already. PCB size = 82 x 45 mm or 3″29 x 1″77.


Schematics: (eagle-file can be downloaded below.)

Full resolution image (GIF format).

Bill of Materials (Parts List:)

For more detail: Echo MP3 player using PIC18LF452

The post Echo MP3 player using PIC18LF452 appeared first on PIC Microcontroller.

MIDI Chord Button Keyboard Using PIC18f4620 part 1

$
0
0

Every time I sit down to document one of my projects, I try to remember the occasions in the past when looking at the finished web page, I might say ‘Well, I won’t do that again!’, because despite how many drafts I’ve gone through, there is always some aspect of the presentation that fails to measure up to my expectations. Then there’s the question of boredom. I don’t want all my project pages to look exactly alike, just reasonably easy to look at and above all else accurate. Finally, there is the thorny issue of the media itself. Most will realise that these pages are formed using WordPress php code, with a few (very few!) additional pieces of my own php. Presentation using combinations of tables, pictures and lots of text hits size problems which I don’t understand, and moreover, I’m unwilling to spend hours, even days trying to fix, so that there is a finite limit to some post lengths. Rather than pushing the boundaries, and risk the non-presentation of a post, I intend keeping each article instalment reasonably small in future. This will also cut down the loading time from the http://joebrown.org.uk/wp root, which several users have noted has grown a little too long lately!

Hexpad and processor board

The article presented here documents an update of my MIDI Chord Button unit described originally on connectable.org.uk. That article used a 28 pin PIC and was written in PIC assembly language. The unit is still in use, and I decided to build a bigger, hopefully better unit, and write the code in ‘C’.

The unit supports a button matrix of (up to) 20 columns, by 8 rows. Each column is a particular musical key e.g. Ab, and each row a chord type, e.g. Maj7th. A momentary-action shift key provides for a further 8 chord types.

The basic mechanism for scanning the matrix is essentially the same as in the original article, and I don’t want to repeat work, simply for the sake of it. Those of you contemplating basing your own project on the following are urged to read the original article.

For the uninitiated, the 20 key columns are arranged in a virtual ‘circle of fifths’. Which means that if you learn a chord sequence, you can transpose up or down the keyboard and play the same sequence again in a different key. This is very similar to the stradella layout of some Italian chord button accordians, and makes a lot of sense, being relatively easy to play.

There is a table of the columns and keys in the original article, but I’ve provided a sample set of panels for the matrix, so make no excuses for showing the new layout here.

I’ve drawn the unshifted chords available on the LH side of the buttons and the shifted chords available on the RH side of the buttons, this has been repeated at each 4th multiple of the columns only, so as to reduce eye strain!

The small table below shows the layout in schematic form, with the base note value for each key/chord combination (given in hex). Note that the keys marked with the suffix ‘1′ represent an octave key – i.e. a musical key that is also further down the keyboard. Also note that I’ve followed the convention of the accordian and renamed the octave keys for Db as C#, Bb as A# etc. If you are confused, look at the base note values given, these will show the relationships.

Perhaps the best thing about a home-built instrument is that you can mash it up to do exactly what you want, and not what some manufacturer (or people like myself) think you want.

 

For more detail: MIDI Chord Button Keyboard Using PIC18f4620 part 1

The post MIDI Chord Button Keyboard Using PIC18f4620 part 1 appeared first on PIC Microcontroller.

MIDI Chord Button Keyboard Using PIC18F4620 part 2

$
0
0

How chords are formed
Before discussing the processor board and software, it is worth mentioning how the chords are composed. I have provided the table below which shows the installed chords together with the intervals/notes they are constructed from, and examples of each in the key of C major.
Since the source-code is provided, and heavily commented, you can experiment, both with the actual chords installed, their placement on the matrix, and whether they will belong to the default or shifted group.
It is also likely that you may want to ‘open’ out some of the Phat Chords. I have left these in their minimum span configuration.
Slash Chords are not catered for on this unit, but a separate pedal-board is being developed which could be used to provide this facility.

Pitch Wheel inside

Chord Controller Board

The chords are produced by scanning a matrix of switches to produce a unique value for each chord comprising the key value of the chord (eg. C#) and the chord value (e.g. min7). The switch matrix is scanned by the matrix decoder board, (see part 1: MIDI Chord Button Keyboard Using PIC Microcontroller) and when a switch close is detected, a TTL ‘low’ is placed on connector SV7 which is connected to RB1 of the PIC Microcontroller on the Controller board, the schematic of which is shown below.
Note that this controller is dual-purpose. For the chord-controller, IC2 – the CD4073 is not required, and it should not be installed.
On the right, SV1 and SV2 carry the address lines to the matrix decoder, Power is also supplied to the matrix encoder board via SV4. The MIDI OUT signals are provided on SV9, whilst the command hexpad, RESET, and LED connections are via X3,SV3, SV6 and SV8.
Both pitch wheel and velocity/volume control are provided for, and these interface to SV10 and SV11. A connector pin on SV8 allows for the connection of a chord-shift switch.
Note that the Analog channels AN0-AN5, and the digital pins associated with these are not used in the design, but code is installed to read each of the analog signals and may be used to provide extra controller interfaces if desired.

Mapping Commands
As an example of how I mapped my hexpad to control the unit (and the connected synth) I append a code-snippet here of the main interpreter.
First of all the hexpad keyvalue is translated from it’s raw scan value then processed. The digit keys 0-9 are passed on without further action except for designating the keytype as DECIMAL_VAL.
The left-hand-side and bottom-row peripheral keys (except for zero) are assigned specific functions/roles, and control passed to a relevant routine as required.
I will discuss various code routines later.

 

For more detail: MIDI Chord Button Keyboard Using PIC18F4620 part 2

The post MIDI Chord Button Keyboard Using PIC18F4620 part 2 appeared first on PIC Microcontroller.

MIDI Chord Button Keyboard Using PIC18F4620 part 3

$
0
0

Connections
The following table documents the connecting leads and molex pin-header numbers tying the various interfaces together.

HeaderPin no.Signal/FunctionDirectionHeaderPin no.Signal/Function
Chord Controller-SV11RD7——>Matrix Decoder-SV41Chord Sel. C
Chord Controller-SV12RD6——>Matrix Decoder-SV42Chord Sel. B
Chord Controller-SV13RD5——>Matrix Decoder-SV43Chord Sel. A
Chord Controller-SV14RD4——>Matrix Decoder-SV44Note Sel. E
Chord Controller-SV21RD3——>Matrix Decoder-SV11Note Sel. D
Chord Controller-SV22RD2——>Matrix Decoder-SV12Note Sel. C
Chord Controller-SV23RD1——>Matrix Decoder-SV13Note Sel. B
Chord Controller-SV24RD0——>Matrix Decoder-SV14Note Sel. A
Chord Controller-SV41+5v——>Matrix Decoder-SV71+5v
Chord Controller-SV42N/CMatrix Decoder-SV73W (KEYDOWN)
Chord Controller-SV43RB1<——Matrix Decoder-SV72Y (/KEYDOWN)
Chord Controller-SV44GND——>Matrix Decoder-SV74GND
Chord Controller-SV31RC2<——Keypad-X16In S3, 7, 11, 15
Chord Controller-SV32RC1<——Keypad-X17In S2, 6, 10, 14
Chord Controller-SV33RC0<——Keypad-X18In S1, 5, 9, 13
Chord Controller-SV34RE2<——Keypad-X15In S4, 8, 12, 16
Chord Controller-SV83RB4——>Keypad-X11Out S13-S16
Chord Controller-SV84RB5——>Keypad-X12Out S9-S12
Chord Controller-SV85RB6——>Keypad-X13Out S5-S8
Chord Controller-SV86RB7——>Keypad-X14Out S1-S4
Chord Controller-X31/MCLR<——Keypad-X21RESET
Chord Controller-SV61RC3——>Keypad-X22LED1
Chord Controller-SV62RC4——>Keypad-X23LED2
Chord Controller-SV63RC5——>Keypad-X24LED3
Chord Controller-SV64GND——>Keypad-X25GND
Chord Controller-SV65+5v——>Keypad-X26+5v
Chord Controller-SV91TX/RC6 (via 220R)——>DIN SOCKET5MIDI-OUT
Chord Controller-SV92GND——>DIN SOCKETSCRScreen
Chord Controller-SV93+5v (via 220R)——>DIN SOCKET4MIDI-OUT
Chord Controller-SV101+5v——>Volume PotLH TagTop
Chord Controller-SV102AN5<——Volume PotMiddle TagSlider
Chord Controller-SV103GND——>Volume PotRH TagGND
Chord Controller-SV111+5v——>Pitch-wheel PotLH TagTop
Chord Controller-SV112AN6<——Pitch-wheel PotMiddle TagSlider
Chord Controller-SV113GND——>Pitch-wheel PotRH TagGND
Chord Controller-SV71GND——>FTDI-USB RS232-TTL1GND
Chord Controller-SV74RX/RC7<——FTDI-USB RS232-TTL4(PC) TX
Chord Controller-SV75TX/RC6——>FTDI-USB RS232-TTL5(PC) RX

Other connectors are documented on the schematic.
Note that I used a 10K Lin pot for the pitch wheel and 10K log for the volume pot. Although these values are a little on the high side for efficient analog conversion, in practise they work fine.

Chord Button Keyboard Shift Bar

I had originally intended to build the key matrix on a printed circuit board, and this would still be the preferred solution. Two thing deterred me. First, placement of the 6X6mm TACT switches on the PCB using the default outlines supplied in Eagle would have meant a longer keyboard than I wanted, and secondly, My Eagle license only allows Eurocard size boards – meaning there would be 3 boards to join together for the matrix. These two factors represented enough reason to look for another solution. I finally plumped for a single longish piece of matrix board. This allowed the key matrix to have the desired spacing – I fore-shortened the distance between each tag on the switches to 0.2 inches by straightening these close to the body of the switch, which then allowed a switch-to-switch pitch of 0.6 inches.
In solving one problem however, I created another. Mounting the finished board proved fiddly and difficult, and a solution using nylon nuts and bolts had to be adopted – you have been warned!
I terminated the matrix with 2 IDC headers – one 10-way and the other 20-way. Because my finished matrix was hand-wired, I haven’t given connection details for this, and you should refer to the matrix decoder schematic for connection details.
I’ve included a suggested matrix schematic in with the main Eagle project files, should you wish to augment this. A snapshot of this is given below:

Chord Shift Switch
I made provision for plugging in a foot-switch, but as the floor in front of me is rather busy when I’m playing, also provided a handy switch bar on the unit. It is crude but effective, and I’ll briefly describe it here.
A piece of 4mm (0.196 inch) diameter bright drawn mild steel was bent at 90deg each end so to form a bar 305mm (12 inch) long, with two short arms projecting roughly 40mm (~1.5inch) and 50mm. (2 inch) A thread was cut on each arm (I used M4), so that when the bar is placed through two locating holes on the front of the keyboard cabinet, and a washer and nut are threaded onto each arm, the shift bar is approximately 20mm from the keyboard cabinet front. (0.75inch)
Two small metal plates (I used Meccano) are fixed over the two holes on the cabinet front, and 2 collets (4mm) are fixed on each of the shift bar’s arms, which are then pushed into place in the cabinet.

 

For more detail: MIDI Chord Button Keyboard Using PIC18F4620 part 3

The post MIDI Chord Button Keyboard Using PIC18F4620 part 3 appeared first on PIC Microcontroller.

Soundtrack using PIC16F688 Microcontroller

$
0
0

This project uses a microcontroller to
drive a speaker and play one of two
songs: Yakety Sax (the chase song
from the Benny Hill Show) and
Entrance of the Gladiators (the clown
juggling unicycle song).

Soundtrack

The tunes are stored as a series of
distinct notes.  The frequency and
duration of each a note is sent to a
function.  A square wave is generated
based on the inputs.  The nice thing
about this is it can be configured to
play any song you have the sheet
music to.

 

For more detail: Soundtrack using PIC16F688 Microcontroller

The post Soundtrack using PIC16F688 Microcontroller appeared first on PIC Microcontroller.


How to Generate Sound using PWM with PIC Microcontroller

$
0
0

Pulse Width Modulation (PWM) is a technique in which the width of a pulse is modulated keeping the time period of the wave constant. The ON time and OFF time can have any different values in the wave cycles, but the sum of the ON time and OFF time remains same for the entire cycles. PWM is a digital wave that can be generated using digital circuits which are not capable of generating analog voltages. With the help of the modulation of the width of a pulse in a period of the wave, they can generate any required voltage with the help of a proper filter circuits. The filter circuits are used for generating the voltage corresponding to a modulated wave

This feature of the PWM wave is making use in so many digital systems like DC motor control, audio devices, simple decoration light controls etc. The PIC18F4550 has an inbuilt PWM module which can generate continuous PWM waves. This project explores the PWM module of the PIC18F4550 and tries generating a sine wave with frequency in the audible range and then produce that sound in a Loud Speaker with the help of a filter circuit and Loud Speaker driver circuits.

How to Generate Sound using PWM with PIC MicrocontrollerGenerating a sine wave has a great deal of significance since the sine wave is the most natural waveform and all other kind of waves can be generated as a combination of sine waves with different frequencies and amplitude. Generating an audible sine wave and producing its sound in a Loud Speaker is the first step towards using the microcontroller in audio applications like media player, announcement system, record and playback etc.

The PIC18F4550 has four PWM output channels and they are P1A, P1B, P1C and P1D. All of them are capable of generating PWM waves at a time. In this project only one of the PWM channels are using. The P1A is the PWM channel in this particular project. This channel is used to generate the PWM waves which are then applied to a filter circuit to generate the sine wave which is described in a previous project on PIC Sine Wave Generation. In this project a driver circuit is designed to generate the sound of that audible sine wave in a Loud Speaker.

The period of the wave is the sum of the ‘ON time + OFF time’. Duty-cycle is the percentage of time period for which the logic1 voltage exists in a cycle (ON time), starting from the beginning of the cycle.

The PWM is that kind of a wave in which the ON time and OFF time can vary in a cycle but the sum of ‘ON time + OFF time’ remains constant for every cycle.

Period = ON time + OFF time

Duty-cycle = ON time / (ON time + OFF time) = ON time / Period

Increasing the Duty-cycle will increase the voltage at the filter device’s output and decreasing the Duty-cycle will decrease the voltage as well.

In this particular project the sine wave samples are generated periodically by re-writing the value of the CCPR1 register to vary the Duty-cycle. It is done by generating interrupts periodically with another timer module timer0 and changing the CCPR1 value when the code is inside the timer0’s ISR.

The voltage generated by the PWM wave in the interval between two interrupts will be a constant value and this time period can be called ‘sampling period’.

The values of voltage that appears at each sampling period are simply called ‘samples’. The more the number of PWM cycles in a Sampling time, more stable the output voltage will be an example of the sine wave samples is shown following figure in which 10 samples are used to resemble a sine wave. These values when applied to a filter circuit can generate the sine wave at its output by smoothing the step size. The brown line shows the actual sine wave constructed by the filter circuit

The values that should be assigned to the CCPR1 register to generate such consecutive samples are actually taken from a look-up table. The look-up table with 50 samples which is used in this particular project to generate the sine wave is shown in the following;

Sample no. Value Sample no. Value Sample no. Value Sample no. Value Sample no. value
1 52 11 85 21 69 31 28 41 16
2 57 12 86 22 65 32 25 42 18
3 62 13 86 23 61 33 22 43 20
4 66 14 86 24 56 34 19 44 23
5 70 15 85 25 52 35 17 45 26
6 74 16 83 26 48 36 15 46 39
7 77 17 81 27 44 37 14 47 34
8 80 18 78 28 39 38 14 48 38
9 82 19 75 29 35 39 14 49 43
10 84 20 72 30 31 40 15 50 48

 

Time period calculations:

In this section the calculations for the sampling time, PWM Period, PWM Duty-Cycle, frequency of the sine-wave etc. are calculated and the details of the calculations are available in a previous project on PIC Sine Wave Generation

Sampling time:

In this project the TMR0 is set to zero and the timer0 is configured as an 8 bit timer with pre-scale value 1:2 which gives a sampling time;

Sampling time = 40us

PWM period:

In this particular project the PR2 is written to a very small value so as to generate small time periods and hence to get more number of PWM cycles per sampling period.

PR2 = 22

The PWM Period = 2us

Number of PWM cycles per Sample = 20

Thus the timer0 will generate an interrupt after every 20 PWM cycles.

The frequency of the sine wave = 500 Hz

PWM Duty-cycle:

The Duty-cycle in this particular project is varied according to the look-up table whenever a timer0 interrupt occurs. The maximum Duty-cycle (100%) is 2us only since it is the value of the PWM period, hence

#include <p18f4550.h>
#include <timers.h>
//======================= chip config ===================//
#pragma config PLLDIV = 1
#pragma config CPUDIV = OSC1_PLL2
#pragma config FOSC = HSPLL_HS
#pragma config USBDIV = 1
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config VREGEN = OFF
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config CCP2MX = ON
#pragma config PBADEN = OFF
#pragma config LPT1OSC = OFF
#pragma config MCLRE = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
#pragma config ICPRT = OFF
#pragma config XINST = OFF
#pragma config DEBUG = OFF
#pragma config WRTD = OFF
//======================= chip config ===================//
 How to Generate Sound using PWM with PIC Microcontroller Schematic
//LCD Control pins
#define rs PORTBbits.RB4
#define rw PORTBbits.RB3
#define en PORTBbits.RB2
//LCD Data pins
#define lcdport PORTD
#define lcd_port_dir TRISD
void lcd_clear ( void );
void lcd_2nd_line ( void );
void lcd_1st_line ( void );
void lcd_ini ( void );
void dis_cmd ( unsigned char cmd_value );
void dis_data ( unsigned char data_value );
void lcdcmd ( unsigned char cmdout );
void lcddata ( unsigned char dataout );
void delay_ms ( int delay );
//=============== SINE WAVE LOOK UP TABLE ================//
const unsigned char sine[50] = {
 52,57,62,66,70,74,77,80,82,84,85,86,86,
                                  86,85,83,81,78,75,72,69,65,61,56,52,
                              48,44,39,35,31,28,25,22,19,17,15,14,14,
                                  14,15,16,18,20,23,26,30,34,38,43,48
                                         };
//=============== SINE WAVE LOOK UP TABLE ================//
//============================ TIMER 0 ISR =================================//
#pragma interrupt tmr0_interrupt
void tmr0_interrupt(void)
{   static unsigned char i = 0;
   i ++;
   // method to write the sample values into the 10bit CCPR1 register //
   CCP1CON |= ( ( sine [ i ] ) << 5 ) & 0x03;
   CCPR1L = ( sine [ i ] ) >> 2;
   // method to write the sample values into the 10bit CCPR1 register //
       if ( i == 49 )
  i = 0;   else;
   INTCONbits.TMR0IF=0;                            // clearing the timer0 overflow bit
}
//============================ TIMER 0 ISR =================================//
void main ( void )
{unsigned char data1 [] = “EngineersGarage”;
unsigned char data2 [] = ”   Sine Wave   “;
int i = 0;
OSCCON = 0x0C;
lcd_ini (); // LCD initialization
delay_ms ( 200 );
//========================= start up display on LCD ================================//
while ( data1 [i] != ‘\0′ )
{dis_data ( data1 [i] );
delay_ms ( 200 );i++;}i = 0;
lcd_2nd_line ();
while ( data2 [i] != ‘\0′ )
{dis_data ( data2 [i] );
delay_ms ( 200 );
i++;
}
i = 0;
/========================= start up display on LCD ================================//
//============================ PWM SETTINGS ====================================//
TMR2 = 0x0 // setting TMR2 value as 0, start counting from 0
PR2 = 22; // set the PR2 value, to get PWM period of 2us
CCPR1L = 0x00; // setting initial value of CCPR1L as 0
CCP1CON = 0x0C; // select single output with P1A, and mode select bits so as to get
P1A, P1B, P1C and                                    // P1D as active-high
TRISC &= 0xFB; // setting the PWM pin as output
T2CON = 0x04; // both the pre-scalar and post-scalar bits are written for 1:1 with
the timer2 turned on.

 

For more detail: How to Generate Sound using PWM with PIC Microcontroller

The post How to Generate Sound using PWM with PIC Microcontroller appeared first on PIC Microcontroller.

The Super-Simple pocket size mp3 player using PIC16LF877A

$
0
0

It is based on the PIC 16LF877, with plenty of processor time to spare. There is a bare bones assembly version, and a new C version with more features and stability. It uses compact flash cards up to over 100 gigabytes (once they exist) including microdrives. (right now they are about 8 gig)  It uses the vs1001k decoder chip. Super simple, low pin count, built in DAC.

And most importantly, it does indeed play music! Have fun!  Please Email me if you have any specific questions, or just to let me know you are doing this project!

mp3 player
And it’s completely open source!

BEGINNERS BEWARE! This is an upper-intermediate project. You will need things like a PIC programming device and some working knowlege of C and/or assembly language programming, as well as a decent but not huge amount of electronics experience. An oscilloscope doesn’t hurt either. Be warned! It’s an involved project to say the least!

If you are a beginner, give these books and websites a try:

www.parallaxinc.com    www.tech-tools.com   www.microchip.com     www.microchipc.com   www.dontronics.com    www.jameco.com     ccsinfo.com (the midrange compiler is the one I used for this project)

all the Forrest Mims III books, available at radio shack

Practical Electronics for Inventors, by Paul Scherz

and Nuts and Volts Magazine (tower books has it most of the time)

Use at your own risk!

This edition, dec 20, 2001 to Feb. 20, 2003.

By Raphael Abrams, not for commercial use under any circumstances!

————————————————————-

A Friendly Note on PIC Burning

Please remember to clear the BROWNOUT fuse when burning the pic. Otherwise, nothing will work. This is the most common mistake, by far!

————————————————————-

HOW IT WORKS:

The first thing to do is to format the CF card FAT32 and load the root directory with songs. Use a standard reader/writer like the Zio. It plugs into a USB port. Drag and drop the files onto the card in windows. The order that you put them onto the card is the order that they play. All files must be on the root directory, I haven’t added directory support.

 

For more detail: The Super-Simple pocket size mp3 player using PIC16LF877A

Current Project / Post can also be found using:

  • sound generator using a pic micro
  • audio microcontroller programs
  • how to build sound by microcontroller
  • pic audio player

The post The Super-Simple pocket size mp3 player using PIC16LF877A appeared first on PIC Microcontroller.

Voice controlled wheelchair

$
0
0
The Project aims at controlling a wheelchair for handicaps by means of human voice. The speech recognition system is a useful way of implementation and is easy to use programmable speech recognition circuit. Programmable, in the sense that user can train the words (or vocal utterances) he needs the circuit to recognize. This board allows the user to experiment with many facets of speech recognition technology. It has 8-bit data out, which can be interfaced with any microcontroller for further development. Some of interfacing applications which can be made are controlling home appliances, wheelchair movements, Speech Assisted technologies, Speech to text translation, and many more.
Voice controlled wheelchair The wheelchair is controlled by voice commands. This can be moved in forward and reverse direction using geared motors of 60RPM. Also this wheelchair is a type of robot which can take sharp turnings towards left and right directions. This project uses PIC16F72 MCU as its controller. This project uses 6V battery.
In this project, the controlling of a wheelchair by speech will be studied. Commands are spoken into a microphone, followed by an action by the wheelchair. Voice Controlled Wheelchair is a kind of a mobile robot whose motions can be controlled by the user by giving specific voice commands. The speech recognition software running on a PC is capable of identifying the 5 voice commands ‘Run’, ‘Stop’, ‘Left’, ’Right’ and ‘Back’ issued by a particular user. After processing the speech, the necessary motion instructions are given to the mobile platform via a RF link.
The speech recognition software is speaker dependant. The special feature of the application is the ability of the software to train itself for the voice commands(‘Run’, ‘Stop’, ‘Left’, ’Right’ and ‘Back’) for a particular user. The graphical user interface running along with the software provides a very convenient method for the users to train. It also provides many other facilities in operating the wheelchair.
In this project we will be using visual basic (VB6.0) as our speech recognition application.
Voice controlled wheelchair SchematicWORKING
The speech recognition system is a useful and easy to use programmable speech recognition circuit. Programmable, in the sense that user can train the words (or vocal utterances) he needs the circuit to recognize. This board allows the user to experiment with many facets of speech recognition technology. It has 8 bit data out which can be interfaced with any microcontroller for further development. Some of interfacing applications which can be made are controlling home appliances, robotics movements, Speech Assisted technologies, Speech to text translation, and many more.
Robotics has been of interest to mankind for over hundred years. However our perception of robots has been influenced by the media and Hollywood. The vast majority of robots do have several qualities in common. First of all, almost all robots have a movable body. Some only have motorized wheels, and others have dozens of movable segments, typically made of metal or plastic. Like the bones in your body, the individual segments are connected together with joints.

Current Project / Post can also be found using:

  • project microcontroller play mp3 source code c
  • how to connect sound with pic16f877a
  • microcontroller mp3 player project
  • pic mcu mp3 player

The post Voice controlled wheelchair appeared first on PIC Microcontroller.

LM386 based stereo audio amplifier with digital volume control using PIC18F2550

$
0
0

Due to its simplicity (requires minimum external components) and high availability, LM386 is very popular among hobbyists for use in low-voltage audio amplification applications. Most of the time a potentiometer is used at the input side of LM386 to provide a volume control in the output speaker. The potentiometer does not control the gain of the amplifier itself, but it creates a voltage divider network at the input, which in fact controls the fraction of the audio signal that is fed to the amplifier. This project is about a stereo audio amplifier using two LM386 ICs with digital volume control for both left and right speakers. So, how would you control the volume digitally? You are right, by replacing the traditional electro-mechanical form of potentiometers with digital potentiometer chips. This project uses MAXIM’s DS1868 dual digital potentiometer chip and a PIC microcontroller to control the volume of a stereo output from two LM386 ICs.

audio amplifier

Theory

Tons of resources can be found on the internet about LM386 and so I am not going to describe it in detail here. The LM386 IC has got 8 pins which require very few external components to work as a mono amplifier. The circuit below is taken from the datasheet and shows the external components required for constructing a mono-channel audio amplifier with LM386. An external 10K potentiometer at the input is used to control the volume of the output speaker. For a stereo audio amplifier, we need two of this circuit.

The supply voltage range for LM386 is wide (4-18 V). It can be powered with a +9V PP3 battery. For digital volume control feature, we will replace the external 10K potentiometer at the input stage with a digital potentiometer chip. MAXIM’s DS1868 is a dual digital potentiometer chip. Each wiper terminal has 256 positions between the high and low end of the potentiometer. The wiper position is set by an 8-bit control value that is stored into the I/O register of DS1868. The communication with the host microcontroller is done through a 3-wire serial interface. Please read my previous post, ‘How to interface MAXIM’s DS1868 digital potentiometer with a PIC microcontroller‘ for further detail on DS1868.

The block diagram below shows the operation of the stereo audio amplifier with separate volume control for left and right speakers. The DS1868 has two potentiometers and therefore a single chip is enough for two LM386 circuits. The DS1868 is offered in three standard resistance values: 10, 50, and 100 KΩ versions. I am using DS1868-010, which is the 10K version. The stereo audio is fed to the high ends (H0 and H1) of the two potentiometers, while both the low ends are grounded. The input audio signals for the two LM386 stages are derived from the wiper terminals (W0 and W1). The PIC18F2550 microcontroller receives user inputs from tact switches and set the wiper positions accordingly, which in fact control the output volume. A LCD is used to display the individual channel volume level.

Circuit Diagram

The block diagram provided in the the theory section described how this project works. The stereo audio amplification circuit is made up of two LM386 mono amplifiers. The circuit diagram of LM386 based mono amplifier was also described above. The microcontroller, DS1868 digital potentiometer, LCD and tact switches connections are shown below. I am using the StartUSB for PIC board for this project which has got a PIC18F2550 microcontroller loaded with a fast USB bootloader. However, this project can also be done with a smaller size PIC from the mid-range family.

There are three tact switches for user inputs. They are named UP, DOWN, and SELECT in the circuit diagram. UP is to increase and DOWN is to decrease the volume. With the SELECT input, you can set the volume of left and right speakers jointly or individually. As mentioned earlier too, the stereo input is fed to the H0 and H1 pins of DS1868, whereas the L0 and L1 pins are grounded. The two wiper terminals, W0 and W1, are connected to the input pins of the two LM386 mono amplifiers. The LCD is operated in 4-bit mode and the data pins (D4-D7) are connected to RB4 through RB7 port pins. The two LCD control pins, RS and E, are driven by RC6 and RC7 pins of PIC18F2550.

 

For more detail: LM386 based stereo audio amplifier with digital volume control using PIC18F2550

Current Project / Post can also be found using:

  • audio signal analysing using proteus PIC program code
  • voice board interface with pic16f877a

The post LM386 based stereo audio amplifier with digital volume control using PIC18F2550 appeared first on PIC Microcontroller.

Treslie – A 3-phase speaker system for Leslie emulation using PIC18F26K20

$
0
0

This post describes the design and construction of a 3-phase loudspeaker intended for Leslie Speaker emulation. The unit is intended to be driven by a 3-channel audio amplifier The Brute, which in turn is controlled by LEMS, a micro-controller based control system, the construction of which both are described in companion posts.

3-phase speaker system

Companion posts are as follows:

Why Treslie?

Well, I once knew a girl with three heads.. No, you wouldn’t swallow that. But the name I’ve adopted is apparently quite common in the USA as a girl’s name. In fact it isn’t hard and you’ve probably already guessed that’s it’s a conflation of tres – meaning 3 (in spanish etc.) , and lie, the last part of Leslie. Whimsy? Probably, but I needed to call it something.

I’ve lifted a small part of text from the LEMS post which I hope clarifies what is being attempted, and this is given below:

I made the long sides ~12 inches (300mm), and the short sides ~6 inches (150mm). This gives an external angle of 120 degrees between the polar plane of each loudspeaker chassis. With an external height (on my cabinets) of around 27.5 inches (698mm), this gives a total volume of around 2.5 cu ft. Internal volume will be a little less than this, and of course each loudspeaker has only 1/3 of the volume, because of the 3 central partitions.

Each compartment should be made as airtight as possible – mainly due to the use of high-compliance (long-throw) loudspeaker units. These give good bass response in small cabinets, but require near-sealed enclosures, if damaging over-excursion of the loudspeaker cone is to be avoided. I found that screwed joints and the liberal use of a bathroom sealant that remains plastic when dry is the best solution. I advise against the use of glue. Access for maintenance would necessitate damaging a glued cabinet. With the sealant used, panels are easily disassembled, and the sealant can be simply replaced.

As this unit was intended to be experimental, and for use mainly at home with a small 70’s organ, and my guitars, I decided to cater for no more than about 30watts per channel, this keeps costs and size down, and allowed for the purchase of 3 reasonably-priced high-compliance units from my local stockist.
The loudspeakers are complimented with 3 cheap piezo horn units. Information on these suggested the use of series connected 47ohm resistors – I ignored this for the input powers I was using, and connected these up without the series resistor, to no ill effect.

Despite the loudspeaker units being cheap, it is worthwhile incorporating a suitable fuse in series. I used a 20mm, 1.6amp quick-blow item, that will protect the loudspeaker against gross DC flow. Too many loudspeaker designs omit this simple protection, with dire results in the case of accidents. The screw-in fuse-holders were sited on a small panel alongside the loudspeaker 4mm connector sockets.

Materials.
The sides were all made from reclaimed chipboard, mostly melamine-covered, of the type used for kitchen cabinet carcasses and cheap 70’s fitted wardrobes. The top and bottom were made from .. .. new chipboard, and the loudspeaker grilles from … new MDF.

Internal bracing was all new wood – mostly offcuts and scraps 3/4 X 3/4 inch (20mm X 20mm).

The sound absorbent material filling each speaker compartment has one important criteria – it should contain bubbles. Bubbles are just great at absorbing (converting to heat) the sound energy that would otherwise bounce around the hard reflective inner surfaces of the cabinet. Don’t let merchants sell you grossly over-priced ‘wadding’. My experiments have shown good results with: a) The remains of old hollow-fill pillows or cushions; b) Bubble-wrap; and c) Expanded polystyrene. All of these can be hoarded until needed – the latter two are usually used as packing materials for stuff delivered to your door.

 

For more detail: Treslie – A 3-phase speaker system for Leslie emulation using PIC18F26K20

Current Project / Post can also be found using:

  • microchip pic based usb sound card
  • audio saund project
  • audio jack interfacing with pic18f
  • pic microcontroller sd card mp3 player

The post Treslie – A 3-phase speaker system for Leslie emulation using PIC18F26K20 appeared first on PIC Microcontroller.

Viewing all 110 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>