EmbDev.net

Forum: µC & Digital Electronics Programming PWM on ADuC812


Author: samik sam (Company: GC) (samik777)
Posted on:

Rate this post
0 useful
not useful
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

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.