PWM-QG8-Sinewave Lookup Table

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PWM-QG8-Sinewave Lookup Table

2,597 Views
abicash
Contributor III

Hello

 

I am trying to generate a variable frequency (few Hz to 100 Hz) PWM waveform to drive an H-Bridge.

A Potentiometer varies a voltage which in turn varies the Frequency.

 

How should i proceed with this?

 

1)I have used native PWM CH0 pin as Edge-aligned PWM.

2)I use a 256 byte LUT(Look up table)

3)PWM frequency 15.625 Khz

4)Used Timer overflow interrupt to update Duty cycle from LUT value.

5)Haven't yet implemented ADC-->PWM updates.

 

What I need is a guideline, as to, what should be the best method and limitations etc with QG8.

Also am not sure how i will change the frequency (up to 100 Hz) with this.

 

Please someone throw some light....

Best Rgds

Abhijit

Labels (1)
0 Kudos
Reply
3 Replies

1,485 Views
iansmusical
Contributor V

Hi Abhijit,

I'm going to take a bit of a theoretical guess here but I'm wondering if you need to set your PWM CH0 frequency via the ADC value (with appropriate mappings and to set the amplitude of the sine wave) as that will give you your few Hz to 100Hz frequency as opposed to using a fixed 15.625KHz period. The 256 LUT values would provide the sine wave values that occur each PWM period but would 256 value be enough to get a good sine wave (a bit like with PWM LED brightness)?

Ian

0 Kudos
Reply

1,485 Views
abicash
Contributor III

Hello Ian

Thanks for taking interest in my post :smileyhappy:

Well actually, even a 64 byte LUT would be sufficient to get a passable Sinewave for me.

What i am doing in my Overflow interrupt is below

#define TIMER_START              0x49 //8MHz/2= 4MHZ = 250ns

#define Channel0_Start             0x24

#define TIMER_OVERFLOW            256 //256x250ns=64usec = 15625 Hz

interrupt 7 void TimerCH0 (void)
{
  // Ack Timer
  TPMSC_TOF =0;

  

TPMC0V=sinewave[iteration++];

     if(iteration==256)iteration=0;

}

So now what is expected is that the Duty cycle is varied at each overflow to get me a 50Hz output wave.

The ADC input should come in picture if i have to vary the output frequency to say 100Hz or 25Hz or whatever is scaled by the ADC input.

Can you define a standard approach which i am not able to understand here?

0 Kudos
Reply

1,485 Views
iansmusical
Contributor V

Hi Abhijit,

You're welcome although admittedly I haven't ever tried generating a sine wave myself :smileyhappy: but I am familiar with LED PWM.

I might have got myself mixed up but for a 50Hz output you need a period of 20ms. Within the 20ms you have to subdivide by 256 values meaning each duty cycle pulse will be around 78us in length. So, I think in the interrupt marking the overflow you are doing the right thing by selecting the next duty cycle value. However, and this is where I might be mixed up but you can also generate an interrupt when the duty cycle is matched and I'm wondering if it is there that you need to apply the next duty cycle value, i.e. so that 256 values occur between one 20ms period!?

Again the ADC value after transforming it will either adjust the period or duty cycle pulse width I think. As for the amplitude of the sine wave that is just a case of changing the size of the values in the LUT.

I hope that helps and doesn't confuse :smileywink:

Ian

0 Kudos
Reply