0

Can someone please guide me how to generate lookup table for generating 50 hz sine wave using PWM in Atmega32.

This is what i have done so far but confused of what to do.

50 Hz sine wave so 20 ms time period 256 samples (No. of divisions)

step i need to increase = 20 ms/256 = 0.078125 ms (Period of PWM signal)

angle step rate = 360/256 = 1.40625

Amplitude of sine wave should be 1.

Atmega32
  • 1
  • 2
  • 4

1 Answers1

0

I think you are starting from the wrong end and getting lost because of that.

Ignoring the lookup table, can you generate a 50 Hz PWM signal usign explicit calls to sin() ? Good. Now the lookup table saves you those expensive sin calls. sin is a periodic function, so you need to store only one period (*). How many points that are depends on your digital output frequency, which is going to be much more than 50 Hz. How much more defines the number of points in your lookup table.

To fill your lookup table, you don't send the result of your PWM function to the digital output but youwrite it to the lookup table. To use the lookup table, you don't call the expensive function but you just copy the table entries straight to your output.

There is one common optimization: A since function has a lot of repetition. You don't need to store the send half, that's just the inverse of the first half, and the second quarter is just the first quarter mirrored.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Could you please give some more info about how am i suppose to create a lookup table i am completely newb to lookup table thing – Atmega32 May 03 '14 at 17:08