Antorbd04
- 30th March 2014, 22:37
feedback not working!!!!!
proteus & main mikro C file : 7288
DEFINE OSE 16
ON INTERRUPT GOTO ISR
'*************************VARIABLES
tblpointernew VAR WORD
tblpointerold VAR WORD
tblpointershift VAR WORD
setfreq VAR WORD
tbltemp VAR WORD
dutycycle VAR BYTE
flag VAR WORD
SINVAL VAR BYTE
FBV VAR BYTE
FBS VAR BYTE
ADDER VAR BYTE
direction VAR BIT
'*************************ALIAS
MOSA VAR PORTC.3
MOSB VAR PORTC.4
PEIE VAR INTCON.6
GIE VAR INTCON.7
TMR1IF VAR PIR1.0
TMR2IF VAR PIR1.1
TMR2IE VAR PIE1.1
'******************************
MAIN:
setfreq = 410
tblpointernew = 0
tblpointerold = 0
tblpointershift = 0
dutycycle = 0
TRISC = 0
PORTC = 0
PR2 = 249
CCPR1L = 0
CCP1CON = 12
TMR2IF = 0
T2CON = $04
TMR2IF = 0
TMR2IE = 1
GIE = 1
PEIE = 1
direction = 0
START:
ADCIN 0, FBV
IF FBV < 256 THEN
FBS = FBS + 1
IF FBS > 8 THEN FBS = 8
ELSE
IF FBS > 0 THEN FBS = FBS - 1
ENDIF
ADDER = FBS << 5
TMR1L = 0 : TMR1H = 0 : TMR1IF = 0
GOTO START
DISABLE
isr:
IF TMR2IF == 1 THEN
update:
tblpointernew = tblpointerold + setfreq
IF tblpointernew < tblpointerold THEN
IF direction == 0 THEN
mosa = 0
mosb = 1
direction = 1
ELSE
mosa = 1
mosb = 0
direction = 0
ENDIF
ENDIF
tblpointershift = tblpointernew >> 11
dutycycle = tblpointershift + ADDER
LOOKUP dutycycle, [0, 16, 32, 47, 62, 77, 91, 103, 115, 126, 136, 144, 151, 156, 160, 162, 163, 162, 160, 156, 151, 144, 136, 126, 115, 103, 91, 77, 62, 47, 32, 16,_ '65%
0, 17, 34, 51, 67, 82, 97, 111, 124, 135, 146, 154, 162, 167, 172, 174, 175, 174, 172, 167, 162, 154, 146, 135, 124, 111, 97, 82, 67, 51, 34, 17,_ '70%
0, 18, 37, 55, 72, 89, 104, 119, 133, 145, 156, 166, 174, 180, 184, 187, 188, 187, 184, 180, 174, 166, 156, 145, 133, 119, 104, 89, 72, 55, 37, 18,_ '75%
0, 20, 39, 58, 77, 94, 111, 127, 141, 155, 166, 176, 185, 191, 196, 199, 200, 199, 196, 191, 185, 176, 166, 155, 141, 127, 111, 94, 77, 58, 39, 20,_ '80%
0, 21, 42, 62, 82, 100, 118, 135, 151, 165, 177, 188, 197, 204, 209, 212, 213, 212, 209, 204, 197, 188, 177, 165, 151, 135, 118, 100, 82, 62, 42, 21,_ '85
0, 21, 43, 64, 84, 103, 122, 139, 155, 169, 182, 193, 202, 210, 215, 218, 219, 218, 215, 210, 202, 193, 182, 169, 155, 139, 122, 103, 84, 64, 43, 21,_ '87.5%
0, 22, 44, 65, 86, 106, 125, 143, 159, 174, 187, 198, 208, 215, 221, 224, 225, 224, 221, 215, 208, 198, 187, 174, 159, 143, 125, 106, 86, 65, 44, 22,_ '90%
0, 23, 45, 67, 88, 109, 128, 147, 163, 179, 192, 204, 213, 221, 227, 230, 231, 230, 227, 221, 213, 204, 192, 179, 163, 147, 128, 109, 88, 67, 45, 23],SINVAL '92.5%
CCPR1L = SINVAL
tblpointerold = tblpointernew
TMR2IF = 0
ENDIF
RESUME
ENABLE
proteus & main mikro C file : 7288
DEFINE OSE 16
ON INTERRUPT GOTO ISR
'*************************VARIABLES
tblpointernew VAR WORD
tblpointerold VAR WORD
tblpointershift VAR WORD
setfreq VAR WORD
tbltemp VAR WORD
dutycycle VAR BYTE
flag VAR WORD
SINVAL VAR BYTE
FBV VAR BYTE
FBS VAR BYTE
ADDER VAR BYTE
direction VAR BIT
'*************************ALIAS
MOSA VAR PORTC.3
MOSB VAR PORTC.4
PEIE VAR INTCON.6
GIE VAR INTCON.7
TMR1IF VAR PIR1.0
TMR2IF VAR PIR1.1
TMR2IE VAR PIE1.1
'******************************
MAIN:
setfreq = 410
tblpointernew = 0
tblpointerold = 0
tblpointershift = 0
dutycycle = 0
TRISC = 0
PORTC = 0
PR2 = 249
CCPR1L = 0
CCP1CON = 12
TMR2IF = 0
T2CON = $04
TMR2IF = 0
TMR2IE = 1
GIE = 1
PEIE = 1
direction = 0
START:
ADCIN 0, FBV
IF FBV < 256 THEN
FBS = FBS + 1
IF FBS > 8 THEN FBS = 8
ELSE
IF FBS > 0 THEN FBS = FBS - 1
ENDIF
ADDER = FBS << 5
TMR1L = 0 : TMR1H = 0 : TMR1IF = 0
GOTO START
DISABLE
isr:
IF TMR2IF == 1 THEN
update:
tblpointernew = tblpointerold + setfreq
IF tblpointernew < tblpointerold THEN
IF direction == 0 THEN
mosa = 0
mosb = 1
direction = 1
ELSE
mosa = 1
mosb = 0
direction = 0
ENDIF
ENDIF
tblpointershift = tblpointernew >> 11
dutycycle = tblpointershift + ADDER
LOOKUP dutycycle, [0, 16, 32, 47, 62, 77, 91, 103, 115, 126, 136, 144, 151, 156, 160, 162, 163, 162, 160, 156, 151, 144, 136, 126, 115, 103, 91, 77, 62, 47, 32, 16,_ '65%
0, 17, 34, 51, 67, 82, 97, 111, 124, 135, 146, 154, 162, 167, 172, 174, 175, 174, 172, 167, 162, 154, 146, 135, 124, 111, 97, 82, 67, 51, 34, 17,_ '70%
0, 18, 37, 55, 72, 89, 104, 119, 133, 145, 156, 166, 174, 180, 184, 187, 188, 187, 184, 180, 174, 166, 156, 145, 133, 119, 104, 89, 72, 55, 37, 18,_ '75%
0, 20, 39, 58, 77, 94, 111, 127, 141, 155, 166, 176, 185, 191, 196, 199, 200, 199, 196, 191, 185, 176, 166, 155, 141, 127, 111, 94, 77, 58, 39, 20,_ '80%
0, 21, 42, 62, 82, 100, 118, 135, 151, 165, 177, 188, 197, 204, 209, 212, 213, 212, 209, 204, 197, 188, 177, 165, 151, 135, 118, 100, 82, 62, 42, 21,_ '85
0, 21, 43, 64, 84, 103, 122, 139, 155, 169, 182, 193, 202, 210, 215, 218, 219, 218, 215, 210, 202, 193, 182, 169, 155, 139, 122, 103, 84, 64, 43, 21,_ '87.5%
0, 22, 44, 65, 86, 106, 125, 143, 159, 174, 187, 198, 208, 215, 221, 224, 225, 224, 221, 215, 208, 198, 187, 174, 159, 143, 125, 106, 86, 65, 44, 22,_ '90%
0, 23, 45, 67, 88, 109, 128, 147, 163, 179, 192, 204, 213, 221, 227, 230, 231, 230, 227, 221, 213, 204, 192, 179, 163, 147, 128, 109, 88, 67, 45, 23],SINVAL '92.5%
CCPR1L = SINVAL
tblpointerold = tblpointernew
TMR2IF = 0
ENDIF
RESUME
ENABLE