This is a multi-part message in MIME format. --Boundary_(ID_mll9sg+5DHZX9O4vCK3zKQ) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Here is an example... ; ; Pseudorandom digital white noise generator for PIC series. ; ; PIC12C508 version written April 7th, 1997 by Scott Rider. ; Questions/comment to chip@aeug.org ; ; PIC12C509 modified version by Antonio L. Benci. 22/03/1999. ; ; This program uses Microchip assembler mnemonics and the Microchip ; MPASM assembler (http://www.microchip.com/). Default config options ; are set in the __FUSES line below: MCLRE off, CP off, WDT off, OSC=INTRC. ; ; _______ _______ ; | \/ | ; (+5V) Vdd --+ 1 8 +-- Vss (GND) ; | | 470 ; X1/CLKI/GP5 --+ 2 7 +-- GP0 (audio out) --/\/\/-- (spkr) ; (not used) | | | 10K 1uF ; X2/CLKO/GP4 --+ 3 6 +-- GP1 --/\/\/--|(-- (line) ; (swt input) | | (swt input) ; GP3/!MCLR --+ 4 5 +-- GP2 ; (swt input) | (PIC12C508) | (swt input) ; +----------------+ ; ; This program generates a continuous stream of white noise through a ; speaker connected (via a 470-ohm series resistor) to pin GP0 of a ; PIC12C509. It demonstrates an easy method for generating a seemingly ; random stream of bits. Hardware folks will probably recognize it as the ; tapped shift register technique covered in the CMOS Cookbook by Don ; Lancaster. ; ; Adapted from the original PIC16C54 (Parallax) version by Scott Edwards. ; ;########################################################################## ; ; Programmable noise weighting added by A L Benci 22/03/1999 ; ; GP1..GP4 are connected to a dip switch which the user can use to select ; 'textures' of 2 to 30. A zero value skips the function. ; ; list p=12c509 radix dec include "p12c509.inc" __FUSES _MCLRE_OFF &_CP_OFF & _WDT_OFF & _IntRC_OSC ;Internal osc. cblock 0x07 ;Variables i ;Loop counter x ;Scratch y ;Scratch zz ;Scratch sr0 ;32 bits of shift register sr1 sr2 sr3 ;/ endc org 0x0 ; ; PIC12C509 cold starts at 03FFF (where it loads a factory-programmed ; internal osc. calibrate value). It then rolls over to 0x0. ; movwf OSCCAL goto start ; ; Subroutines in 12-bit PIC series must go on bottom page of ROM. ; wait loop decfsz i,F goto loop retlw 0 ; ; Main code area traditionally starts at 0x100 on a 12-bit PIC. ; org 0x100 start movlw b'11000000' ;Turn off T0CKI option ;/ movlw b'00000000' ;Preset outputs to come up low movwf GPIO ;/ movlw b'00011110' ;Set the I/O direction (GP3..GP1 as inputs, GP0,GP5 as output) tris GPIO clrf sr0 ;Might as well start with a seed of zero. clrf sr1 clrf sr2 clrf sr3 ;/ ; ; The main loop 'taps' is 24 CPU cycles. At the 4MHz internal clock ; rate, the noise output is operating at a max. rate of about 21KHz. ; taps btfss sr3,6 ;Get bits 28 and 31 for the feedback XOR. bcf x,0 btfsc sr3,6 bsf x,0 ;Bit 31 -> x btfss sr3,3 bcf y,0 btfsc sr3,3 bsf y,0 ;Bit 28 -> y movf y,W ;!(x XOR y) -> carry xorwf x,F btfsc x,0 bcf STATUS,C btfss x,0 bsf STATUS,C ;/ rlf sr0,F ;32-bit shift rlf sr1,F rlf sr2,F rlf sr3,F ;/ ; ; Put a pseudorandom bit out to the speaker. In this example, GPIO bit 0 ; (pin 7 on the PIC12C509) is used. Be sure to use a 470 ohm resistor for ; speaker or 10K or better for input to an op-amp/divider/whatever. ; ; Also, to use all six GP bits for noise, just comment the following 4 ; lines and uncomment the 5th and 6th lines. ; btfss sr3,7 ;line 1 bcf GPIO,0 ;line 2 btfsc sr3,7 ;line 3 bsf GPIO,0 ;line 4 ; movf sr3,W ;line 5 ; movwf GPIO ;line 6 ; ; Uncomment the following 'call wait' to experiment with changing the ; 'texture' of the noise (see 'wait' routine, above). movf GPIO,W ;read switch input andlw b'00011110' ;mask all but swt bits movwf i ;save value btfss STATUS,Z ;is result zero ; call wait ;Optional delay routine to alter sound goto taps ;Ad infinitum... ; ; That's all, folks! ; end Spehro Pefhany wrote: > > At 11:39 PM 4/18/02 +0100, you wrote: > >Any suggestions for a device.. readily accessible.. preferably cheap that > >could be attached to a digital input pin which would provide an > >effectively random input of either 0 or 1? > > If pseudo-random is good enough, you could implement an LFSR PRNG using a > PIC12C508. Cheap > and it only takes ONE part (and about 20 or 30 lines of code). With maximum > length sequence and, > say, 31 bits it would take a long time to repeat. > > Best regards, > > Spehro Pefhany --"it's the network..." "The Journey is the reward" > speff@interlog.com Info for manufacturers: http://www.trexon.com > Embedded software/hardware/analog Info for designers: http://www.speff.com > 9/11 United we Stand Nino. -- ------------------------------------------------------ | Antonio (Nino) L. Benci | | Professional Officer, Electronic Services | | School of Physics & Materials Engineering | | Monash University | | email: nino.benci@spme.monash.edu | | T: 61 3 9905 3649. F: 61 3 9905 3637 | | M: 0414 924 833 | ------------------------------------------------------ --Boundary_(ID_mll9sg+5DHZX9O4vCK3zKQ) Content-type: text/x-vcard; name=Nino.Benci.vcf; charset=us-ascii Content-description: Card for Antonio L Benci Content-disposition: attachment; filename=Nino.Benci.vcf Content-transfer-encoding: 7BIT begin:vcard n:Benci;Antonio L tel;cell:0414 924 833 tel;fax:+61 3 9905 3637 tel;home:0414 924 833 tel;work:+61 3 9905 3649 x-mozilla-html:FALSE url:http://www.physics.monash.edu.au/~ninob org:Monash University;School of Physics & Materials Engineering version:2.1 email;internet:Nino.Benci@spme.monash.edu title:Professional Officer, Electronic Services adr;quoted-printable:;;PO Box 27=0D=0ASchool of Physics and Materials Engineering=0D=0AMonash University;Monash University;VIC;3800;Australia x-mozilla-cpt:;10672 fn:Antonio L Benci end:vcard --Boundary_(ID_mll9sg+5DHZX9O4vCK3zKQ)-- -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics