View previous topic :: View next topic |
Author |
Message |
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
60 Cycle Power divided into 255 segments |
Posted: Fri Jun 13, 2008 10:50 am |
|
|
I am using a PIC16F715 processor on a project.
I am working on a design that requires one pulse of the incoming sine wave to be divided into 255 segments.
Basically I am turning on an output at some time after the sinewave passes zero. I am using an analog input to set how long after the zero crossing I delay before turning on the output hence the 255.
If I try using TMR0 to setup the delay timer I need to clock it at
(1/120) / 255 = 32.68 microseconds.
{(1/120) is the period of 1/2 of the 60 hertz sinewave}
Now for the problem:
The board is using a 10MHz crystal.
If I setup the TMR0 to increment for every 32 microseconds the program will be constantly interrupting.
Does anybody have a better Idea on how I can accomplish this task?
Thanks |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Jun 13, 2008 11:30 am |
|
|
How about having a zero crossing interrupt that loads the timer and enables the timer interrupt. The timer interrupt disables itself. You will have two interrupts per power cycle. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Fri Jun 13, 2008 11:41 am |
|
|
Unless I missunderstand your suggestion.
This would reduce the overhead when the delay between the zero crossing and the timer preset was short because the timer will stop interruptig after it times out until the next zero crossing.
But if the delay was long I would still be interrupting the TMR0 every 32uSeconds for almost the entire 1/2 cycle of the sine wave. |
|
|
Guest
|
|
Posted: Fri Jun 13, 2008 12:50 pm |
|
|
How about a slight variation. interrupt on the zero crossings as Doug said. On interrupts, either load the timer if counting down(scaled 0 - 255 in 1/2 cycle) or set to zero if counting up and then poll the adc and compare to Timer count, trigger when threshold matched or crossed.
I used this approach for a triac circuit controlling the power to a high wattage heater.
Rgds,
Dan |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Jun 13, 2008 1:20 pm |
|
|
Have the zero crossing interrupt set the timer to interrupt when the duty cycle is reached. The timer interrupt then shuts itself off. There is one interrupt at the zero crossing, then one interrupt when the desired duty cycle is reached, then another interrupt at the next zero crossing, etc.. The analog input changes to value the zero crossing interrupt loads into the timer for the timer interrupt. The timer interrupt is not periodic. It is a one-shot triggered by the zero crossing. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Fri Jun 13, 2008 2:22 pm |
|
|
Gentlemen,
Thank you for your input.
It is tough being the only engineer at my company.
I am grateful that you took the time to show me a better way to accomplish my objective.
I wrote a quick little program to implement your suggestions and it worked out great.
Thanks again, and have a great weekend. |
|
|
|