jean12
Advanced Member level 2
- Joined
- Aug 27, 2013
- Messages
- 529
- Helped
- 5
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 18
- Activity points
- 5,497
sbit UP at RB5_bit; sbit DOWN at RB4_bit;
//const signed char sine_table[33] = {0,24,48,69,88,104,115,123,125,123,115,104,88,69,48,24,0,-24,-48,-69,-88,-104,-115,-123,-125,-123,-115,-104,-88,-69,-48,-24,0,};
const signed char sine_table[]={0, 25, 49, 73, 96, 118, 139, 159, 177, 193, 208, 220, 231, 239, 245, 249, 250, 249, 245, 239, 231, 220, 208, 193, 177, 159, 139, 118, 96, 73, 49, 25};
unsigned short new_DC,xx,yy,bb, newduty;
char t,ii;
unsigned char DUTY_CYCLE;
unsigned int TBL_POINTER_NEW1,TBL_POINTER_NEW2,TBL_POINTER_NEW3, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
void debounce()
{
delay_ms(300);
}
void interrupt()
{
if(TMR2IF_bit==1)
{
TBL_POINTER_NEW1=TBL_POINTER_OLD;
if(TBL_POINTER_NEW1<TBL_POINTER_OLD)
{
CCP1CON.P1M1=~CCP1CON.P1M1;
TBL_POINTER_OLD=0;
TBL_POINTER_SHIFT = TBL_POINTER_NEW1 >> 11;
}
TBL_POINTER_NEW1=sine_table[11];
if(TBL_POINTER_NEW1<TBL_POINTER_OLD)
{
CCP1CON.P1M1=~CCP1CON.P1M1;
TBL_POINTER_OLD=0;
TBL_POINTER_SHIFT = TBL_POINTER_NEW2 >> 11;
}
TBL_POINTER_NEW2=sine_table[22];
if(TBL_POINTER_NEW2<TBL_POINTER_OLD)
{
CCP1CON.P1M1=~CCP1CON.P1M1;
TBL_POINTER_OLD=0;
TBL_POINTER_SHIFT = TBL_POINTER_NEW2 >> 11;
}
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sine_table[DUTY_CYCLE];
TMR2IF_bit = 0;
}
}
/*
PWM1_set_duty(sine_table[newduty]);
if(newduty=sine_table[newduty]+11)
{
PWM1_set_duty(sine_table[newduty]+11);
}
else
PWM1_set_duty(sine_table[newduty]+22);
INTCON.TMR2IF=0;
}
} */
void main()
{
TRISA=0XFF;
TRISC=0XF0;
TRISB=0XF8;
CCP1CON=0X0C;
PSTR1CON=0X1F;
DUTY_CYCLE = 0;
PR2=249;
T2CON=4;
T2CON.TMR2ON=1;
T2CON.TMR2ON=1;
TMR2IF_bit=0;
while(TMR2IF_bit==0)
{
TMR2IF_bit=0;
TMR2IE_bit=0; //Enable Timer 2 Interrupr
GIE_bit=1; //Enable Global interrupt
PEIE_bit=0; //disable all peripheral interrupt
//PWM1CON= For dead time programming
}
PWM1_init(15000); //Initialise PWM at 15KHZ
while(1){
new_dc=0;
if(!(PORTA.B5)){
debounce();
if(new_dc<249)
new_dc=new_dc+5; //increment duty cycle
}
if(!PORTA.B4){
debounce();
if(new_dc!=0)
new_dc=new_dc-5; //decrement duty cycle
}
if(newduty!=new_dc)
{
newduty=new_DC;
PWM1_Start();
//PWM1_set_duty(sine_table[newduty]) ;
}
}
}
sbit UP at RB5_bit; sbit DOWN at RB4_bit;
const signed char sine_table[33] = {0, 3, 7, 10, 13, 16, 20, 23, 26, 29, 33, 36, 39, 42, 46, 49, 52, 55, 58, 62, 65, 68, 71, 74, 77, 80, 83, 87, 90, 93, 96, 99, 102, 105, 108, 111, 113, 116, 119, 122, 125, 128, 131, 133, 136, 139, 142, 144, 147, 150, 152, 155, 157, 160, 162, 165, 167, 170, 172, 174, 177, 179, 181, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 211, 213, 215, 217, 218, 220, 221, 223, 224, 226, 227, 228, 230, 231, 232, 233, 235, 236, 237, 238, 239, 240, 241, 241, 242, 243, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 250, 249, 249, 249, 249, 248, 248, 247, 247, 246, 246, 245, 245, 244, 243, 242, 241, 241, 240, 239, 238, 237, 236, 235, 233, 232, 231, 230, 228, 227, 226, 224, 223, 221, 220, 218, 217, 215, 213, 211, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 181, 179, 177, 174, 172, 170, 167, 165, 162, 160, 157, 155, 152, 150, 147, 144, 142, 139, 136, 133, 131, 128, 125, 122, 119, 116, 113, 111, 108, 105, 102, 99, 96, 93, 90, 87, 83, 80, 77, 74, 71, 68, 65, 62, 58, 55, 52, 49, 46, 42, 39, 36, 33, 29, 26, 23, 20, 16, 13, 10, 7, 3};
unsigned short new_DC,xx,yy,bb, newduty;
char t,ii;
unsigned char DUTY_CYCLE;
unsigned int TBL_POINTER_NEW1,TBL_POINTER_NEW2,TBL_POINTER_NEW3, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
void debounce()
{
delay_ms(300);
}
void interrupt()
{
if(TMR2IF_bit==1)
{
TBL_POINTER_NEW1=TBL_POINTER_OLD;
if(TBL_POINTER_NEW1<TBL_POINTER_OLD)
{
CCP1CON.P1M1=~CCP1CON.P1M1;
TBL_POINTER_OLD=0;
TBL_POINTER_SHIFT = TBL_POINTER_NEW1 >> 11;
}
TBL_POINTER_NEW1=sine_table[11];
if(TBL_POINTER_NEW1<TBL_POINTER_OLD)
{
CCP1CON.P1M1=~CCP1CON.P1M1;
TBL_POINTER_OLD=0;
TBL_POINTER_SHIFT = TBL_POINTER_NEW2 >> 11;
}
TBL_POINTER_NEW2=sine_table[22];
if(TBL_POINTER_NEW2<TBL_POINTER_OLD)
{
CCP1CON.P1M1=~CCP1CON.P1M1;
TBL_POINTER_OLD=0;
TBL_POINTER_SHIFT = TBL_POINTER_NEW2 >> 11;
}
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sine_table[DUTY_CYCLE];
TMR2IF_bit = 0;
}
}
/*
PWM1_set_duty(sine_table[newduty]);
if(newduty=sine_table[newduty]+11)
{
PWM1_set_duty(sine_table[newduty]+11);
}
else
PWM1_set_duty(sine_table[newduty]+22);
INTCON.TMR2IF=0;
}
} */
void main()
{
TRISA=0XFF;
TRISC=0XF0;
TRISB=0XF8;
CCP1CON=0X0C;
PSTR1CON=0X1F;
DUTY_CYCLE = 0;
PR2=249;
T2CON=4;
T2CON.TMR2ON=1;
T2CON.TMR2ON=1;
TMR2IF_bit=0;
while(TMR2IF_bit==0)
{
TMR2IF_bit=0;
TMR2IE_bit=0; //Enable Timer 2 Interrupr
GIE_bit=1; //Enable Global interrupt
PEIE_bit=0; //disable all peripheral interrupt
//PWM1CON= For dead time programming
}
PWM1_init(15000); //Initialise PWM at 15KHZ
while(1){
new_dc=0;
if(!(PORTA.B5)){
debounce();
if(new_dc<249)
new_dc=new_dc+5; //increment duty cycle
}
if(!PORTA.B4){
debounce();
if(new_dc!=0)
new_dc=new_dc-5; //decrement duty cycle
}
if(newduty!=new_dc)
{
newduty=new_DC;
PWM1_Start();
//PWM1_set_duty(sine_table[newduty]) ;
}
}
}
"pointerB = pointerA +160"
123,
127,
129,
133,
135,
139,
141,
145,
146,
150,
152,
156,
158,
162,
164,
167,
169,
173,
174,
177,
179,
182,
184,
187,
189,
192,
194,
197,
198,
201,
203,
205,
207,
209,
210,
213,
214,
216,
218,
219,
221,
222,
223,
225,
226,
227,
228,
229,
230,
231,
231,
233,
233,
234,
234,
235,
235,
235,
236,
236,
236,
236,
236,
235,
235,
235,
234,
233,
233,
232,
231,
231,
230,
229,
228,
227,
226,
224,
223,
222,
221,
218,
218,
215,
214,
212,
210,
208,
207,
204,
203,
200,
198,
195,
194,
191,
189,
186,
184,
181,
179,
176,
174,
171,
169,
165,
164,
159,
158,
154,
152,
148,
146,
142,
141,
137,
135,
131,
129,
125,
123,
119,
117,
113,
111,
107,
105,
101,
100,
96,
94,
90,
88,
84,
82,
79,
77,
73,
72,
69,
67,
64,
62,
59,
57,
54,
52,
49,
48,
45,
43,
41,
39,
37,
36,
33,
32,
30,
28,
27,
25,
24,
23,
21,
20,
19,
18,
17,
16,
15,
15,
13,
13,
12,
12,
11,
11,
11,
10,
10,
10,
10,
10,
11,
11,
11,
12,
13,
13,
14,
15,
15,
16,
17,
18,
19,
20,
22,
23,
24,
25,
28,
28,
31,
32,
34,
36,
38,
39,
42,
43,
46,
48,
51,
52,
55,
57,
60,
62,
65,
67,
70,
72,
75,
77,
81,
82,
87,
88,
92,
94,
98,
100,
104,
105,
109,
111,
115,
117,
121,
123,
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?