samik999

Joined Dec 3, 2011
1
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++):

Rich (BB code):
 # Include <ADuC812.h>
# Include <stdio.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);
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.

Last edited by a moderator:

tommydyhr

Joined Feb 3, 2009
39
Is the duty cycle to be directly proportional to the ADC-input? If that's the case, then a simple solution would be to perform some basic arithmetic to the ADC result, so that it can be appended to the PWM SFR.

You could also just capture the ADC-value, and match it to some constants you've defined in your ROM.

In any case, it's a question of priorities. Do you need to conserve space in the ROM, or do you need the program to perform the task as quickly as possible?

Edit: After looking up the specific MCU, it would seem as if it doesn't have a PWM-module at all, and thus has no specific SFR. Now some new questions arise; How great accuracy do you demand? Are you OK with additional external circuitry?

Last edited: