interrupt problem pic18f4620

Status
Not open for further replies.

mr.man

Newbie level 6
Joined
Jan 17, 2013
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,371
I have problem when debug this code using mikroC.........


unsigned char sin_table[158]={0,3,6,9,12,15,18,21,24,27,30,
33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,
96,99,102,105,107,110,113,116,119,122,125,127,130,133,136,138,
141,144,147,149,152,155,157,160,163,165,168,170,173,175,178,180,
183,185,188,190,193,195,197,200,202,204,207,209,211,214,216,218,
220,222,227,229,231,233,235,237,239,241,243,245,246,248,250,252,
254,255,257,259,261,262,264,266,267,269,270,272,273,275,276,277,
279,280,282,283,284,285,287,288,289,290,291,292,293,294,295,296,
297,298,299,300,301,302,303,304,304,305,306,306,307,307,308,308,
309,309,309,310,310,310,311,311,311,311,311,311,311,311,312};

unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;

void interrupt(){

TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW == 312){
CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge
}

DUTY_CYCLE = TBL_POINTER_NEW;
TBL_POINTER_NEW >>8;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
PIR1 = 0;

}

void main() {
SET_FREQ = 1;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
PR2 = 312;
TRISC = 0x3F;
CCP1CON = 0x4C;
PIR1 = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (PIR1 == 0);
PIR1 = 0;
TRISC = 0;
PIE1 = 0x02;
INTCON =0xC0;

while(1);
}


when it goes to the interrupt function, suppose TBL_POINTER_NEW = 1(0+1=1) but it show 256. Is it something wrong with this code. Thank you...
 

actually i try to shifting TBL_POINTER_NEW into 8 bit( since i got 256=1 0000 0000). So, it should get 1 right. But even, i change into TBL_POINTER_NEW>>=8 or i delete TBL_POINTER_NEW>>8 line, it still show 256 as answer. But when i try to implement this code with pic16f684(but with small sine table), it show the right answer.
 

Change DUTY_CYCLE to unsigned int variable and see if it works. Values greater than 255 can't be assigned to CCPR1L because it is a 8 bit register.
 
Last edited:

Post your project files in a zip file. What compiler do you use? Have you selected the right device for your project?

Explain what this part of code does?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
PR2 = 312;
TRISC = 0x3F;
CCP1CON = 0x4C;
PIR1 = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (PIR1 == 0);
PIR1 = 0;
TRISC = 0;
PIE1 = 0x02;
INTCON =0xC0;

 
Last edited:

i'm using MikroC PRO from Mikroelektronika, pic18f4620, frequency = 20MHz...
 

Attachments

  • interrupt prob.zip
    32.3 KB · Views: 64

Remove this line.

Code:
TBL_POINTER_NEW >>8;

Another thing I see in your code is that in the sine table, you have quite a lot of values larger than 255, whereas you declared sin_table as an 8-bit variable:
Code:
unsigned [B]char [/B]sin_table[158]

Hope this helps.
Tahmid.
 
Reactions: mr.man

    mr.man

    Points: 2
    Helpful Answer Positive Rating

thank you, i think i already got the answer
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…