EmbDev.net

Forum: FPGA, VHDL & Verilog LED intensity change by press


von LED intensity change by press (Guest)


Rate this post
useful
not useful
Hello, I am trying to understand how to change intensity of LED every 
time I press button, starting from 25%, by 25% up to 100% (and when it 
reach 100% drop it down to 25% again). So I was wondering if someone 
could explain it through VHDL code. Thanks.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
LED intensity change by press wrote:
> how to change intensity of LED every time I press button
What hardware platform (ASIC, CPLD, FPGA...)?
What toolchain (Xilinx, Altera, Lattice, Synopsys, Aldec...)?

> So I was wondering if someone could explain it through VHDL code.
First YOU must say how YOU would do that in real hardware (with counters 
and comparators and flipflops...). THEN maybe one is able to describe 
this hardware with the Hardware-Description-Language VHDL.

> Thanks.
Youre welcome. But first YOU must show up with something, then maybe one 
will help you. But you cannot come and say: Do my homework pls!

von Nicholas (Guest)


Rate this post
useful
not useful
I am new at this and I apologize for this.
I am using xilinx to code and E2LP.

I was trying it this way:
Every time the button is pressed  add 1 to variable
00 for 25%
01 for 50%
10 for 75%
11 for 100%
The problem is I don't quite understand something called PWM and how it 
actually works.
I found lots of codes where brightness of LED is fading but don't know 
how to make it "jump" for 25%

Thanks and sorry one more time.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Nicholas wrote:
> The problem is I don't quite understand something called PWM and how it
> actually works.
Thios has no particular relation to VHDL. But you must be able to 
imagine the hardware. Then you can describe it.
In your case the PWM hardware actually it is a clock, a 2 bit counter 
and a 2 bit comparator. Try to connect those two components on a sheet 
of paper until they behave in a way you want it.

> I was trying it this way:
> Every time the button is pressed
And how would you detect this button?
You know about synchronizing to the clock domain and about 
edge-detection?
If not: use those keywords for further reserach.

> add 1 to variable
Forget variables for the first half year of doing vhdl. Use signals 
to solve the problem. And: don't "program VHDL". What you must do ist 
"describe hardware with VHDL". And you cannot describe something you 
don'T have a picture of (didn't I mention this already?).

> I found lots of codes where brightness of LED is fading
This is PWM. If a code can do continuos dimming from 0% to 100% it 
will pass 25%, 50% and 75%. So YOU must find a way to give the PWM not a 
smooth value from 0 to 100% but descrete values for those 4 steps...

> but don't know how to make it "jump" for 25%
Thats YOUR part of the task. It won't help you to "copy some code from 
somewhere to elswhere" and not understanding what this code does.


For sure its easy to solve your excercise in less than 20 lines of code. 
But that would not help you at all. To keep things short: start 
thinking about that pretty little excercise on YOUR own!

If you wait till tomorrow I can post a solution. I'm pretty sure you 
won't understand my way, but it will do what you want and your teacher 
will be kind of impressed...

von Nicholas (Guest)


Rate this post
useful
not useful
Thank you for advice and help.
I am having trouble understanding all of this as I went from computer 
programing to this and my mind is still based on that logic(thats why I 
tried adding into a variable).

I will do my best to understand and try to complite this problem on my 
own.
Surely I look foward to have solution because it would help me 
understand more even if it is complicated.

Teachers encouraged us to explore more on our own and I found this 
problem and it interested me for some reason.
I won't get any point or grades and I won't submit this to a teacher so 
thats why I posted here in hope someone will help.

Thank you for help one more time.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)



Rate this post
useful
not useful
Lothar M. wrote:
> If you wait till tomorrow I can post a solution.
As promised: here it is (it grew up to more than 20 lines for better 
readability... ;-)

Have a very close look at it. Do a simulation (i already added a "test 
bench" to have a look at the signals) and dig around with it a good 
while. At least until you understand all of that little code snippet: 
find the PWM counter, the PWM comparator, the synching stage and the 
edge detection...

wf_dimmer_1 shows one complete cycle from 25% to 100% and back to 25%
wf_dimmer_2 shows how the button is synched in and how it is detected
wf_dimmer_3 shows the prescaling from 50MHz to 1kHz
A good hint to get familiar with the tools: find those waveforms in YOUR 
simulator too.

: Edited by Moderator
von Nicholas (Guest)


Rate this post
useful
not useful
Thank you for help.
It seems that I am on a good way to undestanding all of this but there 
is stil a long way to go.
Thank you for using your time to help me and patience for all my 
misunderstanding.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.