Prev: Download & Read your favorite ebooks with eReader JE200
Next: COMP.DSP 2010 pictures and presentations
From: Codefragment on 15 Apr 2010 08:35 Hello, I hope someone can help me with what is probably a simple questions, but I am new at this! I wrote code to generate a sine wave by using the clock interrupt. Now, I have read a tutorial and think that this was the wrong way to do this because the example shows running an interrupt based on the pwm itself. What is the difference between how I wrote my code and the tutorial? (see the code below) The tutorial says PieVectTable.T1CINT = &T1_Compare_isr; PieCtrlRegs.PIEIER2.bit.INTx5 = 1; where I did: PieVectTable.TINT0=&cpu_timer0_isr; PieCtrlRegs.PIEIER1.bit.INTx7 = 1; interrupt void cpu_timer0_isr(void) { // Acknowledge this interrupt to receive more interrupts from group 1 CpuTimer0.InterruptCount++; intervaltimer++; if (intervaltimer%1000==0) { newvalue++; } if (newvalue>100) { newvalue=0; t=0; } t=t+((2*pi)/(100)); // iterations of sin wave x=30000*sin(t); //Determines duty cycle based upon sin value if (x>0) { EvaRegs.CMPR1= (long int) x; EvaRegs.CMPR2=0;//sets pin to zero to drive motor forward } if(x<0) { EvaRegs.CMPR1=0;//0x0000;//sets pin to zero to drive motor backwards EvaRegs.CMPR2= (long int) -x; } //x=sin(t); //Determines duty cycle based upon sin value PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; } |