Hola!!
Tienes razon, no fui claro a esso, desculpa.
Os exemplos ajudaram muito!! Aprendi mais com os problemas, faz poucos meses que estou utilizando C, e tenho muito que aprender. Estou terminando meu trabalho de conclusão de curso, e não encontrei em nenhum outro lugar um forum tão amistoso como todopic;
E por falar no forum, parabéns pelo layout! Esta muito bom!! Gracias
Infelizmente não consegui controlar a intensidade do LED na porta PWM como esperava, a resposta do LED ao trem de pulsos é muito rápida, e não consigo um controle linear fazendo a média entre VCC e 0.
Não imagino como aproveitar o PWM para controlar a intensidade de um LED tomando como base a tensão media de um trem de pulsos.
Talvez me falte algum conceito para aplicar o processo nesse sentido,
DATA = (0 a F pela serial, caracter por caracter)
/** PWM ***********************************************************/
// pwm_PR1[0]=(DATA & 0x0F); // ex:DATA =
// pwm_PR1[1]=(DATA & 0x0F); // ex:DATA =
// pwm_PR2[0]=(DATA & 0x0F); // ex:DATA =
// pwm_PR2[1]=(DATA & 0x0F); // ex:DATA =
pwm_PER[0]=(DATA & 0x0F); // ex:DATA = 3
pwm_PER[1]=(DATA & 0x0F); // ex:DATA = 2
pwm_DCY[0]=(DATA & 0x0F); // ex:DATA = 1
pwm_DCY[1]=(DATA & 0x0F); // ex:DATA = F
pwm_DCY[2]=(DATA & 0x0F); // ex:DATA = F
TRISCbits.TRISC2=0; // Pass 1 - C2 is out
// PR2 = ((byte*)pwm_PR2); // Pass 2 - Period by PR2 Register 0 - FF
// CCPR1L = ((byte*)pwm_PR1); // Pass 5 - PWM Duty cycle 0 - FF
OpenTimer2( TIMER_INT_OFF & T2_PS_1_1 & T2_POST_1_1); // Pass 9
OpenPWM1((byte*)pwm_PER); // char periodo : [(period ) + 1] x 4 x TOSC xTMR2 prescaler. 0 - FF
SetDCPWM1((byte*)pwm_DCY); // unsigned int dutycycle 0 - 3FF
CCP1CON=0b00001100; // Pass 4 - PWM: Single CCP CCP1
// DEBUG
// void OpenPWM1(unsigned char period)
// {
// CCPR1L = 0x00; // Power on reset(POR) for duty cycle
// CCP1CON = 0x0F; // PWM for CCP1
// PR2 = period; // Set period
// TRISC.CCP1 = 0; // Set ouput
// }
// void SetDCPWM1(unsigned long duty_cycle)
// {
// CCPR1L = duty_cycle >> 2; // Place 8 MSbs in CCPR1L
// duty_cycle = (duty_cycle << 4) & 0x30; // Place 2 LSbs in CCP1CON
// CCP1CON = CCP1CON | duty_cycle;
// }
No tieno pinas libre en PIC, senão uno conversor DA seria bueno.
Una duda, PWM és capaz de controla una salida linearmente (0 a 5vcc)?
Saludo!