Page 2 of 2

Re: Driving Piezo with PIC

Posted: Tue May 31, 2011 11:36 pm
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

Re: Driving Piezo with PIC

Posted: Tue May 31, 2011 11:43 pm
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

Re: Driving Piezo with PIC

Posted: Wed Jun 01, 2011 11:11 am
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

Re: Driving Piezo with PIC

Posted: Wed Jun 01, 2011 5:11 pm
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

Re: Driving Piezo with PIC

Posted: Wed Jun 01, 2011 6:29 pm
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

Re: Driving Piezo with PIC

Posted: Wed Jun 01, 2011 7:29 pm
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

Re: Driving Piezo with PIC

Posted: Sun Jun 05, 2011 9:10 am
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

Re: Driving Piezo with PIC

Posted: Sun Jun 05, 2011 12:41 pm
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 15558 times
Since using timer2 interrupt for the clock, it will not simulate on flowcode simulator (hope that's sorted in the new update :P).

Re: Driving Piezo with PIC

Posted: Sun Jun 05, 2011 1:56 pm
by Spanish_dude
That simulator looks cool, I'll download it someday :mrgreen: .

Re: Driving Piezo with PIC

Posted: Sun Jun 05, 2011 2:15 pm
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

Re: Driving Piezo with PIC

Posted: Mon Jun 06, 2011 11:01 am
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

Re: Driving Piezo with PIC

Posted: Mon Jun 06, 2011 1:46 pm
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 15536 times
Try that and let me know how you get on please.

Re: Driving Piezo with PIC

Posted: Sat Jun 18, 2011 10:25 pm
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

Re: Driving Piezo with PIC

Posted: Sat Jun 18, 2011 11:36 pm
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

Re: Driving Piezo with PIC

Posted: Sun Jun 19, 2011 9:51 am
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:

Re: Driving Piezo with PIC

Posted: Sun Jun 19, 2011 10:49 am
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 15491 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

Re: Driving Piezo with PIC

Posted: Sun Jun 19, 2011 10:55 am
by nmindana
You are a fantastic teacher as well :)

thanks very much

Indana

Re: Driving Piezo with PIC

Posted: Tue Jun 21, 2011 1:39 pm
by nmindana
Hi Martin,

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

Thanks

Indana

Re: Driving Piezo with PIC

Posted: Tue Jun 21, 2011 1:49 pm
by medelec35
If you post your flowchart. I will take a look at it for you.


Martin

Re: Driving Piezo with PIC

Posted: Sun Jul 03, 2011 10:17 pm
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