Discussion in "ARM Development" started by    mayank058    Jan 27, 2015.
Tue Jan 27 2015, 11:35 am
#1
dear sir,
I was working on a project pulse generation using mcb2300. Now I want to change this pulse into sine wave. so, please tell me how to change this pulse into sine wave...


[ Edited Tue Jan 27 2015, 02:16 pm ]
Thu Jan 29 2015, 11:46 am
#2
you need to vary your PWM from 0 to 100 and then 100 to 0... it will generate sinewave.
Fri Jan 30 2015, 12:32 pm
#3
dear sir,
please tell me how to do this.. I made a programme for this but it was not working properly..I am posting my programme code.. please tell me what type of corrections are required..


#include <lpc23xx.h>
#include <math.h>
#define PLOCK 0x00000400
#define PWM1PRESCALE 30
#define ANGLE_RES 1.8 //Angle Resoultion
#define PI 3.14159

void initPWM(void);

void initClocks(void);
void setupPLL(void);
void feedSeq(void);
void connectPLL(void);
void computeSineLookupTable(void);
void PWM_ISR(void) __irq;

char sineLookupTable[200];
int count=0;

int main(void)
{
initClocks();

computeSineLookupTable();

VICIntEnable |= (1<<8) ;
VICVectCntl0 = (1<<5) | 8 ;
VICVectAddr0 = (unsigned) PWM_ISR;

initPWM();
while(1){}


}

void computeSineLookupTable(void)
{
float angle;
int i;
for(i=0; i<200; i++)
{
angle = ( ((float)i) * ANGLE_RES );
sineLookupTable[i] = rint(100 + 99* sin( angle * (PI/180) ));
}
}

void PWM_ISR(void) __irq
{
long regVal = PWM1IR;

PWM1MR2 = sineLookupTable[count];
PWM1LER = (1<<2);
count++;
if(count>199) count = 0;

PWM1IR = regVal;
VICVectAddr = 0xFF;
}

void initPWM(void)
{



PINSEL3 = (0x02<<8);
PWM1PCR = 0x0;
PWM1PR = PWM1PRESCALE-1; // 0.5 micro-second resolution
PWM1MR0 = 200; // 200 ticks i.e 200x0.5=100ms period duration
PWM1MR2 = 100; // Initial pulse duration i.e width
PWM1MCR = (1<<1) | (1<<0); // Reset PWMTC & Interrupt on PWMMR0 match
PWM1LER = (1<<2) | (1<<0); // update MR0 and MR1
PWM1PCR = (1<<10); // enable PWM output
PWM1TCR = (1<<1) ; //Reset PWM TC & PR


PWM1TCR = (1<<0) | (1<<3); // enable counters and PWM Mode



}


void initClocks(void)
{
setupPLL();
feedSeq();
connectPLL();
feedSeq();

CCLKCFG = 0x01; // PCLK is same as CCLK i.e 60Mhz



}


[ Edited Fri Jan 30 2015, 02:26 pm ]
Wed Feb 04 2015, 11:05 am
#4
Well just keep it simple, You only need to change your duty cycle register. Take reference from your first code. MR0 is your rate register and MR2 is duty cycle.

Now change duty like this... (pseudo code)
MR0 = 200;
while (1) {
    for (i = 0; i < 200; i++) {
        MR2 = i;
        some_delay();
    }
    for (; i >
= 0; i--) {
        MR2 = i;
        some_delay();
    }
}


Your duty cycle will vary from 0 to 100 then to 0.
Wed Feb 04 2015, 03:21 pm
#5
dear sir,
It still not working.I think we need to pass this pulse train from a filter..so,the filter can convert these pulse into sine wave.,so,if it is possible to then tell me how to design a filter.
Thu Feb 05 2015, 09:59 am
#6
Well I think it was understood to convert PWM digital signal to analog you will need a Low pass filter (RC). I let you experiment with RC selection, here is what low pass filter will look like..
PWM Out----/\/\/\/\------
                        |
                        |
                      -----
                      -----
                        |
                       _|_
                       GND


If you want a better clean output, try using op-amp based LPF. Here are some links to get you started:
http://www.instructables.com/id/Analog-Output-Convert-PWM-to-Voltage/
I like this one: http://electronics.stackexchange.com/questions/34843/how-determine-the-rc-time-constant-in-pwm-digital-to-analog-low-pass-filter

Enjoy building it! its real fun
Thu Feb 05 2015, 12:21 pm
#7
dear sir,
I am not able to understand what u want to say..please tell me how to design LPF by using programme.
Fri Feb 06 2015, 06:34 pm
#8
LPF is a hardware circuit using resistor and capacitor, to smooth out your PWM signal. refer to links I have provided for more information.
Wed Feb 18 2015, 02:53 pm
#9
dear sir,
I want to use digital to analog converter to generate sine wave.so please tell me how can i do this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm