Programming PWM on ADuC812

OP (Company: GC) #2443475
Hi
 I work with a microcontroller ADuC812. wrote a program that produces 
the formation of a linearly increasing output voltage (DAС0), converting 
an input voltage of 0-channel ADC, and transfer the data via the RS-232. 
I do it in the Keil uVision. This is a code(C++):
 # Include <ADuC812.h>
 # Include <stdio.h>
 # Include "ADC.h"
 # Include "DAC.h"
 # Include "max.h"
 # Include "vect.h"

 float in, out;
 unsigned int i;
 void INT_T0 (void) interrupt 1
 {
 out = out + 0.1;

 if (out> = 5) out = 0;
 SetVoltage (out, 0);
 TR1 = 1;

 }
 void INT_T1 (void) interrupt 3
 {
 in = GetVoltage (0);

 printf ("DAC0 =% f", out); /
 printf (": ADC0 =% f \ n", in);
 TR1 = 0;
 TF1 = 0;
 TH1 = 0;
 TL1 = 0;
 }

 void main (void)

 {


 //----------- Set UART ---------------
 SCON = 0x40;
 REN = 1;
   Set timer 2 ------
 RCLK = 1;
 TCLK = 1,
 RCAP2L = 0xDC;
 RCAP2H = 0xFF;
 TR2 = 1
 ES = 0,
 TI = 1; RI = 1;
 EA = 0;
 //------------------------------------------
 EA = 1;
 ET0 = 1;
 ET1 = 1;
 TMOD = 0x00010101;
 TR0 = 1;
 SetVect (1, INT_T0);
 SetVect (3, INT_T1);
 SwitchDAC (0,1);
 InitDAC (0);
 SetVoltage (5,0);
 InitADC ();
 while (1)
 {}
 }

 I need to make a PWM (Pulse-width modulation) generator depending on 
the voltage at the ADC input. Frequency is 1 kHz. I work with 
microcontrollers only for 3 months, so do not have enough experience to 
do without help. Please help me!
 P. S. Sorry for my English. :)

Reply

A question of your own? This thread is over 14 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.