Tone Generation via PIC17C42

Post here to teach people how to do something.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Chuckt
I practically live here!
I practically live here!
Posts: 1127
Joined: Sun Mar 28, 2010 1:36 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Tone Generation via PIC17C42

Post by Chuckt » Sun Dec 22, 2013 5:40 am

Tone Generation via PIC17C42
A general purpose resonator routine is implemented using a PIC17C42. This routine is used to generate multiple tones. A tone signal is normally generated using extensive table lookup schemes.When a multiple tone signal is desired, each tone must have its own lookup table, thus requiring a large amount of storage space, especially when various frequencies are to be generated. This application note implements tone generation using recursive techniques. The algorithm for a resonator is developed and implemented using PIC17C42.
http://www.microchip.com/stellent/idcpl ... e=en011086

Melody Player
This application generates a melody. It was a little bit
difficult to place the tables because of the program
counter's 8 bits, but I found a way to do this. There are
8 melodies programmed in the PIC12C509 device.
When you push the button a melody is played. Every
melody finishes with "retlw 0x0" which is the mark to
stop playing. When the button is pressed again the
next melody is played.
http://ww1.microchip.com/downloads/en/A ... /4_018.pdf

Chuckt
I practically live here!
I practically live here!
Posts: 1127
Joined: Sun Mar 28, 2010 1:36 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Tone Generation via PIC17C42

Post by Chuckt » Sun Dec 22, 2013 12:53 pm

Chuckt wrote:Tone Generation via PIC17C42
A general purpose resonator routine is implemented using a PIC17C42. This routine is used to generate multiple tones. A tone signal is normally generated using extensive table lookup schemes.When a multiple tone signal is desired, each tone must have its own lookup table, thus requiring a large amount of storage space, especially when various frequencies are to be generated. This application note implements tone generation using recursive techniques. The algorithm for a resonator is developed and implemented using PIC17C42.
The PIC17C42 is EOL (End of Life) and has been replaced by the Pic17C42A which isn't recommended for new applications and the programmer is $200 which isn't good.

"The new recommended replacement is the 18F4220 which is supported by the low cost PICkit programmers."

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Tone Generation via PIC17C42

Post by brad » Mon Dec 23, 2013 6:28 am

The 18f4220 is a great uC! I have used it in a few different projects :)

And to be honest, I didn't even know that microchip had a 17f range...

Garth
I practically live here!
I practically live here!
Posts: 232
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: Tone Generation via PIC17C42

Post by Garth » Mon Dec 23, 2013 9:43 am

I'm working on a project for work that does signal generation by a software phase accumulator, on a PIC16 that has to do a lot of other things at the same time. I think the phase accumulator is a better, simpler way of doing it, and you can do as many signals as you have applicable outputs. I need three, and the 16F74 only has two PWM outputs. I could feed digital outputs to another D/A for the third signal, but all the other pins are taken for other functions, so it sends the instructions for the third channel on a second PIC by SPI.

I'll try to describe this without taking too much time. (It's also at http://en.wikipedia.org/wiki/Numericall ... oscillator .) You have a 256-byte wave (sine in my case) look-up table, a two-byte variable PHASE that you advance at each timed interrupt, and a two-byte variable PHASE_INCR telling how much to advance the first variable at each interrupt. The high byte of PHASE becomes the index value into the table. At each interrupt, you increment the two-byte PHASE variable by the value in PHASE_INCR; so you can see that a higher value in PHASE_INCR will get you through the table faster. For really low frequencies, the high byte of PHASE_INCR will be 0, and you will repeat each step in the table several times before moving on to the next one. For high frequencies where PHASE_INCR is more than 1:0000, you will be skipping table values, at least sometimes. As you approach the Nyquist frequency, you will be skipping nearly half way through the table with each jump. The frequency is directly proportional to the PHASE_INCR value. If you have more than one analog output, you can have a separate pair of 2-byte variables for each output, and run them off the same interrupt. The interrupt rate does not need to change to produce different frequencies. The PWM runs off of timer 2, so each time T2 matches the period register, the buffered value you sent to the PWM gets loaded and the interrupt is caused for the next one. You can have plenty of time to get the next PWM values looked up before the next load, so you won't get glitches. I'm running the PIC at 20MHz, and the sample rate at 39kHz.

I might make an SPI / 65SIB programmable signal generator to sell since I'm doing everything for work anyway and it would not be much extra effort to lay out a board to make the whole signal generator as a complete product.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Tone Generation via PIC17C42

Post by brad » Thu Jan 02, 2014 12:28 am

Sorry I missed this one Garth.

I have to say that I am always very impressed with the incredible things you achieve with assembly!

How is this project coming along - any progress over the Christmas / New Year period?

I'm working with PWM at the moment which I'm putting through a low pass filter to give me digital to analog conversion, it doesn't need to be super accurate but it works well for what I'm using it for :)

Garth
I practically live here!
I practically live here!
Posts: 232
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: Tone Generation via PIC17C42

Post by Garth » Thu Jan 02, 2014 5:29 am

Brad, this is the second project I'm doing with the type of cooperative multitasking. It uses a cyclic executive (which is just an endless loop of CALLs) and no multitasking OS, although the first task in the list can alter the list if it's in RAM, for example to add or delete tasks. For realtime work, it works out much better than preemptive multitasking, and it can be done on very simple hardware (PIC16Fxx in this case). Task switches don't keep interrupts waiting. Each task has what amounts to a state machine so it knows what it's supposed to do or be watching for each time it runs, and it doesn't have to save stacks or anything like that. Most times a task is called, it will see that there's nothing for it to do at the moment, and it gives control back in very few instruction cycles. I would like to do a write-up on it and post it on my website after finishing and posting at least one other higher priority. [Edit: Done.] The program-structure macros make all the difference, making it so much easier to see what you're doing and get something complex going and keep it maintainable and preserve the assembly-language performance advantage, instead of going cross-eyed trying to see through a spaghetti pile of jumps and local labels and so on. I wish I had done it 25 years earlier.

On the current project, I just realized that perhaps I should use a notch filter for the PWM frequency. A description of whatever others have done would be welcome. In the past I've done 5-pole anti-aliasing filters which of course got rid of the PWM "carrier" too, but in this case I don't have to worry about images since they're to high to hear anyway but I would prefer to hold the filters' group delay down. The group delay itself is not really a problem, but the phase difference between channels in the higher frequencies may be a problem due to component tolerances. I guess I'll have to experiment. The first PIC is supposed to control the phase between channels, and I don't want to have to do a calibration in production and put calibration data in EEPROM and hope it remains valid across temperature and as things age. I just don't want to feed the PWM frequency (39 and 78kHz) to the amplifiers since they would try to drive it into a low-impedance load and consume more power and possibly have other undesirable effects too. I'm looking at several possibilites but each has its disadvantages.
Last edited by Garth on Sun Mar 26, 2017 2:38 pm, edited 1 time in total.
Reason: typo, and added a link
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Tone Generation via PIC17C42

Post by brad » Sat Jan 04, 2014 9:36 pm

You've got me quite interested - why would you use a notch filter for the PWM frequency? (i'm guessing a notch filter is still the same as a band stop filter)

And, i've said it before and I'll say it again, you blow my mind with your level of knowledge towards programming, simply amazing!

Garth
I practically live here!
I practically live here!
Posts: 232
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: Tone Generation via PIC17C42

Post by Garth » Sun Jan 05, 2014 6:16 am

brad wrote:You've got me quite interested - why would you use a notch filter for the PWM frequency? (i'm guessing a notch filter is still the same as a band stop filter)
More or less, but the notch ideally has an infinite attenuation at the one narrow frequency (not band of frequencies) of interest. It doesn't have as much phase shift as a sharp, many-order (5th-order, 8th-order, etc.) filter of other types which may have many hundreds of degrees of phase shift in the end of the passband even at frequencies where the amplitude has not started to drop off yet. The sharp low-pass filter is commonly called a "brick-wall" filter, because of its ideal frequency-response graph looking like ─┐.

To back up a bit-- I'm sure you're familiar with the concept of the Nyquist frequency and aliasing. If your PWM (or other D/A) output has a sampling rate that's well below twice the highest frequency you can hear, images of the desired output frequencies wil be audible at higher frequencies as well, adding something unwanted. This is most obvious in cheap talking toys. Although you can understand them, they sound really bad. (This is slightly different from the aliasing problems in digital recording, ie, going the other direction, with an analog-to-digital converter; but in both cases it is often desirable to have a brick-wall filter whose cutoff frequency is just below the Nyquist frequency. For an interesting tid bit, there are a few applications where you can legitimately get away with deliberate undersampling as long as all the signals fall between harmonics of the Nyquist frequency, for example signals in the range of 205-215kHz sampled at 40ksps, since the Nyquist frequency is 20kHz, and 200kHz and 220kHz are harmonics of it. Note however that the jitter must still be tight enough for the higher frequency, as if you were sampling at 440ksps or more.)

In the case of what I'm working on, the images from the aliasing from the PWM rates will be too high to hear. However, consider the situation where you feed 80H to a PWM that has 8-bit resolution. Even if you hold it there for sample after sample, meaning that for the moment there's no signal, you still have a maximum-amplitude square wave, at the PWM frequency! This is what I don't want the power amps trying to reproduce, partly as it would waste battery power in this battery-powered hand-held device (which, BTW, has nothing to do with entertainment, but is related to a medical treatment). I also don't want the IM distortion products the amps might produce with the PWM frequency being there so strong (although I must say I haven't measured those distortion products yet). There aren't enough octaves of separation between the desired audio and the PWM frequency to get by with a simple RC filter, and I was thinking that phase variations between channels could be a problem with high-order LP filters if inexpensive parts were used and no calibration were done in production.

This is why I was considering a notch filter. It would get rid of the PWM "carrier" without much effect on phase of the desired signals. The notch filter would not take the PWM harmonics out, but those would be far enough out to handle with a simpler filter with less phase shift in the desired signal. The square wave as referenced above only has odd harmonics, starting with the 3rd; but the even harmonics, starting with the 2nd, will start showing up when you get away from that 80H input which gives the 50% duty cycle. There are different ways to implement a notch filter.

I have not tried the notch filter yet, but after yesterday's experiments with a 3rd-order (not 5th-order or higher) low-pass filter, I think that will work ok.
And, i've said it before and I'll say it again, you blow my mind with your level of knowledge towards programming, simply amazing!
Thankyou. There are a lot of programming fields where I have no knowledge, but in things that relate to my work where embedded computers are controlling realtime processes in products or on the workbench, I tend to be very resourceful and creative in using existing technologies and tools that I do have to come up with new (at least new to me) ways of solving problems.

And, as you can tell, I also get too much enjoyment from writing. :D
Last edited by Garth on Thu Jan 09, 2014 3:30 pm, edited 1 time in total.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Tone Generation via PIC17C42

Post by brad » Wed Jan 08, 2014 10:28 pm

Will you be putting this project out into the market yourself or is it something that you are working on actually at work? (I'm not sure If I have even asked where you work?)
And, as you can tell, I also get too much enjoyment from writing. :D
You seem to be very good at writing, I have to hand it to you!

Garth
I practically live here!
I practically live here!
Posts: 232
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: Tone Generation via PIC17C42

Post by Garth » Thu Jan 09, 2014 4:57 pm

Will you be putting this project out into the market yourself or is it something that you are working on actually at work?
Yes, it is for work. I myself only sell two things so far, for people making hobby computers at home. One is the 4Mx8 10ns 5V SRAM module (shown larger than life on the front page of my website), and the other is the pair of 1Mx8 EPROMs with the large look-up tables for hyperfast, accurate 16-Bit scaled-integer math, including trig & log functions. It's definitely not a money-maker; in fact, I need to sell a few more of the memory modules to break even on the set-up charges for the memory PCBs. I would like to make some additional hobbyist-friendly, breadboard-friendly modules too though, for use on home-made computers.
(I'm not sure If I have even asked where you work?)
Before the company I work for changed hands around 2007, what I mostly did was to design high-end intercoms--the Cadillac of intercoms--primarily for private aircraft. These tie the headsets (often active noise-cancelling) in with the entertainment and all audio communications. With all the features aircraft owners were asking us for, it became unreasonable to control it all without a computer, so that's where I got into microcontrollers. I've done a few projects now however where the microcontroller actually handled some of the audio, not just the control functions for audio and other circuitry. I do the electronic design, schematics, PCB layout, programming, parts lists, assembly instructions for production, writing user and installation manuals, and technical customer service. (One wears a lot of hats in a tiny company.) Since the time the company was bought out though, it has been morphing, and the new owner also owns two other tiny companies (with just a few people each) and he has me working on projects for those, and in this case it has nothing to do with aircraft. I'm not supposed to talk about what it's for.

The previous company I worked for from 1985-1992 was related, but the owner there had this strange idea that he could get a product assembled ultra-cheap and somehow test the quality into it. As you can imagine, there were a lot of rejects, and a tech was kept busy fixing products that had never been sold yet. This was before SMT, and before automated assembly was practical for lower volumes; so with parts stuffed by hand, there were sometimes errors, particularly when the assemblers were pressed for speed. As a result, I got into automated test equipment (ATE) that allowed a low-wage production worker to quickly to test every detail on a product that should have gotten by with a simple functional test. One of the ATE sets I designed, built, and programmed is shown here.

My other work-related computer work is in controlling experiments on the workbench, taking and analyzing data, etc. with my home-made workbench computer, largely for new-product development. I got into this after seeing what could be done with expensive automated test equipment that took a lot of space, and seeing how I could substitute for a lot of that with a very flexible, small home-made computer with enough I/O types and quantity and speed, and with a highly interactive Forth system that allows very quick development of new applications. Pictures of it pop up here and there in my 6502 primer. My introduce yourself post tells more on how I got into this stuff. Hopefully it's entertaining.
You seem to be very good at writing, I have to hand it to you!
Thankyou. It has taken a lot of practice, and I'm still never satisfied that it's as clear and concise as it should be. If you hadn't asked, I'd feel bad for monopolizing this topic which wasn't mine to start with. I hope someone benefits from it.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Tone Generation via PIC17C42

Post by brad » Sat Jan 11, 2014 2:51 pm

I have mentioned it before, but I would certainly like to one day build my own home-brew computer. I did actually start making a basic ALU a year or so back, but It's one of those projects that have been put on the back burner for now. Kickstarter is keeping me busy at the moment :)

I certainly have hijacked my fair share of topics in this forum, so I really don't mind! I've been on other forums where it is a very big no-no to go off topic. But it's all good fun!

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 3 guests