PIC output for piezo transducer

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

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

PIC output for piezo transducer

Post by christoph »

Hi all,
Having driven a 30mm dia. piezo transducer ok from a potted driver bought off the internet (with no details but giving the right sound!), I now want to get the same sound from a much smaller package using an 8-pin PIC12F683 or similar (surface mount package) as I have very little space available from breadboard to actual enclosure! Having found two excellent MM V4 posts: "sweep through a frequency" and "Driving Piezo with PIC", it seems like with very minor modification of one or other of those posts - particularly the first one - this could be achieved fairly easily. However, I havent the knowledge or experience in this area of Flowcode at the moment but need to get this all 'together' for christmas and I was hoping that one of the experienced fellows like Martin (who was instrumental in sorting out the aforementioned posts) might be able to advise given the following details for information:-
All I need is a rising and falling tone that sounds like the typical waa waa waa etc. sound of a police siren (without any pause at each change of 'rise and fall' that is currently built in to one of the solutions posted). I am currently using a 100k pot to enable the rate between each waa waa to be variable from roughly 5 a second down to roughly 1 a second for my particular alarm sound. Nominal voltage is 3.6 volts but working range is from approx 2.5 to 4.2 (using a 3.6 Li Ion rechargeable battery) and occasionally up to 5v from USB port power. Not bothered if the different voltages change the tone a bit and anyway can be partially compensated for by pot adjustment.
The PIC needs to provide a single output 'containing' that signal to connect to my existing sounder circuit of a BC337 transistor buffer via a 1k resistor at 1mA base current. The collector takes care of the rest of the piezo transducer circuit without any other tie-in to the tone generation.
The Piezo is an RS Stock No 238-022 which has a peak resonance at 4.5KHz so I guess a reasonable range for the tone sweep would be around 2 to 6KHz.
Would appreciate advice or a modified flowchart if possible
Many thanks in advance. Chris

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: PIC output for piezo transducer

Post by medelec35 »

Hi Chris,
christoph wrote:Having found two excellent MM V4 posts: "sweep through a frequency" and "Driving Piezo with PIC"
Thank you for that. :)
Perhaps a suggestion.
As well as a pot, perhaps have 1 switch as well?
Pushing and releasing switch will allow adjustment of set highest tone, lowest tone and repetitive rate.

whether you go for the switch idea or not, hopefully I can help you achieve your desired results.
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin,
Thanks very much for your reply - it sounds as though there is more to this than I thought?? With regards to the switch - I really like the idea but have extremely limited room and i was already having to use a 7mm square SMD pot to squeeze it in, in terms of enclosure AND PCB space so wouldnt have room for both without enlargement - but I'm actually trying to make as small as posible. However, the switch could be a nice alternative if it was small enough! If you are thinking in terms of a momentary push button using the programme to give those three parameters depending on how the button was pressed (so that a tiny PB could take the place of the pot), that would be absolutely fine! If not, can you let me know what type of switch/input/operation is required and I will see if I can find something that I might be able to fit in the space available. Much appreciate your help - thanks Martin :)

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: PIC output for piezo transducer

Post by medelec35 »

We may be able to work around with what you have got.

Meanwhile I have created a flowchart which is very much work in progress.
So it will require modifications to get a better result.
If you can comment on it, that would be useful.

The PWM output is from pin 5 and the analogue i/p is on pin 7
I will see if I can find a transducer to test with later.

I feel the frequency change linearity will need to be added since frequency change will be quicker at the higher end.

Currently the sweep will start low, rise up then at peak will drop again.
Let me know If you would like it done differently.

Martin
Attachments
Sweep output 12F683 V1.fcf
(14.5 KiB) Downloaded 636 times
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin,
Have only just got in from the afternoon chores, so havent had time to digest your flowchart in detail yet but I will do so during the evening and post you accordigly. I have an RS Components order ready but holding it to add the 12F683 if that particular PIC will do the job (although I am happy to use any of the readily available 8-pin variety if there was a more appropriate one). However, it means that I cant test it out right away because I have no loose PICs - they are all soldered in place! Would you think there was any reason for NOT using that PIC? It seemed to have suitable credentials - internal clocking etc. and if you let me know if ok, then I will put the order in.
Many thanks Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Sorry,
Network signal lost and didn'T register successful post so submitted again and it produced both!
Chris

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: PIC output for piezo transducer

Post by medelec35 »

No worries deleted one of the posts.
best value for money as they got more bang for buck is 12F1840 and they are cheaper than 12F683 + internal osc goes much higher.
If you have already got 12F683 on order then they will do the job just fine.
There is no reason I can think of not to use one.

Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin,
I have had a good look at your flowchart and I am beginning to understand the approach but I havent quite grasped it all yet. Not done anything involving timing yet (apart from 'delays', so this is a good introduction which ultimately will help me to understand the mechanics of timing within Flowcode! The control panel doesn't currently adjust at any simulation speed at the moment - is that to do with the timing speed? If you can give me the ok for the 683, I will get it ordered and run the piezo with it.
Kind regards, Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Ooops - sorry Martin, I didn't see your earlier post regarding the 12F1840 and as you will see from MY last post, I was just awaiting your ok - so I will check that RS have got 'em and I will go ahead and order those instead - might as well have the speed capability available if needed!
Cheers,
Chris

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: PIC output for piezo transducer

Post by medelec35 »

I have had an idea.
How about for development and setting up I will alter flowchart so pot just alters the frequency.
THen you can use a RS232 to USB converter:
http://www.matrixmultimedia.com/mmforum ... usb#p47820

With the RS232 to USB converter, the data sent to your PC can show ADC value that is generating the current frequency.
Then you will know for the correct frequencies what the correct ADC values will be.
We Can then use Look-up tables:
http://www.matrixmultimedia.com/mmforum ... 26&t=10066
&
http://www.matrixmultimedia.com/mmforum ... =26&t=3543
&
http://www.matrixmultimedia.com/mmforum ... =36&t=4869
So then the tones and duration can be determined by two look-up tables,

Thinking about it we could even use the pot to function as a switch as well as a pot by say turning fully counter clockwise then full clockwise within a given time.
Then there could be beeping to indicate function selected for the pot to adjust etc.

Let me know if you like the RS232 and freqgenerated by pot position, I will then post updated flowchart.


Martin
.
Martin

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: PIC output for piezo transducer

Post by medelec35 »

Just had another thought (Dangerous for me :lol: )
The Piezo transducer is designed to work at a particular resonance frequency and at that point sound emitted will be at its maximum for given supply voltage.

Which means as the frequency goes up and down through resonance, sound emitted will very noticeably change.
I would recommend using a small speaker instead.
If you're determined to carry on using piezo transducer then the third LUT may be required to alter PWM duty which will alter sound pressure level (SPL) to flat out.
Looking at the datasheet for your transducer you can see at 2KHz sound level is 94dB, at about 2.8K sound is 81dB and at 6KHz its 102dB (if I have read datasheet correctly).
Note: Saund may be at diffeven level than data sheet to start, but the ratios will be the same.
As a guide with SPL 6dB difference = double in sound (3dB is double for power).
So it depends if you can live with the wide variation in sound level or not.

Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin,
I wasn't here yesterday and have just fired up the pc and am catching up with your postings and assimilating your comments - back shortly.....

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin,
Wow - so much food for thought and I got interested in the brilliant look up tables tutorial - just a question on THAT for future reference (I have only skimmed through it at this stage, so might be a silly question): can one print a string of a few words rather than a numeric value as the result of an appropriate input?
Back to current business - I like the ideas you have put forward but not sure that I will have enough time to get everything done before Christmas. Whilst tempting, I think I need to keep things simple to ensure I can get this done by the weekend and I don't really need to find or operate continuously at the resonant frequency itself, so could I just mention a couple of things to give a bit more of a 'picture':
Basically, I want to replicate the sound I am getting with the potted sound generator I have at the moment - which is too big - and using the piezo we are looking at which allows for minimal space requirements and running via my piezo driver stage. I am currently achieving 102db at one metre. The potted device gives a sweep over what I loosely believe is about 3 to 5 KHz - although I mention 2 to 6KHz in my first post to ensure the actual range will be covered at this stage (whatever that tuns out to be). The pot controls the sweep rate rather than the tone up and down frequency. This arrangement means that it hits the piezo resonant frequency wherever that lies across the sweep range. Effectively it produces a real 'thump' as it passes through the resonant point and so I dont need to pre-determine this. The thump appears to be approx. mid-way between the lowest and highest frequency so that would be something which needs to be set within the program to avoid the result sounding 'lop-sided'. Turning the pot makes the 'thumps' closer together or further apart which DOES have the effect of raising or lowering the overall sound pitch but this is perfectlly acceptable and gives a good range of 'coloure'. It is so difficult to describe that what I'm doing is ordering the PIC12F1840 today and I will run it with your programme, then the audible results should provide any tweaking information which I can post you with if necessary.
If you feel any of the above means any modification to the flowchart, I wont be programming the PIC till tomorrow evening (after RS delivery).
Many thanks
Chris

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: PIC output for piezo transducer

Post by medelec35 »

Hi Chris.
Before sending to target, it would be best if you first remove the 10ms delay.
That was only added as a habit and would normally be fine.
But in your case it has to be removed so a faster ramp up/down can be achieved.
You will also require a 500us delay between PWM Change period and PWM set duty components.

christoph wrote: I got interested in the brilliant look up tables tutorial
Thanks for that :)
christoph wrote:can one print a string of a few words rather than a numeric value as the result of an appropriate input?
The answer is yes, you can
the correct stored numbers can be found by looking on an ascii table like on this page:
http://www.theasciicode.com.ar/
E.g you want to store Hello, you would use:
72,101,108,108,111
Then you would retrieve these numbers and use SendRS232Char function (so long as you have got professional version of Flowcode).

Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

OK, I will modify the flowchart according to your post.
Cool re LUTs - I am now looking at that as I am having to wait for my 'chips'!!
Incidently, when you say the 'professional version of flowcode' - how will that affect the RS232 situation? I thought I had all that kind of capability!

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: PIC output for piezo transducer

Post by medelec35 »

christoph wrote:Incidently, when you say the 'professional version of flowcode' - how will that affect the RS232 situation? I thought I had all that kind of capability!
Unless you have the professional version of Flowcode, you will not be able to compile any advance components e.g communications which include RS232.
The components can be selected, but when compiling I believe there will be an error.
If you have professional then your be fine.

Here are the available components of non professional versions:

Code: Select all

Components                         : LEDarray, LED, LED7Seg1, LED7Seg4, LCD, Switch, Switchbank, ADC, Keypad, PWM, FormulaFlowcode, MIAC
If its not on the list then it will not allow you to compile. perhaps you can give it a try and compile to hex with RS232 component selected.

Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Oh, I see what you mean - yes I do have the full list including all the comms titles and am using RS232 successfully in projects already, so appear to have what I thought I had!
Cheers
Chris

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: PIC output for piezo transducer

Post by medelec35 »

Sounds like you have professional version then.
Also Help/about Flowcode will also confirm which version you have.


Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin,
Will return to you with results for the above but had to add some items to RS order so will be receiving parts and testing on Thursday now. Also, if you or anyone has a moment to look at my latest query 'Switches in simulation working but not on Matrix MM HP-488-00-3 Development Board' (which I will post shortly),I would be very grateful for any advice.
Cheers,
Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin,
Bit of a snag - the 12F1840 wasn't recognised in the 'simple config' so I selected expert config and it WAS there so selected it. However, it wouldn't config and came up with "failure" error code "-2" and said 'due to': then no explanation - as usual! I next went to PPV3 and tried configue in simple and expert and it said it was not listed and the yellow USB data LED on the development board was flashing. Just to try I tried AUTODETECT but it wasnt recognised and I put in the chip number when asked and again no joy. I had thought it was due to a programme 'repair' (which for some reason I have to do quite often for missing asm files or somesuch - any ideas on the reason for this as I never had any problem until a few weeks ago and doesn't seem to be related to whether I close the computer down or not?). The only possibility is that with my somewhat limited experience wih all the expert config data listed that can be enabled/disabled I might have disabled something I shouldn't or the opposit! I have done all the usual standard things but it is a much longer list than the 683.
Would be grateful for any clues. Tried to see if I coul update PPV3 as it is not in-line with the Flowcode 'expert config' list!
Cheers,
Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin ,
Just for the 'heck of it' I stuffed a 16LF88 chip onto the development board and configured it accordingly (with the idea of trying it) and it programmed without any trouble but it only appeared to do one pass thro' the flowchart so I didn't bother sorting it out as it is too big of course. However, I then re-instated the 1840 and set it as the chip to programme which it DID with no problem but I checked and it has done it as a 12F683! Is this possible?? I am checking that it will do that again!

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: PIC output for piezo transducer

Post by medelec35 »

Hi Chris,
Can you rename your current PPP folder which count be found in:
If 64 bit windows with flowcode V4 - C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\Tools
If 32 bit windows with flowcode V4 - C:\Program Files\Matrix Multimedia\Flowcode V4\Tools
Then unzip the attached files in the ....tools folder.
Yoy may need to up zip to a non portected folder, then cut and paste PPP from zip file to the correct folder.
If you still have problems after, then I may be able to help you further.

Martin
Attachments
PPP.zip
(1.32 MiB) Downloaded 414 times
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

OK - it was the TITLE that mentioned 683 BUT I see now that it programmed successfully because; having gone back to the 1840 it naturally set the defaults in the enable/disable list so - although I havent tried it yet - could you let me know what I actually need to CHANGE in that list - I had obviously changed something I shouldn't have and vica versa! Also, what needs tweaking to get it to run continuously rather than one pass which it also did with the F88?
Thanks,
Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Thanks Martin re PPV3 and I will do that anyway which will be good to get updated. Would also be great if you can just let me know re the points in the post I just sent.
Thanks muchly, Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: PIC output for piezo transducer

Post by christoph »

Hi Martin, I did the PPP 'update', yes I had to cut and paste but it is all there but it still appears to be v3 - same as what I had. What do I need to do next - run the .exe? Do I delete the original one with my name change? (bit out of my territory this manipulation business!)

Post Reply