View previous topic :: View next topic |
Author |
Message |
salmankhalid16
Joined: 18 Dec 2009 Posts: 27
|
timer based 100hz cycle |
Posted: Fri Jun 13, 2014 9:32 am |
|
|
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: 9269 Location: Greensville,Ontario
|
|
Posted: Fri Jun 13, 2014 10:28 am |
|
|
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
|
|
Posted: Fri Jun 13, 2014 10:32 am |
|
|
Which is the most important, 100Hz frequency or 3ms delay
Mike |
|
|
salmankhalid16
Joined: 18 Dec 2009 Posts: 27
|
|
Posted: Fri Jun 13, 2014 10:40 am |
|
|
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
|
|
Posted: Sat Jun 14, 2014 6:30 am |
|
|
please help...... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 14, 2014 2:56 pm |
|
|
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
|
|
Posted: Wed Jun 18, 2014 10:31 am |
|
|
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
|
|
Posted: Wed Jun 18, 2014 2:12 pm |
|
|
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 |
|
|
|