samik777
Newbie level 2
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.
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.