PWM and tune command issue

jensmith25

Senior Member
I have another issue related to some of my recent threads for programming flickering Lights on the 18M2 high power board. The idea is to have two channels so you get different flickering over 24 lights (two sets of 12). I want to put them through the onboard FETs (rather than one set through the motor driver which has the other pwm output pin).

I have both programmes running fine separately but when I put them together the tune command seems to conflict with the pwmout command so the LED is just static on. I can't figure out what's going on. I've simplified the code to try to figure out what's happening but it's still not working. Is there a known conflict with the tune command? Any ideas?

Code:
#Picaxe 18m2

start0: 'Flickering effect
	pwmout B.3,249,1023
	pause 500
	pwmout B.3,249,5
	pause 500
	goto start0
	
start1: 
	goto flickerslow
	goto start1

flickerslow: 'Flickering effect slow - Silent Night 1 slow speed
	tune B.2, 12, ($27,$69,$27,$E4,$27,$69,$27,$E4,$C2,$02,$EB,$C0,$00,$E7,$E9,$29,$00,$6B,$29,$27,$69,$27,$E4,$E9,$29,$00,$6B,$29,$27,$69,$27,$E4,$C2,$02,$05,$42,$2B,$C0,$C4,$00,$27,$24,$27,$65,$22,$E0)
	goto start1
 

The bear

Senior Member
@ jen,
Do you need that first "pause 500"?
Just guessing, it seemed to perform better without it.
I've not done a multi start.
Bear..
 

westaust55

Moderator
Using the multi-task capability of the M2 parts it must be kept in mind that there is only one processor/core so time slice techniques are used.
That is, perform command from one task, then the next command from second task and eventually back to following task in the first command.

Thus while the tune command is being executed no other command is executed.
But when a pause command exists the processor takes the opportunity to move on to the next command in the other thread(s).
Hence in your case the tune will appear to have the priority.

As already suggested, removing the pause in the first task will improve things a bit.
If the tune has some natural breaks/pauses/silences, try breaking the tune into multiple segments each with its own TUNE command. That would allow more frequent returns to the PWM task.
 

AllyCat

Senior Member
Hi,

Is there a known conflict with the tune command?
AFAIK, TUNE is a "Blocking" command (i.e. it requires all the PICaxe's resources to accurately time the notes) so it cannot work with "mult-tasking" which fuctions by rapidly switching between the tasks (i.e the separate start:s).

Or to put it another way, TUNE is a single "instruction" which must be completed before the alternate task (start: thread) is executed.

You might be able to achieve the random effect you want by emulating the TUNE command in a subroutine. For example, a loop which reads a data value from a list (e.g. in EEPROM or a LOOKUP command) and sets up a PWM frequency (if required) and a time delay, which might itself be a counting loop. Then the second task will be able to execute between each program line of the first.

Cheers, Alan.
 
Top