title "White Noise Generator" ; ; Tom Wiltshire for Elecric Druid, March 2008 ; ; This program provides a replacement for the notorious ; MM5837 digital noise source chip. It provides pure ; white noise by outputting random bits at >90KHz. ; This gives a pure noise spectrum to well above audio ; range (3dB dip at 45KHz). ; ; Hardware Notes: ; PIC12F675 running at 4 MHz using internal clock ; ; The hardware is very simple. There are no inputs. ; ; One output ; GP4: NOISE output list p=12f675 ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ;------------------------------ ; Variables ;------------------------------ CBLOCK 0x020 ; LFSR 1, a 31-bit register LFSR1_1 LFSR1_2 LFSR1_3 LFSR1_4 ; LFSR 2, a 23-bit register LFSR2_1 LFSR2_2 LFSR2_3 ; Temporary storage TEMP ENDC ;------------------------------------- ; DEFINE STATEMENTS ;------------------------------------- ; Useful bit definitions for clarity #define ZEROBIT STATUS,Z ; Zero Flag #define CARRY STATUS,C ; Carry Flag #define BORROW STATUS,C ; Borrow is the same as Carry ;---------------------------------------------------------------------- ; Begin Executable Code Segment ;---------------------------------------------------------------------- org 0x000 ; processor reset vector goto Main ; Avoid the interrupt vector ; org 0x004 ; interrupt vector location Main: ; Do the setting up bsf STATUS, RP0 ; Bank 1 ; call 0x3FF ; Retrieve factory calibration value ; movwf OSCCAL ; Store cal value clrf ANSEL ; Turn off analog inputs movlw b'101111' ; GP4 Output, all others unused inputs movwf TRISIO bcf STATUS, RP0 ; Bank 0 clrf GPIO movlw 0x07 movwf CMCON ; Set up initial values of the registers movlw 0x45 movwf LFSR1_1 movlw 0x57 movwf LFSR1_2 movlw 0x9F movwf LFSR1_3 movlw 0xF2 movwf LFSR1_4 movlw 0xD7 movwf LFSR2_1 movlw 0xC8 movwf LFSR2_2 movlw 0x79 movwf LFSR2_3 MainLoop: ; movlw 0x3F ; movwf GPIO ; movlw 0xFF ; movwf TEMP ;DelayLoop: ; nop ; nop ; decfsz TEMP, F ; goto DelayLoop ; clrf GPIO ; movlw 0xFF ; movwf TEMP ;DelayLoop2: ; nop ; nop ; decfsz TEMP, F ; goto DelayLoop2 ; goto MainLoop ; 31-bit LFSR with taps at 31 and 28 ;---------------------------------------------------- swapf LFSR1_4, W ; Get bit 28 movwf TEMP rlf LFSR1_4, W ; Get bit 31 xorwf TEMP, F ; Shift the XORd bit into carry rlf TEMP, F ; Shift the register rlf LFSR1_1, F rlf LFSR1_2, F rlf LFSR1_3, F rlf LFSR1_4, F ; Output the noise bit movf LFSR1_1, W movwf GPIO ; 21-bit LFSR with taps at 21 and 19 ;---------------------------------------------------- rrf LFSR2_3, W ; Get bit 19 movwf TEMP rrf TEMP, F swapf LFSR2_3, W ; Get bit 21 xorwf TEMP, F ; Shift the XORd bit into carry rrf TEMP, F ; Shift the register rlf LFSR2_1, F rlf LFSR2_2, F rlf LFSR2_3, F ; Output the noise bit movf LFSR2_1, W movwf GPIO goto MainLoop ; We never reach here end