hi,
i've noted that my code produce inverted sine waveform and it is not the one i intend to produce,here is my complete code:
Code:
define OSC 20
;*****************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 = 0
;**************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 = 16
PR2 = 78 ;set for 16Khz HPWM(=32 steps*10 times*50hz)
CCP1CON = %000001100 ;set to pwm mode
T2CON=%00000100 ;enable timer2 and set timer2 prescaler value of 1:1
;****************A sine lookup table in an array********************************
sineval var byte[32]
sineval[0] = 148
sineval[1] = 167
sineval[2] = 185
sineval[3] = 200
sineval[4] = 210
sineval[5] = 222
sineval[6] = 228
sineval[7] = 230
sineval[8] = 228
sineval[9] = 222
sineval[10] = 212
sineval[11] = 200
sineval[12] = 185
sineval[13] = 167
sineval[14] = 148
sineval[15] = 128
sineval[16] = 108
sineval[17] = 89
sineval[18] = 71
sineval[19] = 56
sineval[20] = 43
sineval[21] = 34
sineval[22] = 28
sineval[23] = 26
sineval[24] = 28
sineval[25] = 34
sineval[26] = 43
sineval[27] = 56
sineval[28] = 71
sineval[29] = 89
sineval[30] = 108
sineval[31] = 128
timerone var word
Temp VAR byte
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 = 62411 ;gives about 50 hz sine
Main:
pause 5
GOTO Main
'---[TMR1_INT - interrupt handler]------------------------------------------
sine:
TMR1L = timerone.byte0
TMR1H = timerone.byte1
Temp = SineVal[StepCount]
CCP1CON.4 = Temp.0 'Bit 0
CCP1CON.5 = Temp.1 'Bit
CCPR1L = Temp >> 2 'Bit 2-7
stepcount = stepcount +1
if stepcount = 32 then stepcount = 0
@ INT_RETURN
any idea on how to invert the wave form...?thanx in advance
Bookmarks