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

18F46K22 number pulse generator

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



Joined: 07 Mar 2014
Posts: 3
Location: Moscow, Russian Federation

View user's profile Send private message Send e-mail

18F46K22 number pulse generator
PostPosted: Fri Mar 07, 2014 5:42 am     Reply with quote

Hi embedded systems experts! There is one problem: Need a code CCS to get the number of pulses. The required amount must be set programmatically, from 1 to 32767 pulses. Period and frequency should also be regulated. How do I start CCP1 module in this mode? Prompt please.... Crying or Very sad
Ttelmah



Joined: 11 Mar 2010
Posts: 19544

View user's profile Send private message

PostPosted: Fri Mar 07, 2014 6:03 am     Reply with quote

You don't....

You would have to use _two_ CCP modules.
One programmed as a PWM (to generate the pulses), and the other as a counter. The first you program as a normal PWM, and the settings for this control the frequency and pulse width. The second one you set to interrupt at a count (for the number of pulses), and when it interrupts you stop the PWM. The PWM output from the first has to be connected externally to the timer input for the second..
Alexandr



Joined: 07 Mar 2014
Posts: 3
Location: Moscow, Russian Federation

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 07, 2014 6:27 am     Reply with quote

Thank you Ttelmah! I guessed this. Need internal configuration module CCP1 & (synchronize)SPECIAL EVENT TRIGGER? Is that possible? Question
There is no free pins! Sad
Ttelmah



Joined: 11 Mar 2010
Posts: 19544

View user's profile Send private message

PostPosted: Fri Mar 07, 2014 8:20 am     Reply with quote

No.

If you run as a CCP (counter), you can't also run as a PWM.

However you could do it another way, if you have a timer available:

Setup a PWM, for the pulse frequency/width needed.
Calculate how long this will take to generate the number of pulses required.
Program a timer, so it'll overflow at this time (just before actually).
Start the PWM
Start the timer
When the timer interrupts, stop the PWM.

Best Wishes
Mike Walne



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

View user's profile Send private message

PostPosted: Sat Mar 08, 2014 3:30 am     Reply with quote

You don't tell us the range of period and frequency you want.

One other possibility:-

1) Set up a PWM.
2) Use the PWM clock to generate an interrupt.
3) Simply count the interrupts.

Or, if frequency is too fast to allow time for interrupt on every pulse.

1) Set up a PWM.
2) Use the PWM clock to generate an interrupt after say 16 cycles.
3) Adjust pulse count by 16 on each interrupt.
4) Poll the PWM output pin for the last few pulses.

.........................

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19544

View user's profile Send private message

PostPosted: Sat Mar 08, 2014 3:47 am     Reply with quote

Very much agreed.

Caveat (as with the timer approach, which is why I say 'just before actually', is that the PWM period updates on the next count. So you want to set the period to zero, a small fraction before you want it to stop.

Best Wishes
Alexandr



Joined: 07 Mar 2014
Posts: 3
Location: Moscow, Russian Federation

View user's profile Send private message Send e-mail

PostPosted: Mon Mar 17, 2014 8:21 am     Reply with quote

Mike Walne wrote:
You don't tell us the range of period and frequency you want.
1) Set up a PWM.
2) Use the PWM clock to generate an interrupt after say 16 cycles.
3) Adjust pulse count by 16 on each interrupt.
4) Poll the PWM output pin for the last few pulses.

.........................

Mike


Thank you all!
1. Free pin no have.
2. The output frequency from 10 Hz to 10 kHz.
3. Duty Cycle 10-90%.
Need to digest what was said. The last option I like more.
Repairs in the apartment, a little delayed topic!
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