Go Down

Topic: Led dimming without using analogwrite() (Read 759 times) previous topic - next topic

tanvi256

Jul 05, 2020, 08:52 am Last Edit: Jul 06, 2020, 09:54 am by tanvi256
Hello everybody!
i was given a task by my teacher.
I have to control the brightness of LED on pin 13 of Arduino Uno Board , i.e dimming&brightening it in a continuous fashion.
But i cannot use the analogWrite()/timer library
I have to do it using timers.
Can anybody give me a headstart as to how can i go about it or any sort of references/links/codes?
Thankyou :)

TheMemberFormerlyKnownAsAWOL

#1
Jul 05, 2020, 09:21 am Last Edit: Jul 05, 2020, 09:22 am by TheMemberFormerlyKnownAsAWOL
Have a look at the blink without delay example in the IDE, and speed it up a bit, and make the duty cycle variable.

And please don't SHOUT
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

Paul__B

OK, now come on!  This is not your first query and the second time you are seeking assistance with an assignment.  :smiley-eek:

You now know how the forum works.  Please go and select "More"->"Modify" to the bottom right of your first post above and correct the subject title.  :smiley-roll-sweat:   Hint: AWOL has done it for you, you can cut and paste it easily (if you do it in the right order).  :smiley-lol:

But the next thing I - we - want you to do, is to report in detail how your assessment went with the previous assignment.

Having done that, explain what you mean by "I have to do it using timers."  What functions are you or are you not permitted to use?  AWOL has given you the basis but it require the use of millis() (and no other).

tanvi256

Hey! I already posted my final working code on my previous query.It went very well & was approved by my teacher as well!
Regarding this one, I cannot use the analogWrite() function.
i have generate a pwm using timers and via that  dim&brighten the led in a continuous fashion.Im supposed to use timer registers. i dont want it to blink, Its brightness is supposed to vary from Lowest to highest to again lowest continuously.
I hope i was able to frame my question & post the details in a proper manner! :)



TheMemberFormerlyKnownAsAWOL

#4
Jul 06, 2020, 10:32 am Last Edit: Jul 06, 2020, 12:00 pm by TheMemberFormerlyKnownAsAWOL
Quote
I cannot use the analogWrite() function.
...because pin 13 isn't a PWM pin.
You don't even need to mess with the timer registers.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

tanvi256

No no, im aware of that. Its a task assigned to me that i have to do it using timer registers only .

TheMemberFormerlyKnownAsAWOL

i have to do it using timer registers only .
That is simply not possible.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

Paul__B

Well, that is what I was asking.  Do you specifically have to mess around with the timer registers, or just use the millis() function?

Using millis(), you can easily execute a PWM in 20 steps with a 20 ms or 50 Hz cycle.  Even without millis(), you can use loops to execute PWM with even more steps.

Smajdalf

Set registers to get interrupt in given intervals (or wait for some TCNT value in loop) a toggle the LED on pin 13 when this happens. Such as

Code: [Select]

setup(){
configureTimer();
}

loop() {
if (TCNT>someValue) turnLEDOn();
else turnLEDOff();
if (something) update_someValue();
}

Go Up