We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi everyone,
I know this is very little problem but i want to confirm this. My PWM programme and my ADC programme working fine if ican run them individiaully. But If i integrate together then it won't work. I dont know whats the problem. I provide my logic here.
#include<xc164.h>
void initCCU6(); PWM generation void initADC(); ADC initialisation
void main (void) { initCCU6(); initADC(); set ADCST=1 , start conversion while(1) { while(ADSBY=1) { change the duty cycle } return()
}
In my opinion I see some problems...
Every interrupt control register MUST have a unique value. The only exception is for level 0 which is not serviceable.
Perhaps something like this would be better.
CC2_CC16IC= 0x0044; /* enable CC16 interrupt, ILVL =1, GLVL =0 */ CC2_CC20IC= 0x0045; /* enable CC20 interrupt, ILVL =1, GLVL =1 */
I don't understand your code for the ADC. You start it by setting the ADST bit not the ADBSY bit. Secondly you should not poll the ADBSY bit directly after writing it as the peripheral takes some cycles for its state machine to update the status of the bit. You are better served to use the ADC interrupt or poll for the interrupt flag. Your code only performed ONE conversion and you never read the result so how should the duty cycle change from your potentiometer settting?