please dont rip this site

PIC Microcontoller IO Method

Pink Noise Generator

by Tony Kathro August 2000 [anthonyk at] A few notes about the hardware.

Parts required

	2	pic16f84a-20/p

	1	20 mhz ceramic resonator
	12	470 ohm resistors

decoupling caps, as required.

Construct on perfboard or similar. Plug boards will not do for these frequencies.

The faint of heart may wish to use some decoupling capacitors here and there.

Install software to each Pic (perhaps mark them for ID ) and power up.

To evaluate performance I used an excellent Freeware program called Spectrogram obtained from In particular, this program has a one third octave display which is ideal for pink noise. Using this feature, the flatter the line, the pinker the pink.


The software actually creates a series of steps, each one 3db down from the previous one. This works well in practice for most requirements. Purists may not agree with this and should think about dithering to create steps on steps to smooth the noise spectrum. Understanding the way the software works will show a way or two to achieve this effect.

A word of warning. The pinking filter Pic is working pretty near flat out to do its thing. Almost any thing you add will slow the software execution and reduce the high frequency performance. This should not deter you from improving my software however.

The white noise generator Pic has a little headroom for some extra tasks, but not much. I initialy used it to fill in below 70 Hz but the extra software brought it right to the edge. Out with extra software.

Over clocked 10 MHz Pics show performance changes ranging from the negligible to the gross. As you can see this directly on Spectrogram you could use this to select those Pics that will stand a little over clocking. Just for fun of course. See PS below for other uses.

I came to the conclusion that I would need a 100 MHz Pic in order to do the whole thing on one chip. I am interested to see if there are better ways of generating pink noise, so don't be shy to let me know.

Yes, I know there are faster micro's, but I set out to do it on a Pic and this old fart is stubborn.

Have fun
Tony Kathro


By changing the software to RC from HS and implementing a variable oscillator from 1 MHz down, the slowed pink output displayed on a white led has all the appearance of a candle flame.

For those truly random Christmas lights, use a slow RC oscillator and treat the port pins as a 7x4 matrix (or 6x5) and drive numerous strings of lights via suitable drivers.

;			pinkfilt.asm

;	Pinking filter by Tony Kathro.   August 2000.

; 	+/- 0.5db 60hz to 17,000 hz plus

;	Requires 20 Mhz Pic 16f84 plus a white noise
;	source flat to beyond 20Khz. Use of whitegen.asm
;	recommended.

; Programme is sample and hold of white noise bits.

; Each port bit is held twice the time of the previous bit.	

; All bits (12) are added by commoned 1K ohm resistors.

; Common point is output. See pink.txt for extra info

	LIST    p=16F84 ; PIC16F84 is the target processor

	#include "P16F84.INC" ; Include header file


count1		equ	41
count2		equ	42
count3		equ	43
count4		equ	44
count5		equ	45
count6		equ	46
count7		equ	47
count8		equ	48
count9		equ	49
count10		equ	4a
count11		equ	4b

        	bsf 	STATUS, RP0
		movlw	b'00010000'	;PORTA,4 is input from Noisegen
		movwf	TRISA
		movlw	b'00000000'	;all outputs
		movwf	TRISB
        	bcf 	STATUS, RP0 


	bcf	PORTB,0	
	btfsc	PORTA,4	; Test white noise sample
	bsf	PORTB,0	; Copy to bit0 pin

	btfss	PORTB,0	; equal path length
	nop			; ditto

	incf	count1,f	; Advance counter
	btfss	count1,1	; To bit1 if set
	goto	start		; Round again

	bcf	PORTB,1	; Repeat as above for each bit.
	btfsc	PORTA,4	
	bsf	PORTB,1

	btfss	PORTB,1	
	clrf	count1
	incf	count2,f	
	btfss	count2,1
	goto	start

	bcf	PORTB,2	
	btfsc	PORTA,4	
	bsf	PORTB,2

	btfss	PORTB,2	
	clrf	count2
	incf	count3,f
	btfss	count3,1
	goto	start

	bcf	PORTB,3	
	btfsc	PORTA,4	
	bsf	PORTB,3

	btfss	PORTB,3	
	clrf	count3
	incf	count4,f
	btfss	count4,1
	goto	start

	bcf	PORTB,4	
	btfsc	PORTA,4	
	bsf	PORTB,4

	btfss	PORTB,4	
	clrf	count4
	incf	count5,f
	btfss	count5,1
	goto	start

	bcf	PORTB,5	
	btfsc	PORTA,4	
	bsf	PORTB,5

	btfss	PORTB,5	
	clrf	count5
	incf	count6,f
	btfss	count6,1
	goto	start

	bcf	PORTB,6	
	btfsc	PORTA,4	
	bsf	PORTB,6

	btfss	PORTB,6	
	clrf	count6
	incf	count7,f
	btfss	count7,1
	goto	start

	bcf	PORTB,7	
	btfsc	PORTA,4	
	bsf	PORTB,7

	btfss	PORTB,7	
	clrf	count7
	incf	count8,f
	btfss	count8,1
	goto	start

	bcf	PORTA,0	
	btfsc	PORTA,4	
	bsf	PORTA,0

	btfss	PORTA,0	
	clrf	count8
	incf	count9,f
	btfss	count9,1
	goto	start

	bcf	PORTA,1	
	btfsc	PORTA,4	
	bsf	PORTA,1

	btfss	PORTA,1	
	clrf	count9
	incf	count10,f
	btfss	count10,1
	goto	start

	bcf	PORTA,2	
	btfsc	PORTA,4	
	bsf	PORTA,2

	btfss	PORTA,2	
	clrf	count10
	incf	count11,f
	btfss	count11,1
	goto	start

	bcf	PORTA,3	
	btfsc	PORTA,4	
	bsf	PORTA,3

	btfss	PORTA,3	
	clrf	count11
	goto	start



;	White Noise Generator by Tony Kathro.  Aug 2000

; 	24 bit shift register with max. length feedback taps
;	per the Art of Electronics. (second edition)

;	Output is from any PORTB pin. (yes, any.)

	LIST    p=16F84 ; PIC16F84 is the target processor

	#include "P16F84.INC" ; Include header file

sr1		equ	21 
sr2		equ	22 
sr3		equ	PORTB

        	bsf 	STATUS, RP0
		movlw	b'00000000'	;all outputs
		movwf	TRISA
		movlw	b'00000000'	;all outputs
		movwf	TRISB
        	bcf 	STATUS, RP0

		movlw	b'10101010'
		movwf	sr1		;seed for noise gen.

		movlw 0 		
      	btfsc	sr3, 1 	
        	xorlw 0xFF 		
      	btfsc sr3, 6 
        	xorlw 0xFF 
      	btfsc sr3, 7 
        	xorlw 0xFF 
      	addlw 1 
     		rlf	sr1, f 
     		rlf 	sr2, f 
		rlf 	sr3, f

		goto	start



file: /Techref/microchip/pinknoise.htm, 7KB, , updated: 2001/2/22 14:04, local time: 2024/7/18 04:07,

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> PIC Microcontoller IO Method </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!