Driving Piezo with PIC

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi Martin,

It's OK, I am trying to boost it using a transistor / inductor combination.

Can you tell me if it is possible to run two different variables, with TMRO in the main prog?.

I wish to run the clock in the background and the piezo would sound once its triggered. Works well on simulation but doesn't work on the real hardware ? :(

Indana

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi Martin It's OK, I am trying to boost it using a transistor / inductor combination.

Can you tell me if I can use two different variables on TMR0, one for the main clock and one for the piezo once it is triggered.

It works OK on simulation, but dosen't work on the real hard ware? clock too fast, corrupted characters etc :(

regards

Indana

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Driving Piezo with PIC

Post by medelec35 »

Have you changed something?
It ran on my hardware just fine. Could the inductors be causing spikes? This would cause corruption and possible damage microcontroller.
You can use timer0 timer1 or timer 2 for generating 1Hz. My choice would be utilise timer0 to avoid conflicts. Maybe someone else could advise on that aspect.
I will see if i can put someting together later.
Before I do, you need to explain exacly what you want to show in LCD and also if you want a set level adj etc.

Piezo transducers are loud connected between A1 and A2 so long as it running at correct frequency. I had to cover my ears as tone was so piercing.
Did you try 'Variable Frequency Generator 500Hz to 5KHz (100 Hz Steps)'
To determine best frequency?

Martin
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi Martin,

I was using 3v battery supply and a 5Meg pot, do you think this could be the reason?.
May be it needs a higher voltage?.


many thanks

regards

Indana

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Driving Piezo with PIC

Post by medelec35 »

nmindana wrote:Hi Martin,

I was using 3v battery supply and a 5Meg pot, do you think this could be the reason?.
May be it needs a higher voltage?.


many thanks

regards

Indana
If you mean to supply chip/LCD then yes that is definitely the reason. There is not enough current to power either LCD or micro.
Maximum Peak to peak voltage for the piezo is 30V, so no need to tap from a 3V supply
If not then what are you using the 5M pot for?
Perhaps you could post the circuit diagram.

Martin
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi sorry I meant 3v just for the piezo without the LCD. The 5M pot is to select the best frequency, in relation to the programme that you posted earlier. The gadget is meant to be portable and hence the battery supply.


Indana

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi Martin,

Can you help me out.
I have combined your Piezo example with the digital clock example, with no success ?.

When sensor AN0 triggers the clock is meant to stop and trigger the piezo, and start working again once the (AN0<125).

Thanks

regards

Indana
Attachments
Digital clock and piezo alarm.fcf
(23.49 KiB) Downloaded 415 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Driving Piezo with PIC

Post by medelec35 »

Hi Indana,
Was a good try!
I have modifed your flowchart to interface with the frequency generator. See:
http://www.matrixmultimedia.com/mmforum ... =26&t=8443
So at least when moisture is above a pre-set level then the frequency can be adjusted from 500Hz to 5KHz
I have also altered the clock part, so only when clock is running the : flashes.
The display with show the clock (24HR clock) on the top line, and current moisture lvl on the bottom line.
I have not got my Ebock programmer with me this weekend, so I have only tested code on a simulator that runs in real time from a loaded hex file:
Digital clock and piezo alarm_Modified1.jpg
Digital clock and piezo alarm_Modified1.jpg (149.92 KiB) Viewed 14369 times
Since using timer2 interrupt for the clock, it will not simulate on flowcode simulator (hope that's sorted in the new update :P).
Attachments
Digital clock and piezo alarm_Modified1.fcf
(23.89 KiB) Downloaded 494 times
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Driving Piezo with PIC

Post by Spanish_dude »

That simulator looks cool, I'll download it someday :mrgreen: .

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Driving Piezo with PIC

Post by medelec35 »

Spanish_dude wrote:That simulator looks cool, I'll download it someday :mrgreen: .
I was surprised how cheap it is for how well it does work.
I got it from:
http://digitalelectrosoft.com/pic-simulator
and it costs 29 USD
I'm not associated with the product, I just believe its the best simulator on the market.

Martin
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Works Brilliant thanks Martin

The seconds clock displays a thrid digit for eg: 450 after some time has lapsed. I will try to rectify and will let you know how I got on.

Regards

Indana

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Driving Piezo with PIC

Post by medelec35 »

No problem.
Glad, Its working brilliant for you.
nmindana wrote:The seconds clock displays a thrid digit for eg: 450 after some time has lapsed.
You could add a LCD PrintString component macro, with " "
(two sets of speech marks separated with one space).
Suggestion.JPG
Suggestion.JPG (32.51 KiB) Viewed 14347 times
Try that and let me know how you get on please.
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi Martin,

Sorry I was away on a holiday for a while.
I was trying to change the output pins from port A 1&2 to port B 6&7 (piezo outputs)
and I found it difficult than I thought. can you help please.

thanks

Indana

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Driving Piezo with PIC

Post by medelec35 »

nmindana wrote: I was trying to change the output pins from port A 1&2 to port B 6&7 (piezo outputs)
and I found it difficult than I thought. can you help please.

thanks

Indana
Just change from 2 portA to 64 PortB
and 4 PortA to 128 Port B.
Don't forget to change 0 PortA to 0 PortB
Finally you have to change the masking ticks from 1 & 2
to 7 & 8 on all three outputs of Timer0_Freq_Tick macro.

Martin
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi Martin,

I am struggling to understand.
I always thought send "1" for on and "0" for off.
Does this numbers switch port B 64 times etc ?
Why different numbers for different ports ?.

Indana :roll:

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Driving Piezo with PIC

Post by medelec35 »

Hi Indana,

Lets take the 64 1st

Code: Select all

If you have                       128  64  32  16  8  4  2  1
In Binary 64 (Decimal) =           0    1   0   0  0  0  0  0 
You can see bit under the 64 is high(1) all the rest are low(0)

Going from the far right bit = Least Significant Bit or LSB = bit 0 (there are eight bits in total), the high bit is bit 6
If you had an output icon set to the whole port eg portB, and was assigned with the value of 64 then pin conected to portB6 would be the only pin that will be high (at +5V)
all the rest of the port will be set low (0V)

Masking:
Suppose none of the bits on the output Icon was masked and decmal value assigned to portB is 100

Code: Select all

If you have                       128  64  32  16  8  4  2  1
In Binary 100 (Decimal) =          0    1   1   0  0  1  0  0 = 64+32+4

So bits 6,5 & 2 are all high and the remaining bits left will be low.
If you mask bit 6 (select Entire port, Use Masking, bit6)
Masking1.jpg
Masking1.jpg (35.64 KiB) Viewed 14302 times
Then only bit 6 is ever effected, so only bit 6 will be high, or with 0 as a value will go low.
This is the same as selecting output to a single bit and using 1 for bit = on and 0 for bit = off

I have use masking when I want more than one bit(or pin) to be affected, but not all 8 bits.

So it has nothing to do with counting 64 times.

Hope this helps

Martin
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

You are a fantastic teacher as well :)

thanks very much

Indana

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi Martin,

I am getting a continuous tone!.
Can you explain how to change the "on/off" period.

Thanks

Indana

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Driving Piezo with PIC

Post by medelec35 »

If you post your flowchart. I will take a look at it for you.


Martin
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Driving Piezo with PIC

Post by nmindana »

Hi Martin,

I wish to change the target device now to 16F689, would the same programme be suitable for this device, Flowcode says no :?

Thanks

regards

Indana

Post Reply