Searching \ for 'Candle flicker algorithm' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=candle+flicker+algorithm
Search entire site for: 'Candle flicker algorithm'.

Truncated match.
PICList Thread
'Candle flicker algorithm'
1999\01\11@145800 by Shahid Sheikh

picon face
Hi all,

I'm using a 12C508 to control the lights in a HO scale model church. On one
of the desks in the church, I was planning on putting a real tiny bulb and
make it flicker like a candle. Anyone has an algorithm handy for making a
bulb flicker like a candle?

The PIC will be doing other tasks as well like understanding an incoming
datastream of NMRA DCC but its going to have a constant program loop. It
also turns on a 5 W tube and a several other bulbs on the inside and out.

I'm also thinking of controlling the transistor that energizes the
transformer for the tube directly from the PIC. Anyone knows what frequency
those transformers work at? Its from a broken battery operated flash/tube
light.

Shahid

1999\01\12@082252 by paulb

flavicon
face
Shahid Sheikh wrote:

> I'm using a 12C508 to control the lights in a HO scale model church.
> On one of the desks in the church, I was planning on putting a real
> tiny bulb and make it flicker like a candle.

 A yellow LCD might be good too - a "candle-like"" colour.

> Anyone has an algorithm handy for making a bulb flicker like a candle?

 Well, concept yes.  A 7-bit Pseudo-Random Binary Sequence Generator
will generate a sequence of 128 steps.  Running at 20 steps per second,
this gives a cycle length of 6.4 seconds and it's unlikely that a viewer
would notice a repeating cycle of that length.

 IIRC, the feedback steps for this are bits 1 and 7, or 6 and 7.  Other
loner sequences are better, but you have to know the fedback taps for
maximal sequence.  Someone *must* have a web reference.  Scott?
--
 Cheers,
       Paul B.

1999\01\12@095956 by dave vanhorn

flavicon
face
>  Well, concept yes.  A 7-bit Pseudo-Random Binary Sequence Generator
>will generate a sequence of 128 steps.  Running at 20 steps per second,
>this gives a cycle length of 6.4 seconds and it's unlikely that a viewer
>would notice a repeating cycle of that length.
>
>  IIRC, the feedback steps for this are bits 1 and 7, or 6 and 7.  Other
>loner sequences are better, but you have to know the fedback taps for
>maximal sequence.  Someone *must* have a web reference.  Scott?
>--
>  Cheers,
>        Paul B.


I've got it in AVR code, http://www.dontronics.com in the download dungeon.
"Getting started".
It wouldn't be hard to translate to pic-ish.

1999\01\12@115037 by Chip Weller

flavicon
face
Paul B. Webster wrote:
>Shahid Sheikh wrote:
>
>> I'm using a 12C508 to control the lights in a HO scale model church.
>> On one of the desks in the church, I was planning on putting a real
>> tiny bulb and make it flicker like a candle.
>
>  A yellow LCD might be good too - a "candle-like"" colour.
>
>> Anyone has an algorithm handy for making a bulb flicker like a candle?
>
>  Well, concept yes.  A 7-bit Pseudo-Random Binary Sequence Generator
>will generate a sequence of 128 steps.  Running at 20 steps per second,
>this gives a cycle length of 6.4 seconds and it's unlikely that a viewer
>would notice a repeating cycle of that length.
>
>  IIRC, the feedback steps for this are bits 1 and 7, or 6 and 7.  Other
>loner sequences are better, but you have to know the fedback taps for
>maximal sequence.  Someone *must* have a web reference.  Scott?


I have been using linear congruential sequences for Random numbers, they are
fast and fairly good. It is best to use the highest order bits to get the
best random sequences. See Knuth "The Art of Computer Programming" Vol 2.
for a good reference on various types of Random numbers. The following code
is for an 8-bit and a 16-bit sequency, both cover the full set possible
values:

Rand16  ; best to use only top 8-bit value, stored in RanNum. Seed both
       ; that and RanLow.
   ; RanNum' = (RanNum * 257 + 48821) mod 2^16
   movf RanLow,w
   addwf RanNum,f
   movlw .48821%.256
   addwf RanLow,f
   skpnc
     incf RanNum,f
   movlw .48821/.256
   addwf RanNum,f
   retlw 0

Rand8    ; best to use only high nibble of RanNum.
   ; RanNum' = (RanNum * 17 + 163) mod 256
   swapf RanNum,w
   andlw 0F0h
   addwf RanNum,f
   movlw .163
   addwf RanNum,f
   retlw 0

Chip

1999\01\12@172644 by Russell McMahon

picon face
A "flaming torch" which was allegedly so real that it could not be
distinguished from the real thing at a distance was described in
Silicon Chip magazine, October 1997, p61-63.

The light is a mosfet driven light bulb wrapped in coloured
cellophane.
(A transistor would do as well).
The flicker drive is provided by 2 x 555 timers.
The lamp is usually on.
Either timer will drive the lamp off when its output is low (ANDed
outputs - low = off. Actually just uses 2 diodes).
Timers have about a 10:1 on to off ratio (so each is usually allowing
the bulb to remain on).

Judging by component values, one timer has about a 1 second cycle
time and the other about a 0.4 second cycle time (giving off times
around 0.1 and 0.04 seconds respectively).
The lamp thermal time constant means it never turns off fully with
the values they use.

With a constant program loop available you could increment two
counters and turn off the bulb for a preset period when either
reaches a terminal count.



regards

           Russell McMahon

From: Shahid Sheikh <spam_OUTSheikhTakeThisOuTspamEROLS.COM>
>I'm using a 12C508 to control the lights in a HO scale model church.
On one
>of the desks in the church, I was planning on putting a real tiny
bulb and
>make it flicker like a candle. Anyone has an algorithm handy for
making a
>bulb flicker like a candle?
>
>The PIC will be doing other tasks as well like understanding an
incoming
>datastream of NMRA DCC but its going to have a constant program
loop. It
>also turns on a 5 W tube and a several other bulbs on the inside and
out.
>
>I'm also thinking of controlling the transistor that energizes the
>transformer for the tube directly from the PIC. Anyone knows what
frequency
>those transformers work at? Its from a broken battery operated
flash/tube
>light.



Typical fluorescenmt inverters are 20 KHz plus (so as to be
inaudible).
Lower would work OK provided the transformer didn't saturate.

1999\01\13@011557 by Gerhard Fiedler

picon face
At 20:05 01/12/99 +1300, Russell McMahon wrote:
{Quote hidden}

but with digital counters don't use a ratio of 10:4, use two rather big
prime numbers with approx. that ratio, or/and maybe randomize the ration a
bit :-)

ge

1999\01\13@021143 by Dr. Imre Bartfai

flavicon
face
Hi,

all have almost exactly this project as I teached young people first steps
with PIC, random number generation, PWM, etc. I attach it for your
convenience. Xcus, but some comments are in Hungarian. I hope it does not
matter.

Imre
; Fire emulator

       DEVICE        PIC16C84,XT_OSC,WDT_ON,PWRT_ON
       ID        'FIRE'
       
       ORG        0Ch                ; RAM terulet

S1M        DS        1                ; szamlalo cca. 1 msec
WSAVE        DS        1                ; W mentesi terulet
SSAVE        DS        1                ; STATUS mentesi terulet
FLAGS        DS        1                ; jelzok
PWMACCU        DS        1                ; PWM akkumulator
RNDLO        DS        1                ; veletlen szamok
RNDHI        DS        1

MSEC1        EQU        FLAGS.0                ; most telt le 1 msec

       ORG        0                ; Program kezdete
       BSF        RP0                ; Bank #1
;                76543210
       MOVLW        11000001b
;                  | |\|/ -------  TMR0 elooszto: 4
;                 | +-----------  Elosztva: TMR0
;                  +-------------  TMR0-t a belso ora lepteti
       MOVWF        OPTION
       B        Start

       ORG        4                ; megszakitas kezelo

; az akkumulÊtor ment­s­re a WSAVE, a STATUS ment­s­re a SSAVE
; szimbolikus nevö regisztereket hasznÊljuk
       MOVWF   WSAVE           ; WSAVE <- W : ment­se
       SWAPF   STATUS,W        ; W <-x- STATUS
       MOVWF   SSAVE           ; swapolt STATUS ment­se
; itt jän a voltak­ppeni megszakÁtÊskezel­s
       BCF        T0IF                ; IT nyugtazasa
       INCF        S1M                ; szamoljuk a msec-eket
       BSF        MSEC1                ; jelezzuk
;
ITVeg
; itt a v­ge
       SWAPF   SSAVE,W         ; W <-x- SSAVE
       MOVWF   STATUS          ; STATUS <- W
       SWAPF   WSAVE,F         ; WSAVE <-x- WSAVE
       SWAPF   WSAVE,W         ; W <-x- WSAVE
       RETFIE                  ; visszat­r­s

Start
       MOVLW        0F0h                ; B0-3
       MOVWF        TRISB                ; output
       BCF        RP0                ; visszakapcsolas
       MOVLW        10100000b        ; GIE, T0IE
       MOVWF        INTCON
       CLRF        TMR0                ; ora 0-zasa
       CLRF        FLAGS                ; ez is
       B        Init
       
PwmLoop
       BTFSS        MSEC1                ; varj 1 msec-ig
       B        PwmLoop                ; amig le nem telik
       CLRWDT                        ; Watchdog 0-zasa
       BCF        MSEC1                ; Flag visszaallitasa
       MOVLW        128                ; a random ciklus tesztje
       SUBWF        S1M,W                ; S1M = 128
       BNZ        Pwm                ; meg nincs itt az ideje
Init        
       CLRF        S1M                ; 0-zas
       CALL        Random                ; veletlen szam generalas
Pwm        MOVFW        RNDLO
       ADDWF        PWMACCU                ; PWM generator
       BC        LiteOn                ; gyujtsd ki
LiteOff        MOVLW        0011b                ; kioltas
       B        Lite
LiteOn        MOVLW        1100b
Lite        XORWF        RNDHI,W                ; mix
       MOVWF        PORTB                ; effekt
       B        PwmLoop

; Random Number Generator
Random
       MOVFW        RNDLO                ; first test RNDLO|RNDHI=0
       IORWF        RNDHI,W
       SKPNZ                        ; no change when not zero
       COMF        RNDLO                ; otherwise invert
       MOVLW        80h                ; bit mask for RNDHI.7
       ANDWF        RNDHI,W                ; fetched
       BTFSC        RNDHI.6                ; Bit#6 set?
       XORLW        80h                ; XOR with bit
       BTFSC        RNDHI.4
       XORLW        80h
       CLRC                        ; set default
       BTFSC        RNDLO.3
       XORLW        80h
       SKPZ                        ; do nothing if zero
       SETC                        ; otherwise set C
       RLF        RNDLO                ; left w/Carry
       RLF        RNDHI
       RETURN

       END


On Tue, 12 Jan 1999, Paul B. Webster VK2BZC wrote:

{Quote hidden}

1999\01\13@150849 by Harold Hallikainen

picon face
Harold Hallikainen
.....haroldKILLspamspam@spam@hallikainen.com
Hallikainen & Friends, Inc.
See the FCC Rules at http://hallikainen.com/FccRules and comments filed
in LPFM proceeding at http://hallikainen.com/lpfm

       Looking back a little over a year ago, I wrote code for a flicker
device.  It just output random numbers on a port at an adjustable speed
(the flicker rate was set by a pot driving an A/D).  I wrote a Basic
program that generated a file with 256 RETLW statements, each with a
random number between 0 and 255.  The flicker code just stepped thru the
table and output the results.

Harold


___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...