EmbDev.net

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


Author: LED intensity change by press (Guest)
Posted on:

Rate this post
0 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.

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 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!

Author: Nicholas (Guest)
Posted on:

Rate this post
0 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.

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 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...

Author: Nicholas (Guest)
Posted on:

Rate this post
0 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.

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:
Attached files:

Rate this post
1 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
Author: Nicholas (Guest)
Posted on:

Rate this post
0 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.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.