PDA

View Full Version : sine wave inverter (modified tahmid mikro C 16f877 to 16f72) problem in: feedback



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

HenrikOlsson
- 31st March 2014, 06:20
OK!!!!!!
FBV is declared as a BYTE so IF FBV < 256 THEN will always evalute true. FBV can never be larger then 255 so FBS will always be incremented to 8 and then stay there.

/Henrik.

Antorbd04
- 31st March 2014, 09:38
OK!!!!!!
FBV is declared as a BYTE so IF FBV < 256 THEN will always evalute true. FBV can never be larger then 255 so FBS will always be incremented to 8 and then stay there.

/Henrik.

hmm.... you are right.
but from this blog (http://forum.allaboutcircuits.com/blog.php?b=512) i found that i convert to picbasic. but not working!!!!
can you solve this problem????

Antorbd04
- 31st March 2014, 10:42
OK!!!!!!
FBV is declared as a BYTE so IF FBV < 256 THEN will always evalute true. FBV can never be larger then 255 so FBS will always be incremented to 8 and then stay there.

/Henrik.

i ALSO TRY THE FOLLOWING CODE. BUT DON'T WORKING. PROTEUS OUTPUT::::
7289

pLZ HELP ME SIR.......



ADCIN 0, VOLT
FBV = FBV + VOLT
IF FBV = FBV + 30 THEN

HenrikOlsson
- 31st March 2014, 11:13
Hi,

THERE'S NO NEED TO SHOUT, WE HEAR YOU LOUD AND CLEAR!

Think about that last statement for a while.
When exactly do you expect FBV be equal to itself + 30? That's simply never going to evalute true because it will always compare itself to a larger value.

In PBP bytes and words are unsigned, they can never be less then zero. So something like IF A > 0 THEN will always evalute true.
When you do ADCIN 0, Volt the variable Volt will always be positive so FBV=FBV+Volt will keep accumulating FBV over and over and over again untill it overflows and starts over.

Finally, in the code in your first post you have DEFINE OSE 16, that's not correct and you don't seem to do any sort of setup for the ADC, manually or with DEFINEs - check the manual.

/Henrik.

Antorbd04
- 31st March 2014, 11:51
Hi,

THERE'S NO NEED TO SHOUT, WE HEAR YOU LOUD AND CLEAR!

Think about that last statement for a while.
When exactly do you expect FBV be equal to itself + 30? That's simply never going to evalute true because it will always compare itself to a larger value.

In PBP bytes and words are unsigned, they can never be less then zero. So something like IF A > 0 THEN will always evalute true.
When you do ADCIN 0, Volt the variable Volt will always be positive so FBV=FBV+Volt will keep accumulating FBV over and over and over again untill it overflows and starts over.

Finally, in the code in your first post you have DEFINE OSE 16, that's not correct and you don't seem to do any sort of setup for the ADC, manually or with DEFINEs - check the manual.

/Henrik.

I am very sorry for that. But I need this project as soon as possible.

I hope your advise is correct but unfortunately I unable to understand what you say & what you order me to change in my code. If you give me the correct code then I will very happy.
Thanks.

Dave
- 31st March 2014, 13:25
I see that you have started a new thread. Looking for more code giveaways? Once again your statement:
"I hope your advise is correct but unfortunately I unable to understand what you say & what you order me to change in my code. If you give me the correct code then I will very happy." sounds like you know nothing about the project you are trying to re-create. It also sounds like you want everybody to drop everything they are doing to write your code for you when you say:
"I am very sorry for that. But I need this project as soon as possible" Maybe you should have been studying the language and the project before the last minute.

Just my 2 cents.....