16F877 pwm duty cycle
Napsal: 25 led 2011, 22:57
Zdravim, poradi nekdo jak zmerit sirku nuly a jednicky jednoho pulzu? Chtel bych na to pouzit metodu capture.
Nasel sem nekde priklad, ale nejak jsem to nepochopil. Meri to, ale hodnota je spatna. Merim stridu cidla smt160. Prinejhorism se to da asi zmerit timerem, ale takhle se mi to zda jednodusi.
Nasel sem nekde priklad, ale nejak jsem to nepochopil. Meri to, ale hodnota je spatna. Merim stridu cidla smt160. Prinejhorism se to da asi zmerit timerem, ale takhle se mi to zda jednodusi.
Kód: Vybrat vše
void interrupt() {
if(PIR1.F2 == 1) // if CCP1 Edge Detected (CCP1 Interrupt)
{
PIR1.F2 = 0; // Reset CCP1IE
if(CCP1CON.F0 == 1) // if Rising Edge detected
{
Leading = CCPR1L| CCPR1H<<8; // Copy CCPR1 to Leading Edge var
CCP1CON.F0 = 0; // Set to falling edge
} // END Rising Edge
else if(CCP1CON.F0 == 0) // If Falling Edge Detected
{
Capture = CCPR1L | CCPR1H<<8; // Copy CCPR1 to Falling Edge var
Capture = Capture - Leading ; // Calculate Pulse Width
CCP1CON.F0 = 1; // Set to Traling edge
}// END Falling Edge
}// END CCP1 Interrupt