PWM Jellyfish

nbw

Senior Member
Latest update, LEDs have arrived.

I thought I'd enhance things a bit, using Hippy's code (above) as the main 4-channel PWM. I I wrote some very particular PWMOUT commands for one of the pins, to create a nice flickering "boot-up" series of flashes and fades. This is on pin C.5 of the 20X2, which is the typical pwm pin. It works fine. This is at 8MHz.

I thought I'd add this piece of code just before Hippy's code, where it sthen witches to 32MHz. The idea was then it would just carry into the fading in and out for the four sets of LEDs, looping happily.

Hippy's original code assigned the LEDs to pins c.0, c.1, c.2, c.3. I changed the c.0 one to c.5, because that's where the PWM pin on the 20X2 is. My thinking was once the initial work on the single set of LEDs was finished, it would carry on to the loop, where c.5 is just one of the four sets of LEDs.

BUT!

My code on c.5, by itself - works fine.
Hippy's code on c.5, by itself - works fine
My code, then Hippy's - my bit works , his no longer does!

Really odd. I use setfreq m8 to do mine, then switch to m32 after it's done.

Any ideas?

thanks as always!
 

nbw

Senior Member
Latest update, LEDs have arrived.

I thought I'd enhance things a bit, using Hippy's code (above) as the main 4-channel PWM. I I wrote some very particular PWMOUT commands for one of the pins, to create a nice flickering "boot-up" series of flashes and fades. This is on pin C.5 of the 20X2, which is the typical pwm pin. It works fine. This is at 8MHz.

I thought I'd add this piece of code just before Hippy's code, where it sthen witches to 32MHz. The idea was then it would just carry into the fading in and out for the four sets of LEDs, looping happily.

Hippy's original code assigned the LEDs to pins c.0, c.1, c.2, c.3. I changed the c.0 one to c.5, because that's where the PWM pin on the 20X2 is. My thinking was once the initial work on the single set of LEDs was finished, it would carry on to the loop, where c.5 is just one of the four sets of LEDs.

BUT!

My code on c.5, by itself - works fine.
Hippy's code on c.5, by itself - works fine
My code, then Hippy's - my bit works , his no longer does!

Really odd. I use setfreq m8 to do mine, then switch to m32 after it's done.

Any ideas?

thanks as always!
any ideas anyone? I still haven't managed to figure it out......
 

nbw

Senior Member
#Picaxe 20X2
#No_Data

; Note : Do not set DWELLx to zero !
' TIME value is the length to fade up and down. Dwell is the pause in between
Symbol TIME1 = 3300 : Symbol DWELL1 = 1200 ' c.5 3300,1200 are good values
Symbol TIME2 = 4500 : Symbol DWELL2 = 1900 ' pin 3
Symbol TIME3 = 2400 : Symbol DWELL3 = 200 ' this one not used
Symbol TIME4 = 2700 : Symbol DWELL4 = 2800 ' pin 1

; Symbol PWM_BIT = 8
; Symbol PWM_DIV = 256
; Symbol PWM_MAX = 255
; Symbol PWM_ADD = PWM_MAX * 4
; Symbol T_LOOP_MS = PWM_ADD / 100

; Symbol PWM_BIT = 9
; Symbol PWM_DIV = 128
; Symbol PWM_MAX = 511
; Symbol PWM_ADD = PWM_MAX * 4
; Symbol T_LOOP_MS = PWM_ADD / 200

Symbol PWM_BIT = 10
Symbol PWM_DIV = 64
Symbol PWM_MAX = 1023
Symbol PWM_ADD = PWM_MAX * 4
Symbol T_LOOP_MS = PWM_ADD / 400

Symbol K = 65535 * T_LOOP_MS

Symbol TLOOP1 = TIME1 / T_LOOP_MS
Symbol TLOOP2 = TIME2 / T_LOOP_MS
Symbol TLOOP3 = TIME3 / T_LOOP_MS
Symbol TLOOP4 = TIME4 / T_LOOP_MS

Symbol TINC1 = $FFFF / TLOOP1
Symbol TINC2 = $FFFF / TLOOP2
Symbol TINC3 = $FFFF / TLOOP3
Symbol TINC4 = $FFFF / TLOOP4

Symbol DLOOP1 = DWELL1 / T_LOOP_MS
Symbol DLOOP2 = DWELL2 / T_LOOP_MS
Symbol DLOOP3 = DWELL3 / T_LOOP_MS
Symbol DLOOP4 = DWELL4 / T_LOOP_MS

Symbol DINC1 = $FFFF / DLOOP1
Symbol DINC2 = $FFFF / DLOOP2
Symbol DINC3 = $FFFF / DLOOP3
Symbol DINC4 = $FFFF / DLOOP4

Symbol LED1 = C.5 ' pin 10
Symbol LED2 = C.1 ' pin 9
Symbol LED3 = C.2 ' pin 8
Symbol LED4 = C.3 ' pin 7

Symbol bits = w0
Symbol paused = w1

Symbol level1 = w2
Symbol level2 = w3
Symbol level3 = w4
Symbol level4 = w5

Symbol paused1 = w6
Symbol paused2 = w7
Symbol paused3 = w8
Symbol paused4 = w9

Symbol pulse1 = w10
Symbol pulse2 = w11
Symbol pulse3 = w12
Symbol pulse4 = w13


;gosub initial_fade
;pause 500
SetFreq M32
pause 300

#Macro Fade( level, direction, fadeInc, pausedVar, pausedBit, pauseInc )
If pausedBit = 0 Then
; Paused
pausedVar = pausedVar Min pauseInc - pauseInc
If pausedVar = 0 Then
pausedVar = $FFFF
pausedBit = 1
End If
Else If direction = 0 Then
; Fading up
level = $FFFF - fadeInc Max level + fadeInc
direction = level ^ $FFFF Max 1 ^ 1
Else
; Fading down
level = level Min fadeInc - fadeInc
direction = level Max 1
pausedBit = direction
End If
#EndMacro

MainLoop:
Do
Fade( level1, bit1, TINC1, paused1, bit11, DINC1 )
Fade( level2, bit2, TINC2, paused2, bit12, DINC2 )
Fade( level3, bit3, TINC3, paused3, bit13, DINC3 )
Fade( level4, bit4, TINC4, paused4, bit14, DINC4 )
Gosub GeneratePwm
Loop

GeneratePwm:
pulse1 = level1 / PWM_DIV : PulsOut LED1, pulse1
pulse2 = level2 / PWM_DIV : PulsOut LED2, pulse2
pulse3 = level3 / PWM_DIV : PulsOut LED3, pulse3
pulse4 = level4 / PWM_DIV : PulsOut LED4, pulse4
paused = PWM_ADD - pulse1 - pulse2 - pulse3 - pulse4
PauseUs paused
Return



' --------------------------
' barney's code here

initial_fade:
setfreq m8
pause 200
' gentle fade to start

pwmout C.5, 124, 0
wait 2

for paused1 = 0 to 700 step 100
pwmout c.5,124,11
pause 250
pwmout C.5, 124, 0
paused2 = 700 - paused1
pause paused2
next

for b2 = 1 to 5
pwmout c.5,124,5
pause 150
pwmout C.5, 124, 0
pause 20
next

pwmout C.5, 124, 0

'----------------------------------------------------------

for b2 = 3 to 8
for paused1 = 2 to 6
pwmout C.5, 124, b3 ; 4000Hz at 100% @ 8MHz = 499
pause 16
b3 = paused1 * b2
pwmout c.5,124,0
pause 12
next
next
pwmout C.5, 124, 0

'----------------------------------------------------------

for paused1 = 4 to 15
pwmout C.5, 124, paused1 ; 4000Hz at 100% @ 8MHz = 499
pause 15
next

pwmout C.5, 124, 0

for paused1 = 36 to 4 step -2
pwmout C.5, 124, paused1 ; 4000Hz at 100% @ 8MHz = 499
pause 15
next

pwmout C.5, 124, 0
'----------------------------------------------------------

for paused1 = 6 to 50
pwmout C.5, 124, paused1 ; 4000Hz at 100% @ 8MHz = 499
pause 16
next

pwmout C.5, 124, 0

for paused1 = 50 to 6 step -1
pwmout C.5, 124, paused1 ; 4000Hz at 100% @ 8MHz = 499
pause 20
next

'----------------------------------------------------------
pause 100
pwmout C.5, 124, 0

for paused1 = 6 to 150
pwmout C.5, 124, paused1 ; 4000Hz at 100% @ 8MHz = 499
pause 15
next

wait 1

for paused1 = 150 to 0 step -1
pwmout C.5, 124, paused1 ; 4000Hz at 100% @ 8MHz = 499
pause 23
next

wait 3
return
 

nbw

Senior Member
Sorry, it's a bit long. Hippy's code is the original , mine starts from the line "Barney's code". I put mine as a subroutine called just before Hippy's loop.
 

premelec

Senior Member
Have you read the PWMOUT command description? You might need to use PWMOUT pin OFF command when changing.. worth a try...
 

nbw

Senior Member
Everyone, I've finished it. My stupid phone takes photos that are huge, which is annoying. I've posted several pix and a 45 second video on my Facebook page if anyone is interested.

All PWM (thanks Hippy, premelec, and the others) channels working great on my six foot tall jellyfish made from copper, an old washing line, used spark plugs, and so on.

Facebook: just look for Barney Walker, a red-headed guy and there's a blue Indian motorcycle in the background.

Again, a huge, appreciative thanks.
 

nbw

Senior Member
Thanks! It looks so much better in video, but I don't think I can upload one here - it's only 45 sec but 90Mb.
It took 90-100 hours to make, features a 20X2 and 4 separate triangle wave generators to phase the four pairs of tentacle LEDs on and off. Also has a blue EL wire coiled on the inside to light that up if required.

All four PWM banks can be individually switched off, steady on mode (dim), or PWM. The EL wire can be on/off and brightness adjusted. And the tentacles, gentle pulsing or off.

:)
 

lbenson

Senior Member
Nice job. It looks good even in still shots . . . but:
It looks so much better in video, but I don't think I can upload one here - it's only 45 sec but 90Mb
upload to youtube and provide the link. Very quick process, especially compared to the amount of time you've put into building the thing.
 

Buzby

Senior Member
You could make the tentacles sway gently to add a bit more effect.

Put some muscle wires about halfway down, linked between the tentacles.

Cheers,

Buzby
 

nbw

Senior Member
Muscle wire - I'll learn about that for the next project - thank you!


the link is to the video on youtube, thanks!!
 

lbenson

Senior Member
Nice. Buzby's right--gently swaying tentacles would be the cat's meow. Of course, if you actually do have a cat, that life-likeness might be too great an attractant.
 

nbw

Senior Member
I'm thinking of a big seahorse next - maybe 40-45cm tall - with musle wires to make the dorsal spines flex!
 

nbw

Senior Member
I think I would like to get some muscle wire to experiment with - asking for suggestions / recommendations from people who have bought it before (we don't have it in NZ) - where have they bought it, where the site has a good range? I'll be after the thinner stuff I suspect, that needs perhaps 30-100mA to twitch. It won't be handling a big weight - just an LED at the end of the wire, and the wires to the LED.

Thoughts?
(thanks in advance)
 
Top