On/Off piezo alarm not hogging main loop - possible?

satrapus

Member
I'm using a 18m2 for my project (single process).

A call to a subprocedure calls pwmout on the b.3 pin to run an ir led at 38khz.
Processing then returns to main procedure...

Functionality requires an alarm to be activated at some point, following which other processing still takes place with the alarm still on.

As I don't have any more pins with pwm support (which I think would solve this) is there any jiggery pokery that would set off an on/off
alarm while returning flow to main procedure.

I could just turn on the piezo for a continuous tone but this is naff.
Playing silent night is nice but again it pauses process flow so it's not an option.

I'd like the 18m2 to drive everything and want to avoid using an external 555 timer solution for a siren alarm.

Many thanks
 

hippy

Ex-Staff (retired)
Multi-tasking could perhaps do the job. SOUND or TUNE should work for fancy programmable alarms, no need for another PWMOUT.
 

satrapus

Member
Thanks, this is all new to me.
I was under the impression that multitasking will have a negative effect on the accuracy of timing commands.
I could go to the 20M2 for 2 pwmout's but unfortunately there is no power board like the CHI035 for it.
I was going to use this board to save me designing a pcb as I think it has everything I need.
 

hippy

Ex-Staff (retired)
It might be best to fully explain what you are trying to do and what the rest of the program is which this has to fit in with. The 18M2 supports two PWMOUT.
 

satrapus

Member
Naggers, now I'm really confused.
In Picaxe editor 6 only pin b.3 is shown with pwm. I presume this means it supports pwm.
The pwmout wizard only lets me select pin b.3.

In manual1 on page 10 pwm is only on pin b.6 for 18m2 ?

Now you tell me 18m2 supports two pwmout.
Does this mean its use is not bound to a pin that has it specified?

If I can use 2 pwmouts simultaneously this will solve my siren issue.
 

oracacle

Senior Member
I would maybe look into using the time variable (ref enable time). from my understanding it increments every second, all that will be needed is an if statement that call a sub procedure in the main loop (ie if time <> previous then gosub...) - you will beed a spare variable to store the previous time value.
 

Goeytex

Senior Member
Well that's good news.
Off to figure out how to turn my buzzer on/off every second using pwmout...
PWMOUT will not go that slowly. You could set the PWM to 256 hz and then divide with a ripple counter. Then have the ripple counter output trigger an interrupt.

With even less overhead, you could use a 555 timer to trigger an interrupt every second.

Unfortunately Picaxe Basic does not support interrupt on internal timer with M2 chips. You need an X2 for that feature.
 
Top