hello, every body i'm working with the AT89C5115 of ATMEL and i want to generate a square pulse of 40Khz using the PCA( PWM, the capture or the timer ). for the moment i coulndn't resolve the problem PCA counter registers (CL and CH) doesn't increment even activated. ? if some one have informations i'll be gratefull thanks in advance
swapna, How to do this depends a bit on your clock frequency. Take a look at the datasheet for your chip. On page 76 it details the CMOD register. Two of the bits in this SFT are used for selecting the source for the PWM. This is how you control the PWM's frequency. As you can see, it can be a fixed fraction of the clock frequency, or if you need a specific frequency, it can be clocked from an overflow on a timer. The duty cycle is set by using the CCAPxH and CCAPxL registers, where x is the number of the PCA module you're using as a PWM. What happens is that the PCA counter counts up from 0x00 to 0xFF. Whenever the value of the counter is BELOW the value in CCAPxL, the output on that PCA module's pin is LOW. Whenever the value is HIGHER than CCAPxL, the output is high. CCAPxH is important because you don't load new values into CCAPxL directly. You put the desired value in CCAPxH and the hardware loads it for you when the PCA counter overflows. There are, of course, other important details involved, like how to put the PCA into PWM mode, but these are ALL included in the cookbook that everyone keeps admonishing you to read. As far as assembly versus C, if you've included the header files from Keil, writing a value to a register is simple. For instance, if you want to load 0x55 into the CCON register, just write
CCON = 0x55;
jay, thank you for the information on PCA. it was a lot helpful. Also a thank you to Alicia for being so supportive. swapna