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 » How could i use the potentiometer included in the nerdkit to control the frequency of a square wave?

January 05, 2011
by rboggs10
rboggs10's Avatar

I am using the piezo buzzer on the PC4 pin,

January 05, 2011
by rboggs10
rboggs10's Avatar

When I turn the potentiometer I want it to change a variable in the program then use that variable as the delay in "delay_ms()" to change the frequency of the square wave that outputs to the piezo buzzer.

January 05, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi rboggs10,

The question you are asking is very broad, and I'm not sure what exactly you are confused about. There are several aspects to your project, and the best way to go about completing it is to break them down and solve them one by one separately. The two main parts of your project are 1) reading the potentiometer, and 2) actuating the buzzer.

I suggest starting with #1 first. The first step is to figure out exactly how a potentiometer works and then from there hook it up so it actually helps you do what you want to do. Rather than me telling you how to hook it up though. Why don't you give us an idea of what you understand potentiometers do, and from a high level explain how you think one might use them with a microcontroller as an input. I'm sure between all of us we can come up with a good design for your project.

Humberto

January 05, 2011
by Ralphxyz
Ralphxyz's Avatar

I am using a pot in place of the tempsensor and outputting a pulse.

sorry the code is not uploadable using the NerdKit boot loader but can be loaded using a ISP or HVPP programmer but you can see how to use a pot to generate a square pulse.

/* PIN ON (high) for simulation of revolutions //*/
    DDRB |= (1<<PB4);    //Data Direction Output  // LED as output
        {
        PORTB |= (1<<PB4);      // turn on LED
        delay_ms(50);           // ON for 50 milliseconds 
        PORTB &= ~(1<<PB4);     // turn off LED
        delay_ms(last_sample);  // OFF from pot setting (lower pot faster flash)    
        }

//*

This generates a variable pulse (led flash) depending on the position of the pot.

This "should" be a 50ms square pulse with the frequency determined by last_sample.

This is a RPM simulator program which I am using to try to learn how to get RPM

Ralph

January 07, 2011
by rboggs10
rboggs10's Avatar

Thanks Ralph. I am looking into it and will see what I can do.

January 07, 2011
by Ralphxyz
Ralphxyz's Avatar

I am modifying the code to use PWM (just to learn PWM) but either might do what you are asking for.

Ralph

Post a Reply

Please log in to post a reply.

Did you know that the printf format string "%.3f" will show three digits after the decimal point? Learn more...