I noticed now that my programm is wrong. Without the sine look up table every thing works and i can generate 3 pwms with variable duty cycle and frequency... but when I add the sine look up table it dosent work anymore. I believe its cause my for loops just work all the time...I thinkg that my sine wave and my pwm ar not cuppeld together some how can anyonhelp me ?
#include "pwm01.h"
int sine[] = {2048,2305,2557,2802,3034,3251,3449,3625,3777,3901,3995,4059,4092,4092,4060,3996,3902,3778,3628,3452,3254,3037,2805,2560,2308,2051,1795,1542,1297,1065,847,649,473,321,197,102,37,4,4,35,99,193,316,466,642,839,1056,1288,1533,1785,2041};
static int k = sizeof(sine)/sizeof(int)/3; //length of the sine table =51
static int j= k*2; //(2/3)*50 length of the sine table
//static int test= sizeof(sine)/sizeof(int) ;
void setup()
{
// uint32_t pwm_duty =0.5* 65535;//2^16=65536
uint32_t pwm_freq2 = 30000;
// Set PWM Resolution
pwm_set_resolution(16);
// Setup PWM Once (Up to two unique frequencies allowed
//-----------------------------------------------------
pwm_setup( 7, pwm_freq2, 2); // Pin 7 freq set to "pwm_freq2" on clock B
pwm_setup( 8, pwm_freq2, 2); // Pin 8 freq set to "pwm_freq2" on clock B
pwm_setup( 9, pwm_freq2, 2); // Pin 9 freq set to "pwm_freq2" on clock B
// Write PWM Duty Cycle Anytime After PWM Setup
//-----------------------------------------------------
// pwm_write_duty( 7, pwm_duty ); // 75% duty cycle on Pin 7
// delay(30000); // 30sec Delay; PWM signal will still stream
// Force PWM Stop On All Pins
//-----------------------------
/* pwm_stop( 6 );
pwm_stop( 7 );
pwm_stop( 8 );
pwm_stop( 9 );*/
}
void loop()
{
while(1){
for(int i = 0; i<50;i++){
pwm_write_duty( 7, sine[i]*16 ); // 16 is a factor to improve the resoultion of the sine wave
pwm_write_duty( 8, sine[(i+k)%51]*16); // 75% duty cycle on Pin 8
pwm_write_duty( 9, sine[(i+j)%51]*16 ); // 75% duty cycle on Pin 9
delay(5); // The sine wave frequency is determinded in this way Sine index = 51*10 milli seconds delay= 510, Frequncy=1/510
}
}
}