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

60 Cycle Power divided into 255 segments

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



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

60 Cycle Power divided into 255 segments
PostPosted: Fri Jun 13, 2008 10:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 13, 2008 11:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 13, 2008 11:41 am     Reply with quote

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








PostPosted: Fri Jun 13, 2008 12:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 13, 2008 1:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 13, 2008 2:22 pm     Reply with quote

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.
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