View previous topic :: View next topic |
Author |
Message |
saksun
Joined: 01 Jun 2017 Posts: 15
|
how can I generate pulses on clkin pin |
Posted: Sat Jun 17, 2017 12:29 am |
|
|
Hi...
I'm using ccs vs-5.017d and working on pic16f526.
I connected switch to clkin pin and buzzer to clkout pin of my controller. I want to turn on buzzer using clk pulse.
That pin is working as io...how should i configure that pin as clk?
How can i generate clk pulses on clkin pin using internal oscillator??
Which fuses i have to use in my code??
Thanks in advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Jun 17, 2017 12:41 am |
|
|
You can't.
The only way to develop pulses on this pin, is to pulse it yourself from the software. You can generate pulses on the CLKOUT pin from the internal oscillator (clue in the name....).
Look at table 3-2 in the datasheet. What does it show as options on the CLKIN PIN?. What does it show as options on the CLKOUT pin?. |
|
|
saksun
Joined: 01 Jun 2017 Posts: 15
|
|
Posted: Sat Jun 17, 2017 2:05 am |
|
|
Can you give any sample code for this?? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Jun 17, 2017 8:02 am |
|
|
It's not going to be any use to you for a 'buzzer'. Just a continuous clock at 1/4 the oscillator frequency.
The only practical way to drive a buzzer, is going to be by coding a pulse train. Ideally shift to a more sophisticated PIC that has a PWM, then you can program this to a frequency the suits your buzzer, and turn it on/off at will. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Jun 17, 2017 8:14 am |
|
|
It's not going to be any use to you for a 'buzzer'. Just a continuous clock at 1/4 the oscillator frequency.
The only practical way to drive a buzzer, is going to be by coding a pulse train. Ideally shift to a more sophisticated PIC that has a PWM, then you can program this to a frequency the suits your buzzer, and turn it on/off at will. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Jun 17, 2017 1:31 pm |
|
|
'buzzer' is a generic term...
There are electromechanicl 'buzzers' and you do NOT want to hookup one to a PIC I/O pin ! Odds are real good you'll destroy the PIC.
There are piezo 'buzzers', those MAY be able to be attached to a PIC i/o pin.
When posting questions you should always post the part number, better yet a 'link' to the devices you want to use. That way we can easily decide if it's a good part for you.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Jun 17, 2017 2:41 pm |
|
|
Assuming this is a Piezo sounder, then you can generate a signal on it by simply toggling the output pin at an interval. The problem is if the code wants to do anything else, it has to stop toggling and do the other job. This is where hardware to generate the pulses comes in. Also a lot depends on the clock speed of the processor, and the frequency the sounder needs.
So (for instance), you can generate about a 1KHz tone for one second like:
Code: |
#define SOUNDER_PIN pin_you_want
int16 ctr;
for (ctr=0;ctr<1000;ctr++)
{
output_toggle(SOUNDER_PIN);
delay_us(495);
}
|
However do anything else, and the tone will change. |
|
|
saksun
Joined: 01 Jun 2017 Posts: 15
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Mon Jun 19, 2017 5:00 am |
|
|
It's good that you posted the part mumber ! I was able to get the datasheet and can tell you that
1) you will need to add the resistor/transistor/diode as they show on page 2 or 3 of the data sheet. That buzzer can draw over 100 ma so if you connect directly to the PIC you WILL destroy the PIC.
2) good news the PIC is rated for 3 volt operation, same as the buzzer, so you should be able to run off say 2 'D' sized batteries for some time...
3) you'll need to 'pulse' the pin at about 2600 HZ to get maximum noise from the buzzer. Unfortunately that PIC does not have an onboard PWM module as such is not a good choice, it also does NOT have ANY interrupts, that I could see !
Jay |
|
|
saksun
Joined: 01 Jun 2017 Posts: 15
|
|
Posted: Mon Jun 19, 2017 6:59 am |
|
|
Quote: | 1) you will need to add the resistor/transistor/diode as they show on page 2 or 3 of the data sheet. That buzzer can draw over 100 ma so if you connect directly tot he PIC you WILL destroy the PIC. |
I did this all but i can't getting how to do coding for this.......???
And also i want to sound buzzer only when switch is closed for 15s otherwise not...... is this condition is possible?? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Mon Jun 19, 2017 9:20 am |
|
|
Mr T, in a previous reply shows some of the code you need.
Actually you should start with the simple '1Hz LED' program. It will flash an LED at about 1Hz. When running, it will confirm you can make code, compile without errors and download the code into the PIC. It also confirms your 'fuses' are correct, proper wiring , etc.
As for the no buzz until switch closed for 15 seconds. Yes, it is possible to code for that condition.
Jay |
|
|
|