View previous topic :: View next topic |
Author |
Message |
CMatic
Joined: 11 Jan 2012 Posts: 69
|
Fix length PWM pulse |
Posted: Mon Nov 02, 2015 11:53 pm |
|
|
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
|
|
Posted: Tue Nov 03, 2015 7:15 am |
|
|
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
|
|
Posted: Tue Nov 03, 2015 7:46 am |
|
|
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
|
|
Posted: Tue Nov 03, 2015 9:12 am |
|
|
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
|
|
Posted: Tue Nov 03, 2015 4:17 pm |
|
|
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
|
|
Posted: Tue Nov 03, 2015 5:50 pm |
|
|
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
|
|
Posted: Tue Nov 03, 2015 6:00 pm |
|
|
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
|
|
Posted: Tue Nov 03, 2015 6:05 pm |
|
|
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
|
|
Posted: Tue Nov 03, 2015 7:34 pm |
|
|
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
|
|
|
CMatic
Joined: 11 Jan 2012 Posts: 69
|
|
Posted: Tue Nov 03, 2015 10:36 pm |
|
|
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. |
|
|
|