NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Input adc read 0-900 equals pwm output 900-4500.

May 03, 2010
by met_fredrik
met_fredrik's Avatar

Hi! I am using a servo as an adc input. Well actually I am only using the potmeter inside the servo. And I modified the temp sensor project file to read it. And then I am using the adc read to output pwm corresponding to the movement. However the problem occurs when I get a readout which spans from 0-900. And my pwm output for the servo spans 900-4500.

This seems more like a mathematical challenge than a programming issue. But I can't seem to figure it out!

Hope I have made my self understandable:)

Thanks!

May 03, 2010
by met_fredrik
met_fredrik's Avatar

The solution was to add a multiplier. So simple..:P

But now I have encountered a new problem. The input has alot of noise in it. The potmeter from the input servo seems to move just a tiny bit even when standing still. So I need to program something that when a number is flicking between let's say "4701" and "4702"(needless to say this makes my output servo go crazy) it makes the servo stay at one of the numbers. All I am using now is:

last_sample = adc_read();
servo = ((last_sample)*10);

I can't make a delay_ms command because I need the servo to be able to respond quickly from the input.

Thanks!

Post a Reply

Please log in to post a reply.

Did you know that 20 LEDs can be controlled from 11 microcontroller pins, to make a twinkling heart outline? Learn more...