//==============================================================================
// Config COMPARATOR
//==============================================================================
void init_CMP(void)
{
CMPCON1bits.CMPON = 0; // CMP1 Desabilitado p/ config
CMPCON1bits.CMPSIDL = 1; // Não funciona no modo IDLE
CMPCON1bits.INSEL = 11; // Select CMP1A input
CMPCON1bits.EXTREF = 0; // Choose internal reference
CMPCON1bits.RANGE = 1; // referencia interna depende da
// configuração do registro abaixo
CMPCON1bits.CMPPOL = 0; // ativo em modo alto
// Tensao de ref de 1V
CMPDAC1 = 630; // Choose comparator reference
// (CMREF (Avdd/2)/1024)
CMPCON1bits.CMPON = 1; // Habilita comparador
}
//=============================================================================
//
//=============================================================================
void testePWM(void)
{
PTCONbits.PTEN = 0;
IOCON1bits.PENH = 1; /* PWM1 outputs controlled by PWM */
IOCON1bits.PENL = 1; /* module */
IOCON1bits.PMOD = 0b10; /* Choose Independent PWM mode */
IOCON1bits.FLTDAT = 0; /* Turn OFF both PWM1 outputs
in case of a fault condition */
IOCON1bits.POLL = 0; // PWM1L is active low
IOCON1bits.POLH = 0; // PWM1H is active low
PWMCON1bits.DTC = 2; /* Dead time function disabled */
PWMCON1bits.IUE = 1; // Atualizaçao instantanea do DUTY CYCLE
FCLCON1bits.FLTSRC = 0; //1 /* Comparator is Fault source */
FCLCON1bits.FLTPOL = 0; //1 /* 0 = ativo em high, 1 = ativo em low */
FCLCON1bits.FLTMOD = 0; //1 /* FLTDAT from IOCONx register
FCLCON1bits.IFLTMOD = 0;
FCLCON1bits.CLMOD = 1;
IOCON1bits.FLTDAT = 0; /* Turn OFF both PWM1 outputs
in case of a fault condition */
PTPER = 18900; /* PWM period of */
/* Period = PTPER*1.05nsec = 9.99us */
PTCONbits.PTEN = 1; /* Turn ON PWM module */
}