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 CCS Technical Support

Fix length PWM pulse

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



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

Fix length PWM pulse
PostPosted: Mon Nov 02, 2015 11:53 pm     Reply with quote

I am trying to generate a 100 msec pulse with pwm signal on it. I am going to use a 16F1825 part which has 3 different timers, namely Timer0 (8bits), Timer1(16bits with Gate input) and Timer2/4/6 (8bits).

I believe that I can generate a audible tone (say 2khz) using the Timer2 and then use its compare output pin to trigger timer1 so that I can get a 100 msec output.
I am able to generate the 2khz tone using Timer2, but unsure what to do for the gated Timer1 to produce the 100 msec pulse output. Thanks for suggesting a solution to this arrangement.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Nov 03, 2015 7:15 am     Reply with quote

perhaps i am having a language problem with
Quote:

a 100 msec pulse with pwm signal on it.


a 100 ms pulse is a PULSE IMHO with a single rise and fall time.

DO you mean you want a base FREQUENCY of 10HZ and wish to slice and dice it into variable PWM duty cycles? If so - the math you need to understand for master clock selection is included in the data sheet for he PIC you are using,
and you never say if the pulse is meant to repeat or just be triggered for one event.
temtronic



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

View user's profile Send private message

PostPosted: Tue Nov 03, 2015 7:46 am     Reply with quote

hmm.. I think he wants a 2KHz signal pulsed on for 100ms, then off for xx seconds....



Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19494

View user's profile Send private message

PostPosted: Tue Nov 03, 2015 9:12 am     Reply with quote

Problem is that if he tries to do this by stopping the source clock for the PWM, it could stop either off, or on.

I suspect he needs to be much simpler. Program a PWM, and have a timer (either just a delay, or a interrupt 'tick' based timer), which just switches the PWM on/off at the required time.

It isn't clear at all if he actually wants to vary the pulse width of the 'on' sections. The description if of a simple tone with no PWM....
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Nov 03, 2015 4:17 pm     Reply with quote

We are all unsure what you want.

It will help if you draw a picture of EXACTLY what's required.
(At this stage ignore the timers.)

Mike
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Nov 03, 2015 5:50 pm     Reply with quote

It would not harm anything if you were to at least mention the
PIC you are using and the clock you intend to use.

the clock frequency may turn out to be much
more important than you think.

also post the code you are using to make
that 2khz signal.

lastly posting your compiler version puts us all on the same
"revisionist" page ....

The amount and quality of help you receive depends greatly
on your ability to give US (accurate&&adequate ) information.
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Tue Nov 03, 2015 6:00 pm     Reply with quote

temtronic wrote:
hmm.. I think he wants a 2KHz signal pulsed on for 100ms, then off for xx seconds....



Jay


temtronic is correct, I just want a pwm signal to start and stop in 100 msec. I am going to use this for key pressed tones as audible feedback from users actions. The problem is that when you have a free running pwm signal, it is not precise enough to start and stop. I apologize for not being detailed enough the first time. Thanks in advance.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Nov 03, 2015 6:05 pm     Reply with quote

how precise do you need the timings to be?

what is the performance
specification for what you are trying to do?

can 100 msec time be +/- 5% ?

OR have 2 msec of jitter ??

how accurate the 2khz?
will 1910 hz or 2090 matter ?
+/- 5% good enough ?
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Tue Nov 03, 2015 7:34 pm     Reply with quote

asmboy wrote:
how precise do you need the timings to be?

what is the performance
specification for what you are trying to do?

can 100 msec time be +/- 5% ?

OR have 2 msec of jitter ??

how accurate the 2khz?
will 1910 hz or 2090 matter ?
+/- 5% good enough ?


Its not very precise, it can be +/- 5% or have some jitter like you have suggested. All I want is a 100msec duration of the PWM output signal with let say +/- 5% and some jitter. Hope this clarifies my requirement, it should not be exact or precise.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 03, 2015 8:38 pm     Reply with quote

This thread has a technique for outputting a specific number of pwm pulses:
http://www.ccsinfo.com/forum/viewtopic.php?t=41403
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Tue Nov 03, 2015 10:36 pm     Reply with quote

PCM programmer wrote:
This thread has a technique for outputting a specific number of pwm pulses:
http://www.ccsinfo.com/forum/viewtopic.php?t=41403


PCM programmer, thanks for the suggestion, it is working but I had another idea regarding using Timer1 (which has a gated input and using it with the compare output of Timer 2). Thanks for this thread suggestion.
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