hellow Henrik,
thanx for the tips, i've re-worked my sine table,also i've include the code for accuracy although i'm not sure if i've place it in a right place!
For a 4MHz xtal and TMR1 prescaler of 1 i reload the T1 with the value 64980 to get 50Hz and it's what m getting on the scope.
Also TMR2 with prescaler of 4 is loaded with 117 for the interrupt to be generated every 556us(256-(556/(4*0.25*4))
But the problem is that the waveform i'm getting on the scope is not smooth at all....Simulation results..pdf
code:
where i'm wrong in the code? are the calculations above correct?Code:define OSC 4 ;*****************VARIABLE DECLARATION****************************************** wsave VAR BYTE $70 SYSTEM ' alternate save location for W wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1 wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2 wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3 STEPCOUNT var byte 'Define stepcount as byte type variable stepcount = 36 ;**************SETTING THE REGISTERS WITH APPROPIATE BIT DEFINITION************* ADCON0 = %00000000 ADCON1 = %00000000 ;all anolog output trisb = %11111111 ;define porta as input trisc = %11111011 ;make ccp1/portc.2 an output pin trisa = %11111111 ;define porta as input TMR2 = 117 PR2 = 13 ;set for 18Khz HPWM(=36 steps*10 times*50hz) CCP1CON = %000001100 ;set to pwm mode T2CON=%00000110 ;enable timer2 and set timer2 prescaler value of 1:4 ;****************A sine lookup table in an array******************************** sineval var byte[36] sineval[0] = 128 sineval[1] = 148 sineval[2] = 167 sineval[3] = 185 sineval[4] = 201 sineval[5] = 215 sineval[6] = 227 sineval[7] = 235 sineval[8] = 240 sineval[9] = 242 sineval[10] = 240 sineval[11] = 235 sineval[12] = 227 sineval[13] = 215 sineval[14] = 201 sineval[15] = 185 sineval[16] = 167 sineval[17] = 148 sineval[18] = 128 sineval[19] = 108 sineval[20] = 89 sineval[21] = 71 sineval[22] = 55 sineval[23] = 41 sineval[24] = 29 sineval[25] = 21 sineval[26] = 16 sineval[27] = 14 sineval[28] = 16 sineval[29] = 21 sineval[30] = 29 sineval[31] = 41 sineval[32] = 55 sineval[33] = 71 sineval[34] = 89 sineval[35] = 108 timerone var word INCLUDE "DT_INTS-14.bas" ; Base Interrupt System ;********Define INT_Handler as ISR********************************************** ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, _sine, ASM, yes endm INT_CREATE ; Creates the interrupt processor ENDASM T1CON = %000001 ; Prescaler = 1, TMR1ON TMR1L = 255 TMR1H = 254 @ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts timerone = 64980 ;gives about 50 hz sine Main: pause 5 GOTO Main '---[TMR1_INT - interrupt handler]------------------------------------------ 'accuracy thing TimerShadow VAR WORD T1CON.0 = 0 'Stop TMR1 TimerShadow.HighByte = TMR1H TimerShadow.LowByte = TMR1L TimerShadow = TimerShadow + Timerone TMR1H = TimerShadow.HighByte TMR1L = TimerShadow.LowByte T1CON.0 = 1 'Restart TMR1 sine: TMR1L = timerone.byte0 TMR1H = timerone.byte1 CCPR1L = sineval[STEPCOUNT]>>1 stepcount = stepcount -1 if stepcount = 0 then stepcount = 36 @ INT_RETURN




Bookmarks