Dear friends,
i am ghanshyam gajjar. i have interface CS5460A to AT89c52. And generate PWM by using the AT89c52. I have no idea for how to generate the PWM using the AT89c52 because it has no any pwm channel. it is posible for using timer. please give me answer.
Thanks. ghanshyam gajjar.
You can emulate PWM using Timer as PWM puls oscillator. Here is an example of 8-bit PWM. Timer period must be equal <PWM_Period>/256. You can adjust this example for PWM wide other than 8 bits. And optimize the perfomance if needed.
unsigned char PWM_Period_Counter, PWM_Puls_Counter, PWM_Value; // define PWM_PASSIVE_LEVEL as you need #define PWM_PASSIVE_LEVEL 1 #define PWM_ACTIVE_LEVEL (1-PWM_PASSIVE_LEVEL) // define PWM_Output pin, INTERRUPT_TIMER0 vector & PWM_ISR_RBANK as you need sbit PWM_Output = Pn^m; #define INTERRUPT_TIMER0 1 #define PWM_ISR_RBANK 1 void PWM_Timer_ISR() using PWM_ISR_RBANK interrupt INTERRUPT_TIMER0 { if (--PWM_Period_Counter==0) { // end of PWM period - reload PWM value PWM_Puls_Counter = 256-PWM_Value; PWM_Output = PWM_PASSIVE_LEVEL; } else { if (--PWM_Puls_Counter==0) PWM_Output = PWM_ACTIVE_LEVEL; } } void main() { PWM_Value = 0; // setup and start Timer0 (or TimerX) while (1) { PWM_Value = produce a PWM value... } }
Or (better) use an other uCPU (for example, AT87C51Rx2) with hardware PWM function. ;)
T2 is far more flexible and has "PWM capability"
Erik
erik malund wrote: T2 is far more flexible...
This is correct. One can use Timer2 (or Timer0 ;) ).
erik malund wrote: T2 ... has "PWM capability"
Timer 2 of AT89C52 has "Programmable Clock Out" capability, but it is NOT PWM capability. Programmable Clock Out produce always 50% duty with adjustable clock frequence:
A 50% duty cycle clock can be programmed to come out on P1.0, as shown in Figure 5. This pin, besides being a regular I/O pin, has two alternate functions. It can be programmed to input the external clock for Timer/Counter 2 or to output a 50% duty cycle clock ranging from 61 Hz to 4 MHz at a 16 MHz operating frequency.
Mm... Forum engine is really pure. Data sheet quote in my previous post should be look like:
And a post in "Preview" mode looks not like the same post finally. :-(
P.S. To ghanshyam gajjar. Atmel's document "At89C52 Data Sheet" says:
Not Recommended for New Designs. Use AT89S52
But AT89S52 hasn't PWM implementation too. :-(
is to use a chip with a PCA
"Data sheet quote in my previous post should be look like"
You're using the wrong tags!
The 'pre' tags are just for quoting code - not "normal" text. Try italic instead...
Please learn to use the correct tags.
Otherwise, it makes your posts very difficult for us to read.
Andy Neil wrote: You're using the wrong tags!.. Try italic instead.
Mallard McChin wrote: Please learn to use the correct tags.
Yes, you are right. I do learn it. And I misdo sometimes - so do I learn. ;)
But! 1. It is not possible to correct own post. :-( 2. Ok, there is "Preview". But (see my previous post) "Preview" shows the text otherwise as finally "Post" (try it - you will see ;) ). 3. Yes, it's a good idea to use Italic for quotation, to make an accent etc. And to use Bold to highlight the names. But except Bold, Italic and
source code tag
there is... nothing more! I suggest it looks better if a quotation has an other background color as main text - and I have tried to use < pre > tag...
Ok, one used earlier a typewriter and was happy, :) Shakespeare hasn't even it. :D But there was in those days no forums... ;)
Sorry for offtop. And to be grumble about forum engine.