alpha91
Full Member level 3
- Joined
- Sep 23, 2011
- Messages
- 168
- Helped
- 1
- Reputation
- 2
- Reaction score
- 2
- Trophy points
- 1,298
- Activity points
- 2,625
Hi all, is that possible to implement timer interrupt to a LED fading PWM function?
microcontroller: 16F628A
compiler: MikroC
Objective:
LED fade in and out slowly by adjusting the PWM.
I had developed a code that working in this way
using timer so slowly increase the PWM duty cycle. However, it did not work out to be what i imagine.
The reason why i need this is because i need to insert this function into another program which able t change the PIC mode with LED blinking function (using interrupt timer as well).
My code is as below:
Thank you.
microcontroller: 16F628A
compiler: MikroC
Objective:
LED fade in and out slowly by adjusting the PWM.
I had developed a code that working in this way
using timer so slowly increase the PWM duty cycle. However, it did not work out to be what i imagine.
The reason why i need this is because i need to insert this function into another program which able t change the PIC mode with LED blinking function (using interrupt timer as well).
My code is as below:
Code:
signed int i = 0;
void InitTimer1()
{
T1CON = 0x31;
TMR1IF_bit = 0;
TMR1IE_bit = 1;
INTCON = 0xC0; //
}
void Interrupt() {
if(TMR1IF_bit)
{
for(i = 0; i < 256; i += 10) // LED is glowing with delay by using timer
{
PWM1_Set_Duty(i);
TMR1H = 0x4E; // set timer
TMR1L = 0x20; // set timer
}
for(i = 250; i >= 0; i -= 10) // LED is fade out with delay by using timer
{
PWM1_Set_Duty(i);
TMR1H = 0x4E; // set timer
TMR1L = 0x20; // set timer
}
TMR1IF_bit = 0;// reset trigger bit
}
}
void main()
{
TRISB = 0x00;// B3 PWM output
PWM1_Init(5000); // Initialize PWM frequency
//PWM1_Set_Duty(127);
PWM1_Start();
while (1) {
}
}
Thank you.