lpcware

[LPC1114] How to control output voltage ?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Mondo90 on Fri Sep 26 15:02:28 MST 2014
Hello,

I am looking for a way to control LED brightness by input voltage value. I want to read value from ADC (photoresistor) and then base on this value dimmer or brighten the led.

So far I found pwm example code, but this is completely unclear for me, where is code responsible for setting INPUT ADC , and where is code responsible for output voltage control ?

int main (void) {
/* Initialize 32-bits timer 0 */
init_timer32(0, TIME_INTERVAL);
enable_timer32(0);

/* Initialize the PWM in timer32_1 enabling match0 output */
init_timer32PWM(1, period, MATCH0);
setMatch_timer32PWM (1, 0, period/4);
enable_timer32(1);

/* Initialize the PWM in timer16_1 enabling match1 output */
init_timer16PWM(1, period, MATCH1, 0);
setMatch_timer16PWM (1, 1, period/8);
enable_timer16(1);

/* Enable AHB clock to the GPIO domain. */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

/* Set port 2_0 to output */
GPIOSetDir( 2, 0, 1 );

while (1)                                /* Loop forever */
{
/* I/O configuration and LED setting pending. */
if ( (timer32_0_counter > 0) && (timer32_0_counter <= 50) )
{
GPIOSetValue( 2, 0, 0 );
}
if ( (timer32_0_counter > 50) && (timer32_0_counter <= 100) )
{
GPIOSetValue( 2, 0, 1 );
}
else
while ( timer32_0_counter < 100 ); //wait for
  timer32_0_counter = 0;
}
}


I am completely lost with this task, any help will be appreciated.

Outcomes