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

timer based 100hz cycle

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



Joined: 18 Dec 2009
Posts: 27

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

timer based 100hz cycle
PostPosted: Fri Jun 13, 2014 9:32 am     Reply with quote

Hello all...
I am working on a project in which i have to generate a 100 hz waveform.
Now my code takes 7ms to complete all tasks, ie reading adc and sending data on serial port.
And 3ms is free time.
I want such code which generates an interrupt at start of every 10ms cycle. Then keeps the waveform high for 7ms until i do all my work and then lower the output for 3ms, which is free time, and then again generate an interrupt after 10ms.

Regards
temtronic



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

View user's profile Send private message

PostPosted: Fri Jun 13, 2014 10:28 am     Reply with quote

For starters you should tell us which PIC you're using !
There's a few dozen threads about this topic,even code in the library,again depends on your PIC type.
Depending on the PIC any number of timers could be suitable.
There's also the RTOS that might work,depending on the compiler version you have..

cheers
Jay
Mike Walne



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

View user's profile Send private message

PostPosted: Fri Jun 13, 2014 10:32 am     Reply with quote

Which is the most important, 100Hz frequency or 3ms delay

Mike
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

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

PostPosted: Fri Jun 13, 2014 10:40 am     Reply with quote

Thanks for the reply....
I am using pic16f876 and want to use timer 2...

I want a 10ms pulse, which ON time is 7ms during which i will do my adc reading and sending serial data and OFF time is 3ms...
salmankhalid16



Joined: 18 Dec 2009
Posts: 27

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

PostPosted: Sat Jun 14, 2014 6:30 am     Reply with quote

please help......
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 14, 2014 2:56 pm     Reply with quote

This thread has code to make a software PWM generator. It has an
interrupt routine that interrupts at a 100 Hz rate (once every 1 ms).
You can set the duty cycle for 70% and this routine will do what you need:
http://www.ccsinfo.com/forum/viewtopic.php?t=20050
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 10:31 am     Reply with quote

PCM programmer wrote:
This thread has code to make a software PWM generator. It has an
interrupt routine that interrupts at a 100 Hz rate (once every 1 ms).
You can set the duty cycle for 70% and this routine will do what you need:
http://www.ccsinfo.com/forum/viewtopic.php?t=20050

Since the OP also wants to synchronize A/D reading and other things with this 100Hz waveform, he will have to abandon whatever timing he is using now for the A/D reads and look inside the PWM code to find the place where the waveform is set high. But he cannot do his other work there because presumably it is too time-consuming to do inside the ISR. He will have to set a flag there and poll for that flag in the main program do decide when to start the other work that needs to be synchronized.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Mike Walne



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

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 2:12 pm     Reply with quote

RLScott wrote:
PCM programmer wrote:
This thread has code to make a software PWM generator. It has an
interrupt routine that interrupts at a 100 Hz rate (once every 1 ms).
You can set the duty cycle for 70% and this routine will do what you need:
http://www.ccsinfo.com/forum/viewtopic.php?t=20050

Since the OP also wants to synchronize A/D reading and other things with this 100Hz waveform, he will have to abandon whatever timing he is using now for the A/D reads and look inside the PWM code to find the place where the waveform is set high. But he cannot do his other work there because presumably it is too time-consuming to do inside the ISR. He will have to set a flag there and poll for that flag in the main program do decide when to start the other work that needs to be synchronized.

Your guess is as good as mine.
He is keeping us in the dark.
So we cannot help.

Mike
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