Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
projects:generator [2015/03/17 10:40] – [Commands] darronprojects:generator [2017/03/07 05:57] (current) – [Schematic] darron
Line 1: Line 1:
-==== dsPIC tone generator ====+==== dsPIC/PIC32 tone generator ====
 <wrap right> <wrap right>
 {{:projects:generator:gen.jpg?200}} {{:projects:generator:gen.jpg?200}}
 </wrap> </wrap>
  
-This is a  project for the dsPIC33FJ128GP802 acting as a tone generator connected to a [[:boards:rpi|Raspberry Pi]].+This is a  project for the dsPIC33FJ128GP802 or PIC32MX150F128B acting as a tone generator connected to a [[:boards:rpi|Raspberry Pi]].
  
 Four separate tones may be generated simultaneously from five different waves and each tone can be any audible frequency. Four separate tones may be generated simultaneously from five different waves and each tone can be any audible frequency.
Line 10: Line 10:
 A tone may also be triggered and it has a standard four stage envelope (ADSR). A tone may also be triggered and it has a standard four stage envelope (ADSR).
  
-This project is still under development and certain aspects may change or features added or removed at any time.+This project is under development and certain aspects may change and features added or removed at any time. 
 === Waves === === Waves ===
  
-These are standard wave types supported for generating tones.+There are standard wave types supported for generating tones.
  
 {{:projects:generator:sine.jpg?100}} {{:projects:generator:sine.jpg?100}}
Line 24: Line 25:
 {{:projects:generator:noise.jpg?100}} {{:projects:generator:noise.jpg?100}}
  
-=== Install ===+=== Schematic ===
  
-First install working [[:tools:xc16|XC16]] compiler.+This is the bare minimum layout required for this project using the dsPIC with integrated audio DAC. We use a [[:boards:rpi|RPi]] for communication and ICSP.
  
-Now build the dsPIC application.+{{:projects:generator:generator.png?200}} 
 + 
 +For PIC32 an external audio DAC is required. Only the CS4334K and PT8211 are supported 
 +at present and are selected at compile time. Connection to either device is as follows. 
 + 
 +<columns 50% 50% ->
 <code> <code>
-hg clone http://hg.kewl.org/pub/generator +CS4334K WITH Vcc = 5V. 
-cd generator + 
-make+PIC32MX150   CS4334K         COMMENT 
 +----------   -------         ------- 
 +PIN 15 RPB6  PIN 4 MCLK      128X OVERSAMPLING CLOCK 
 +PIN 16 RPB7  PIN 3 LRCK      SAMPLE RATE LEFT/RIGHT CLOCK 
 +PIN 17 RPB8  PIN 1 SDATA     SERIAL DATA INPUT 
 +PIN 18 RPB9  PIN 2 DEM/SCLK  DE-EMPHASIS FILTER OFF/ON 
 +PIN 25 SCK1                  UNUSED
 </code> </code>
  
-This is the bare minimum layout required for this project. We will use a [[:boards:rpi|RPi]] for communication with the dsPIC and for ICSP.+</columns>
  
-{{:projects:generator:generator.png?200}}+<columns 50% 50% -> 
 + 
 +<code> 
 +PT8211 WITH Vdd = 5V. 
 + 
 +PIC32MX150   PT8211          COMMENT 
 +----------   -------         ------- 
 +PIN 15 RPB6                  UNUSED 
 +PIN 16 RPB7  PIN 2 WS        SAMPLE RATE LEFT/RIGHT CLOCK 
 +PIN 17 RPB8  PIN 3 SDATA     SERIAL DATA INPUT 
 +PIN 18 RPB9                  UNUSED 
 +PIN 25 SCK1  PIN 1 BCK       SERIAL BIT CLOCK 
 +</code> 
 + 
 +</columns> 
 + 
 +The CS4334K is a far superior device, but the PT8211 is incredibly cheap (15p each). 
 + 
 +=== Firmware === 
 + 
 +For dSPIC First install a working [[:tools:xc16|XC16]] compiler, for PIC32, install [[:tools:xc32|XC32]]. 
 + 
 +Now build the dsPIC/PIC32 applications. 
 +<code> 
 +hg clone http://hg.kewl.org/pub/generator 
 +cd generator/src 
 +make 
 +</code>
  
 [[:projects:pickle|Pickle]] must be installed and configured and when ready we can write the firmware. [[:projects:pickle|Pickle]] must be installed and configured and when ready we can write the firmware.
 +
 +Eg.
 <code> <code>
-p24 lvp program dac/dac.hex+p24 lvp program dspic.hex
 </code> </code>
  
Line 66: Line 107:
 | /      | The accumulator low word is transferred to the voice volume word                               | | /      | The accumulator low word is transferred to the voice volume word                               |
 | %      | The accumulator low word is transferred to the voice square wave duty word                     | | %      | The accumulator low word is transferred to the voice square wave duty word                     |
-| @      | The accumulated is evaluated as the voice ADSR envelope                                        |+| @      | The accumulater low word is transferred to the voice ADSR envelope generator                   |
 | !      | Trigger the voice ADSR envelope                                                                | | !      | Trigger the voice ADSR envelope                                                                |
 | >      | The accumulator low nibble is transferred to the voice selection byte                          | | >      | The accumulator low nibble is transferred to the voice selection byte                          |
Line 79: Line 120:
 </code> </code>
  
-Using `bcfrom the shell we can perform the above like this.+Using GNU bc from the shell we can calculate the above for 440 Hz like this.
 <code> <code>
 printf "%08X=\n" `echo "scale=10; 2^32 / 78000 * 440" | bc` printf "%08X=\n" `echo "scale=10; 2^32 / 78000 * 440" | bc`
Line 103: Line 144:
 === Resources === === Resources ===
 [[http://en.wikipedia.org/wiki/Numerically_controlled_oscillator|NCO]] [[http://en.wikipedia.org/wiki/Numerically_controlled_oscillator|NCO]]
 +