[PIC] Explanation for the below mentioned code which is mikro c program

Status
Not open for further replies.

vinay.k

Newbie level 1
Joined
Mar 24, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
11

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const unsigned char SinLkUpTab[50]={0,8,16,24,31,39,47,55,62,70,77,85,92,99,
106,113,120,127,134,144,147,153,159,165,171,177,182,188,193,198,202,207,
211,215,219,223,226,229,232,235,238,240,242,244,246,247,248,249,250,250};
unsigned short cnt,inc,dec,sqinc,cnt1;
void interrupt()
{
if(dec==0)
{cnt++;
PWM1_Set_Duty(SinLkUpTab[cnt]);
}
else if(dec==1)
{cnt--;
PWM1_Set_Duty(SinLkUpTab[cnt]);
}
TMR1IF_bit=0;
TMR1H=0xFF;
TMR1L=0x76;
}
void main()
{
TRISB=0;
PORTC=0;
PORTB=0;
TRISC=0;
TRISA=0;
PORTA=0;
T1CON=0b00000001;
TMR1IF_bit=0;
TMR1H=0xFF;
TMR1L=0x76;
TMR1IE_bit=1;
cnt=0;
sqinc=0;
cnt1=0;
inc=0;
dec=0;
PWM1_Init(20000);
PWM1_Start();
INTCON=0xC0;
PORTA.b0=1;
while(1){
if(cnt==49&&dec==0)
{
dec=1;
}
else if(cnt==0&&dec==1)
{
PORTB.B1=~PORTB.B1;
dec=0;
}
}
}

 
Last edited by a moderator:

The program is self explanatory: It is an up/down counter that scans a table of values of a sinusoid to be loaded into PWM module of microcontroler, and represents the duty-cycle for the output. The code probably is part of an inverter. Depending on circuit topology, output B1 can be used to select the pair of devices that will be switched at current half cycle of the waveform.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…