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

i need to gen the 50HZ frq using TIMER0\1

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



Joined: 17 Sep 2007
Posts: 9
Location: Chennai-India

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

i need to gen the 50HZ frq using TIMER0\1
PostPosted: Mon Sep 17, 2007 3:04 am     Reply with quote

i need 0 gen the 50HZ frq using timer0\1 for inverter application....

that means i gen the 50Hz sinewave output
anestho



Joined: 27 Dec 2006
Posts: 28

View user's profile Send private message

PostPosted: Tue Sep 18, 2007 4:07 am     Reply with quote

Using a timer interrupt, you can generate a 50Hz square wave NOT sine.
fedetouz



Joined: 01 Aug 2007
Posts: 14

View user's profile Send private message

PostPosted: Tue Sep 18, 2007 6:45 am     Reply with quote

you need a dsPIC for generate 50Hz sine function.
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Do it this way
PostPosted: Tue Sep 18, 2007 10:01 am     Reply with quote

Construct a 256 (or 1024) lookup table with the approximate sine values.
Then select a PIC chip that has a hardware PWM and then feed the PWM registers with the values form the lookup table.

Read the table and stuff the value the PWM registers every 20mS/NVILT NVILT is Number Of Values In Lookup Table. Use a Timer to trigger next feed !

pquedo code:

global int1 Feed;

Timer ISR ()
{
Feed=1; // the ONLY thing you do in the timer ISR
}

int main()

int16 index=0;


while(1)
{
while( !Feed){;} // wait for next feed time

Set_PWM ( SineLookup[index] );
Feed=0;

// manage the index at 50Hz we have plenty of time even if it's a 4MHz system
index++;
if(index >= 1024)
{
index=0;
}

}

Adjust the timer period to adjust the frequency.

For 50Hz this works very well.

Of course the sine wave will be crude with small steps which is plenty good enough for DC-AC converter, if you filter the output a little you can get a better looking sinewave.

good luck
hans w
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