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
Posted: Tue Sep 18, 2007 4:07 am
Using a timer interrupt, you can generate a 50Hz square wave NOT sine.
fedetouz
Joined: 01 Aug 2007 Posts: 14
Posted: Tue Sep 18, 2007 6:45 am
you need a dsPIC for generate 50Hz sine function.
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
Do it this way
Posted: Tue Sep 18, 2007 10:01 am
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.
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