CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how can I generate pulses on clkin pin

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
saksun



Joined: 01 Jun 2017
Posts: 15

View user's profile Send private message

how can I generate pulses on clkin pin
PostPosted: Sat Jun 17, 2017 12:29 am     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Sat Jun 17, 2017 12:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 17, 2017 2:05 am     Reply with quote

Can you give any sample code for this??
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Jun 17, 2017 8:02 am     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Sat Jun 17, 2017 8:14 am     Reply with quote

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: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jun 17, 2017 1:31 pm     Reply with quote

'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: 19215

View user's profile Send private message

PostPosted: Sat Jun 17, 2017 2:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 19, 2017 4:39 am     Reply with quote

Quote:
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


I'm using magnetic buzzer part no. AV-9004-UP2-LF(RoHS).
http://www.buzzer-speaker.com/manufacturer/magnetic%20buzzer/smd/av-9004-up2.htm
http://www.buzzer-speaker.com/data%20sheet/magnetic%20buzzer/AV-9004-UP2-LF.pdf
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jun 19, 2017 5:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 19, 2017 6:59 am     Reply with quote

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: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jun 19, 2017 9:20 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group