[LPC1114] How to control output voltage ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[LPC1114] How to control output voltage ?

234 Views
lpcware
NXP Employee
NXP Employee
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.
0 Kudos
2 Replies

204 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mondo90 on Mon Sep 29 10:42:44 MST 2014
Sure, thank you ;)
0 Kudos

204 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Sat Sep 27 14:53:11 MST 2014

Quote: Mondo90
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 ?



Since this snippet is part of a PWM sample, there's no ADC in it...

Output [s]voltage[/s] PWM control is done by 'period'...
...
 init_timer32PWM(1, period, MATCH0);
 setMatch_timer32PWM (1, 0, [color=#f00]period/4[/color]);
...
 init_timer16PWM(1, period, MATCH1, 0);
 setMatch_timer16PWM (1, 1, [color=#f00]period/8[/color]);
...}


I would suggest to use actual ADC / PWM samples of your toolchain and learn how they work...

After that it shouldn't be too difficult to combine them   
0 Kudos