PDA

View Full Version : Generating various waveforms with resistive DAC, how to alter pitch?



CuriousOne
- 19th April 2016, 08:33
Hello. I've built simple R-2R 8 bit DAC and hooked it to PIC MCU.

The code looks like this:



DO
PORTB=%00000001
NOP
PORTB=%00000010
NOP
PORTB=%00000100
NOP
LOOP


And so on, this is just a fragment to get idea.

Now the output frequency is determined by MCU clock, and time needed for PORTB operation and nop operation. But how control it in realtime?
I want to hook a simple piano keyboard, and to be able to play at least 2-3 octaves.

PAUSE/PAUSEUS does not provide required precision, is there any way to replace "nop" with adjustable delay in above code?

I'm using PIC16F870, but I can use any other in 16 or 18 family.

HenrikOlsson
- 19th April 2016, 13:03
PAUSE/PAUSEUS does not provide required precision, is there any way to replace "nop" with adjustable delay in above code?
I was going to say that that is prety much what PAUSEUS does but PAUSEUS defaults to 1us "ticks". A workaround solution might be to DEFINE OSC 4 but run the PIC at 40MHz, that way you get 100us resolution. If that's not an option you will have to resort to some ASM type delay loops - which shouldn't be too hard to find.

Apart from that I think what you should do is look at a DDS aproach instead. IIRC I wrote code for a similar application for a user here a while back. Search around and see if you can find it or I will look into it later and post the link (then if it's suitable or not is another question).

/Henrik.

schu4647
- 19th April 2016, 16:03
I would use a Nuvoton ISD3800 Development board which you can control by SPI with your PIC. These are the same devices in greeting cards but much better quality. I have put them on appliances. http://www.digikey.com/catalog/en/partgroup/isd3800-demo-board/40612

schu4647
- 19th April 2016, 16:42
I have one of these. If you are interested I can program it with your wav files and it will be ready to go. Go to my site and buy 3 of my diaper checks and send me a note that you want the ISD3800 board instead. www.thediapercheck.com. I am really just giving you the board for what it cost me. It can be difficult to program.

Art
- 24th April 2016, 02:17
A manual delay should be as fast as asm if you have
defined no clear watchdogs to be inserted in code,
and configure the chip with watchdog off.



delay = 20

...

for count = 0 to delay
next count


For something quicker you could set up a number of delays




Delaytwonops:
@ nop
@ nop
return



Waste four instructions




gosub waste

...

waste:
return