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()
}
It would be helpful if you posted the source code and the exact errors.
and take care to read the instructions:
www.danlhenry.com/.../keil_code.png
Don't manually re-type the code into the post - use only copy-and-paste;
Note that TABs don't work (well) - use spaces instead,
and don't forget to check it in the 'Preview'...
And try to avoid the subject line "Keil" when posting on a Keil forum where every thread is about Keil...
Yesterday, I was working on some new logic. I will post my source code here. I connected the 0-5v potentiometer on one of the ADC pin but when i was changing the poetentiometer value the duty cycle doen't change. I solve that keil errors.
#include<XC164.h>
#include <stdio.h> /* standard I/O .h-file */ #include <math.h>
#define Period (0xFFFF - 0x00FA) /* 50u second period- (FFFF- 250H)*/
#define cv1 (0xFFFF - 0x00FA) /* TON*/ #define cv2 (0xFFFF - 0x00FA + 0x007D) /* Toff*/
//#define cv3 (0xFFFF- 0x00FA + 0x003E) /* 5us delay */ //#define cv4 (0xFFFF - 0x00FA +0x003E + 0x007D)
unsigned short usPhaseShift = 0x0019; /* 5us delay */
void CC16_event(void) interrupt 0x30{
if (CC2_CC16 == (int)cv1) { CC2_CC16 = cv2; } else { CC2_CC16 = cv1; } }
void CC20_event(void) interrupt 0x34{
if (CC2_CC20 == cv1+usPhaseShift) {
CC2_CC20 = cv2+usPhaseShift; } else {
CC2_CC20 = cv1+usPhaseShift; } }
void main (void) {
DP9 |=0x0011;/* P9.0 and P9.4: Output port associated with CC16(CC16IO) */ P9 |= 0x0011;
P5 |= 0x0001; /* Port 5 as an input port associated with AN0 */ P5DIDIS_P0 = 1; /* pin is used as analogue input channel */
/* CAPCOM unit 2 used */ // CC2_T78CON &= 0xFF00; /* Reset time 7 in timer mode*/ CC2_T78CON |= 0x0000; /* Set timer frequency: Binary 000, Staggred mode*/ CC2_T7REL = Period; /* Set timer T7 reload register */ CC2_T7 = Period; /* reset T7 register */
CC2_M5 &= 0xFF00; CC2_M5 |= 0x0005;
CC2_T8REL = Period;/* set timer T8 reload register */ CC2_T8 = Period; /* reset T8 register */
CC2_M4 &= 0xFF00; /* Reset CAPCOM mode register*/ CC2_M4 |= 0x0005; /* Initialise Compare mode 1*/
CC2_CC16= cv1; /* Initialise CC16 with compare value cv1 */ CC2_CC20= cv1+usPhaseShift;
CC2_CC16IC= 0x0044; /* enable CC16 interrupt, ILVL =1, GLVL =0 */ CC2_CC20IC= 0x0044;
CC2_T78CON_T7R = 1; /* start T7 */ CC2_T78CON_T8R = 1; /* start T8 */
PSW_IEN = 1; /* allow all interrupts */
/* Init ADC */ ADC_CON = 0x80; /* Enable A/D converter */ /* Start Convert on AD0BUSY set */
ADC_CON_ADBSY = 1;
while(1){ while (ADC_CON_ADBSY); /* Wait for conversion */ CV1 = 0x007D
} }
From your post, we can see that you do not read anything we write - or why else do you still fail to post the source code according the the link Andy mailed?
If you are in "output-only" mode, then we can ignore this thread...
maybe he can try the <SORCE> and <END_SUORCE> tags :-)
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?