This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Keil

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()

}

Parents
  • 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?

Reply
  • 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?

Children
No data