Nicolas, (and Rickman)
On 08-05-16 19:21, Nicolas Matringe wrote:
>> Well, the reason I thought like that, is because that is how the design
>> was done on this particular MCU-based project: two "threads", one that
>> counts the number of rising edges and one that that "processes" this per
>> timeslot. (*)
>> And global data as a way for the two processes to communicate with
>> eachother.
> The problem you have here is not "thinking hardware". You have to keep
> in mind that VHDL is a language that describes actual logic gates, not a
> programming language.
Well, the reason I am interested in FPGAs is to -from what I read about
it- it seams to requite a completely different way of thinking then I am
used when writing code.
And that is now my main problem.
If you look on the net, there is quite some information on FPGAs, on
VHDL and building your first "blinky", etc. So actually getting started
is not that difficult.
The next step, learning to get your brain into the correct "twist" and
learn to think hardware, will probably require doing a large number of
exercises. But this is a lot more difficult to find.
I was actually a bit surprised to see there are no courses on FPGA, VHDL
or verilog on any of the major MOOC flatforms (edx, coursera, ...) as I
hoped thse would have been the places to find the exercises I need.
> A process describes a single piece of logic, with its inputs, outputs
> and internal signals. Having several processes modify a single signal is
> *exactly* connecting the outputs of different pieces together. As a
> basic rule of electronics, you just Don't Do That (it has exceptions, of
> course)
I know, and that I also told myself beforehand ... but you know, my
experience gave me a different feeling.
The first exercise I did for myself was PWM, based on the logic of how
an arduino does PWM: a counter that goes up in loops, a PWM output pin
that goes to "1" on counter=0 and "0" on couter=pwm-value.
So the logic I had was this:
--- cut here --- cut here --- cut here --- cut here ---
(...)
signal led_t : std_logic := '0';
signal pwm_r : std_logic_vector(18 downto 0) := "1000000000000000000";
(...)
process(clk_in,cnt_r,pwm_r) is
begin
if falling_edge(clk_in) then
if cnt_r = pwm_r then
led_t <= '0';
elsif cnt_r = 0 then
led_t <= '1';
end if;
end if;
end process;
led <= led_t;
--- cut here --- cut here --- cut here --- cut here ---
In fact, this seams to work, which was ... great.
Actually, my first thought was, ... well, this is not that much unlike
coding afterall.
Apparently, the language is intelligent enough to see that "led_t" is
changed under certain conditions, but there are also moments when it is
not changed; ... so by itself it seams to create a "memory-cell" for
that output pin. Nice! :-)
However, I think this particular example kind-of gave me the wrong
impression. :-(
>> Just wondering.
>> On the SPI interface of the STM32F1, there is a "TXNE" bit (part of the
>> "SR" register) which is set by the SPI hardware when data has been
>> received by the SPI interface.
>> And ... by just reading the received data from the SPI DR register, this
>> actually automatically resets that bit.
>> I wonder how you would describe this in VHDL.
>
> Well the CPU bus must have a "read" signal somewhere so when the correct
> address is presented and the read signal is active, the bit is cleared.
Well, I have been thinking about this.
My "problem" is to image how a "read" action (which is for the actual
piece of hardware containing the data quite a "passive" thing) can
trigger a action (in this case, erase the RXNE bit).
But I guess "reading data from a register" this is not really the just
"reading data". It's probably a "write" action: copy the data from the
register to the internal bus of the processor and -once that is done-
clear it.
(althou, isn't this a "sequencial" action ???)
>> Setting that bit is clearly done by one process (the process that drives
>> the SPI interface), ... but reading that data (and the result of
>> clearing that bit) is probaby done by code outside the SPI block.
>>
>> Don't you have the same senario as I had: two processes trying to change
>> one piece of data (in this case, the TXNE bit).
>>
>> Or am I seeing things to complicated here?
>
> I think you're confused by the term "process"
> Your TXNE bit can be written as a set/reset flip flop in a single process:
>
> process (clk, rst)
> begin
> if rst = '1' then
> txne <= '0';
> elsif rising_edge(clk) then
> if set = '1' then
> txne <= '1';
> elsif reset = '1' then
> txne <= '0';
> end if;
> end if;
> end process;
> I didn't think much about what should happen if both set and reset are
> active at the same time. Here, set has precedence.
OK, my mind-problem is this:
Perhaps it is my "IT" mind, but I tend to look at information as "data".
In this case, there is a piece of information (the "clock counter") and
two actions ("increase the value by one" and "reset the value to zero").
Around this piece of information, there is a box to execute these
actions, which can be implemented in software or in hardware.
The main difference, as I see it, is that software and hardware work
with two different mechanisms:
- software is based on a "single-shot" event. Something or someone sends
a command to the black box managing the information (i.e. the command
"reset the counter to 0"), that command is executed and that is it.
- in contrast, hardware is based on a "state" (e.g. the nRST-line is set
low -> the value of the register is set to zero). This state remains
valid as long as the nRST is low. (so to make the counter "active"
again, the nRST line must to reset to 1).
(this is also how you implemented this in your VHDL example, no?)
So, if I am not wrong, I want to reset the counter to zero, I first need
to set the nRST line to 0, and then set it back to 1 again; ... which is
works ... except that this is a is a "sequencial" action.
And I just though that the whole idea of VHDL was that everything runs
in parallel, not in serie.
Or not?
> Nicolas
Cheerio! Kr. Bonne.