hello
I am bit confuse about the period. How can we generate 50micro second period using CAPCOM2 in XC164CS? Can anyone hwlp me plz?
I just want to produce 50micro second period PWM or u can say 20Khz. What should be the timer reload value?
Vivek
hi
I have provide my code here. It just produce the fix pulse width of 20 KHz. Now I want to change the pulse width but keep the frequency as 20KHz. I know here I provided on and off time and i can change that one to vary the width but some more flexibility so do I need to generate the another interuupt.
Cv1 and CV2 are the two registers values to compare
#include<XC164.h>
#include <stdio.h> /* standard I/O .h-file */
#define Period 0x007D /* 50u second */
#define cv1 0x003E /* TON*/ #define cv2 0x007D /* Toff*/
void CC16_event(void) interrupt 0x30{
if (CC2_CC16 == (int)cv1) { CC2_CC16 = cv2; } else { CC2_CC16 = cv1; } } void main (void) { DP9 |=0x0001; P9 |= 0x0001;
/* CAPCOM unit 2 used */ CC2_T78CON &= 0xFF00; /* Reset time 7 in timer CC2_T78CON |= 0x0000; CC2_T7REL = Period; /* Set timer T7 reload CC2_T7 = Period; /* reset T7 register */ CC2_M4 &= 0xFFF0; /* Reset CAPCOM2 CC2_M4 |= 0x0005; /* Initialise Compare mode 1*/ CC2_CC16= cv1;
CC2_CC16IC= 0x0044; /* enable CC16 interrupt, ILVL =1, GLVL =0 */
CC2_T78CON_T7R = 1; /* start T7 */
PSW_IEN = 1; /* allow all interrupts */
while(1); { } }
Come back with some code you have written and: - what hardware you are running it on - what timer constants you have been using - how you computed your timer constants - what frequency you expected - what result (frequency or other result) you really got
Then someone on this forum will be able to help you by pointing out what you did wrong.
View all questions in Keil forum