Programming Throwdown - FPGAs
Episode Date: November 20, 2013This show covers Field Programmable Gate Array (FPGA) programming. Tools of the show: Jason: Kaggle http://www.kaggle.com/ Patrick: KiCad http://www.kicad-pcb.org/ . Books of the show: Jason:... Mahout in Action http://amzn.to/1eizgRS Patrick: Bebop to the Boolean Boogie http://amzn.to/1cGRdaD ★ Support this podcast on Patreon ★
Transcript
Discussion (0)
Hosting provided by Host Tornado.
They offer website hosting packages, dedicated servers, and VPS solutions.
HostT.net.
Programming Throwdown, Episode 30, FPGAs.
Take it away, Jason.
Hey, so, you know, I'm a big fan of board games as is
Patrick and been playing a lot of board games lately on the phone you mean like
like monopoly actually do they have an op oh no you know what I looked into
monopoly on the phone but it it got terrible reviews like a bunch people are
like the app crashes there's like micro transactions in monopoly which that sounds horrible yeah no i was joking i was joking
most people think board games monopoly not good i don't like board games yeah that's right that is
sort of the flow it's like let me think board games equals monopoly equals me sitting around
for three hours while the two people left you know finish the game equals equals
not fun but uh yeah so i've been playing uh ticket to ride it's been pretty awesome uh patrick's been
playing carcassonne or carcassonne depending on i won't try to pronounce it i play several board
games on my phone uh i like this card game dominion oh yeah dominion's great i didn't know
they can play it really fast.
I don't know.
I have an iPhone, so I can play it on my iPhone.
Oh, I see.
Is Dominion, is it free?
Yeah.
Well, I have a version I downloaded a long time ago that was free.
Supposedly, the guy was going to stop doing it when they actually released a real Dominion.
But I don't know if that's ever happened.
That they've released a free one or that he... So they were they were gonna make an official the people who would officially license dominion oh i see i see
but they haven't done that yet yeah i don't i don't know if they did gotcha gotcha yeah they um
uh they're really fun i mean it's uh the bad thing about ticket to ride is uh so you can either do
pass and play which i've been doing my wife
or like you know you use a tablet and you know i put some trains down i pass it over to her right
um the online play it forces you to play with strangers which i think is is a terrible design
decision i mean i think the problem is you know you think about it right who makes a board game
somebody who is like pretty into like math techie like like like
game theory kind of stuff whatever those people you know would never want to play with friends
they'd always want to play like ranked like that's what they have is like this ranked game system
where i'm being matched up with somebody from from a pool of three people probably want to play
tickets to ride i'm being matched up with...
You should mention this is only on Android.
On iOS, you can actually play with your friends.
Really?
Yes.
Oh, man.
Yeah, so specifically the Android is literally a copy of the web version.
So, yeah, they're using like...
You know how Adobe has this thing thing called flex i think it's
called flex or air or something like that air yeah air yeah where you write code and it works on the
web and on the phone so so these guys are using that i believe um and uh and yeah so so on the
web as well you can't pick people to play again so for all the people who are extremely confused
about jason talking about putting trains down on a board because you don't know what this ticket to ride game is
yeah it's a board game that they made an iphone or now an android version of and they also have
an iphone ipad version ios version and a web version apparently which has been out for a while
so how do you like playing so you do you have the board game the actual board game
no so so i used to um play board
games with a group of guys uh back when i lived on the east coast and uh we all kind of split the
cost by buying different board games each and so i did not have the ticket to ride game and i still
oh okay okay but you have played the physical version oh yeah a bunch of times have you uh do
you have that ticket to ride i do i do i have uh i have the ticket to ride i was amazed how mainstream ticket to ride is like it's in
walmart and target now yeah that's right that's right so how do you feel like the differences
between playing it on a tablet phone versus actually moving the pieces and sitting around a
table yeah so so for all of these board games it is way better on the phone on electronic version i'm just
i'm just so much i mean it's almost to the point where uh uh you know if they made tablets just a
little bit bigger i would just play it on the tablet like even with a group of four people
rather than really yeah so i find it depends on the game yeah so like but like ticket to ride
isn't that much upkeep
in rules and math that you have to get right.
So I actually prefer playing it in person, I think.
And people have more fun and conversations.
When you play on your phone,
even if with people in the same room,
everybody's really focused and trying to do their thing.
And so it gets kind of quiet.
People don't tend to converse as much.
But then other games that I've played that require,
like Dominion, I was saying,
there's a lot of shuffling you have to do and stuff.
So it's actually really nice on the phone
because they just do all that for you,
so you can just play very quickly.
So you can get a game in against a computer
or a random person or a friend in like five minutes
versus 20 minutes or 30 minutes.
Yeah, definitely.
I mean, of course, the elephant in the room here, right,
is being able to create the desktop experience using these devices, right?
Like, if each person at the table has a phone, a smartphone,
and there's a tablet or maybe even two tablets in the center of the table,
there's no reason why you couldn't, you know,
recreate the same exact experience just you know electronically like in the sense that like the phones would just have
the cards that you'd be but that's like the world's most expensive board game oh yeah yeah
you have to assume that people already have all of this stuff otherwise yeah it breaks down
but but the thing is your point is valid that like the uh it's true when we do the pass and
play we're not talking quite as much, when we do the pass and play,
we're not talking quite as much as when we're playing the board game.
But I think that's more just a fact of you just have to kind of keep passing it back and forth.
It's not really like a board game where it's just kind of always there.
It always feels like one person has to be paying attention
versus a board game everyone can step away, right?
Oh, yeah. i don't know but they have pros and cons i don't think they replace each other but i like to have them both yeah it makes sense i mean for uh more complex games like uh always like
agricola you know with all those pieces and the putting the fences and the pigs and dealing with
all that it's like that would be so much easier and then computing the score at the end always took like 20 minutes you know
that's true so what you need is an app where you just take a picture of the configuration of the
board at the end and then it scores it for you yeah yeah definitely or like if you're really bad
at chess you have like a chess app that you like take a picture of the chess board and it recommends
the next move for you that'd be awesome so when you're when the guy you're playing you know sneezes you just like
whip it out real quick take a picture and have you seen this where uh anyone can beat a grandmaster
in chess just by having like two grandmasters in a room and the person playing the you know
opposite grandmasters move anyways you know what i mean like like you have two grandmasters
you're playing both of them the first the one on the right makes a move and you make the same move
to the one on the left like eventually oh so you'll win one of the two games against a grandmaster
yeah exactly yeah okay yes so uh yeah okay a pretty cool thing is uh just we'll get off the
subject is vassal um it's kind of
clunky i wouldn't recommend it unless you got a little bit of techie skills um wait they're
listening to our podcast yeah well i guess what i'm saying is don't recommend this to you know
your friends who don't know anything about programming or anything like that um you know
because most people would want to play this with other people and And so if you want to play this with other people,
you'll probably have to go to their house and set this up,
which is kind of unfortunate.
But it's pretty cool.
It lets you play over the Internet.
And basically what they've done is they have a bunch of board games,
like probably 100-something board games,
and they literally have just taken pictures of all the cards
and the board and all and the board
and all the pieces and they don't have any of the game logic in vassal but they just have the the
resources so in other words um if you're playing monopoly like on vassal you can just put a house
anywhere on the board it's as if you're really playing a board i mean there's nothing stopping
you from physically putting a house somewhere even if it doesn't make any sense right so it's
very open-ended and it supports many different games and you have to kind of enforce the rules
yourself but uh it does let you play a ton of board games online which is i think it's pretty
nice nice all right i'm gonna have to check that out i haven't tried that before yeah totally all
right so on to the news our first news topic seems to have been very controversial online,
and that is this new product called Coin, which is at onlycoin.com,
where Coin is a revolutionary new credit card device, or just card device, I guess.
And the idea is that it is a small electronic thing that is the same exact
size as a normal credit card, rewards card, driver's license,
this kind of thing.
And on your phone,
you take a picture of the front and back of the card and then you run it
through a little card reader that they send to you.
Similar if you've ever seen like the square device is what I imagine it
being.
Cause it's not out
yet you swipe it then it kind of knows what's on the magnetic stripe and it has pictures of the
front and back then you can sync from your phone via bluetooth to this device and have up to i
think it says eight cards where at the push of a button on the front there's a little screen
embedded and when you push button you can cycle through your cards and then if you want to use your debit card you select the debit card and
swipe uh you know if you want to use your credit card you punch this button again and you know it's
your credit card you can swipe so how does this what's the connection between this and the phone
so the idea is that the phone is needed because if somebody wants to see that you actually own the card, I guess, and also that like, you know, prove you have the card, then you want to have that on the phone.
Also, the phone is what's used to transmit the details of what the card like how to be that card.
Oh, right, right, right.
I see what you're right so like um on the magnet i don't know that much about it but like the magnetic swipe of these cards like the strip on the back that the dark color typically
has magnetic particles that are i don't think they're encoded or encrypted very well i mean
encoded somehow but they're not encrypted very strongly and basically when you swipe it some
pattern comes off that is like the card number what the card is and your name and your
billing address or something like just a few items or something as well right the what the cvv those
three no oh yeah yeah or maybe in like the expiration date but like just a string and so
if you have a mag reader like square or something else you can basically just get clear text
basically what's on the front of the card by just swiping right so this device presumably will reprogram the magnetic stripe to whatever you've selected
when you push the button and then when you swipe it through the reader will just think that card
was swiped through that's awesome so um is there anything about how much it'll cost or anything
so i oh i I forgot now.
Oh, actually, I'm on the website now.
You can preorder.
If you preorder, it's $55.
If you know, once it is launched, that it's $105.
Okay.
Yeah.
So there's it seems really interesting.
But people have like a lot of concerns, I guess, legitimate or not.
But that has like it seems pretty legitimate. Like it doesn't seem like a, of concerns i guess legitimate or not but uh that has like it seems
pretty legitimate like it doesn't seem like a you know obvious scam it's backed by some
pretty big companies and vc firms um and they weird thing is though is that they require you
to prepay your pre-order so this is slightly similar to kickstarter but like if kickstarter
doesn't succeed you don't pay
but if it does then you pay and eventually get your item but normally when you pre-order something
you pay when it ships but here they're collecting it up front so you pay now so they can do all
their manufacturing and it doesn't as far as i can tell like i mean they have prototypes but it
doesn't exist yet right right so as with anything there's a risk and there's also a risk that
you know like if you
go to a restaurant and the person takes your card like they could in theory switch to a different
card on purpose or by accident um yeah but that doesn't help them in here does it i mean no but
like uh people have these and also like accepting it right like i don't know what this is this isn't
visa or mastercard like oh Like, where do I?
So there's just like, it'll be, at least initially,
there'll be a lot of uncertainty from people.
But it would be nice to get rid of all the extra cards, right?
Like, and just carry one card.
You know, you're absolutely right.
Like, think about this.
You know, your debit card, as everyone knows,
is much less secure than a credit card.
It's actually very hard
to reverse a transaction on your debit card whereas it's it's almost trivial on a credit card
um so somebody could say at a restaurant you know artificially add to your bill uh like somehow scam
you that way and then switch it to your debit card and uh you know what i mean like like
and then it would be harder to get your money back yeah so i mean that's one concern they have
some nifty safety features like if the card gets too far away from your phone it could auto disable
or send an alert to your phone so that you like okay like that's a cool feature i guess that's
true if they have the phone the phone can always like they could always have a button that says you know lock my card so yeah that's what i was thinking like a valet mode or
whatever like yeah so like they could disable it from changing or yeah you disable it completely
or just disable yeah there's like you said disable it from changing but like like one of the things
so there's been other startups that are attempting to do similar style things um and some of them
it's by essentially you swipe one card
and then they hold some pool of money
and then you can select on kind of like the backend
what card you want it to go to,
which is a very different thing and has other problems.
But one of the nice things about that is that
that website can then track all of your purchases
across all of your cards.
Versus like this coin thing,
you can't track your purchases because
it knows it got swiped but it doesn't for instance know how much money was charged because they're
not a part of the actual transaction yeah that makes sense so we'll see it's definitely interesting
uh i i like to see people innovating in this area because it's the current credit card stuff isn't
that great so yeah right definitely yeah i mean you
think about it if they get this right you almost don't need a wallet anymore i mean if you get it
down to only needing two cards maybe there's like a better you know carrying you know utensil for
that right i mean the wallet in general but where am i going to put the pictures
of my kids on your phone okay yeah okay that works the the next uh news article dart turns 1.0
so we talked about dart i believe we did a whole show on dart pretty sure yes yeah and uh you know
we're both big fans i'm a very very big fan. I think Dart is amazing.
I have had to write a lot of JavaScript.
And I found recently there's some good tools that make JavaScript a little easier in terms of, you know, there's a tool called Typecast, which is pretty nice.
I think we might have talked about it. But Dart kind of gives you a lot of these things,
and it gives you a really nice set of batteries, as we always say.
There's a plenty of batteries included in Dart,
such as hash maps and lists and all these great things,
even tree sets, ordered maps, etc.
So it turns 1.0, which is pretty awesome.
This article that we've linked to talks a lot about the different features of Dart. The common criticism of Dart is that it just doesn't have that widespread adoption.
I mean, it has this critical mass problem, right, where you have just so much infrastructure built in JavaScript. And even though Dart 1.0 makes it much easier to access JavaScript code from Dart,
you just, it still is just, you know, it's incredible, there's an incredible amount of
inertia to move people off of JavaScript. I mean, it doesn't matter what the alternative would be.
I mean, if you look at popular alternatives to JavaScript, they are almost always just small enhancements to JavaScript, like TypeScript, which compiles to JavaScript, CoffeeScript, which compiles to JavaScript, so on and so forth.
So this is, you know, this is pretty difficult.
But, you know, I believe strongly this is just a really great language.
And, you know, we'll hopefully see it continue to get adoption.
Are there any other browsers besides Chrome that can run dart natively yet um i don't think so and in fact uh you can't
run dart natively in chrome either so um yeah there's a special version of chrome that you can
download which does let you run Dart natively but for one reason
or another it's still not part of
part of the regular Chrome
okay
yeah so there's actually no browser
which lets you do that but
looking right now to see
if I don't think
that you know Firefox or any of the
so it says that yeah so currently
when you part of the so it says that yeah so currently when you uh part of the
dart software development kit is a version of chrome chromium that dartium yeah oh a version
of chromium i see oh yeah right this red right no worries but but yeah the uh uh you know i i don't
really know why uh i mean i could only guess guess that maybe they're having trouble with mobile or something.
I have no idea.
To finish that thought, you can convert your Dart code to JavaScript
using this thing called Dart to JS.
Then it will run in any modern browser.
Nice.
Yeah, very cool so the next article we have is a successful ability of a qubit to last
for 39 minutes so is that the guy here i hear i hear around the applause is that the guy who jumps
from block to block changing the colors and and swears when he gets hit. Wait, that's Qbert, isn't it? Oh, you're absolutely right.
Yeah, close, but not quite.
So a qubit is the name for a quantum bit,
and I'm probably going to butcher this
because I've always wanted to learn more
about quantum computing and computers
and have never successfully managed
to make heads or tails of it.
So if you have a normal bit, it can be zero or one.
But in quantum physics and in quantum events,
you can have things that are not just unknown,
like you don't know if there's zero and one,
but actually exist in both zero and one with some probability.
Right.
And so if you have that, it's called a superposition.
So it's unknown.
And it's really easy for something to interact with this particle
or this qubit that is in this superposition to interact with it.
And once something interacts with it,
essentially you've made a measurement of what the state actually is
and the superposition collapses.
And now you have an actual either zero or one yeah so let me let me maybe like are you gonna do better here we go no no i'll just come up with it so a lot of people don't understand quantum
mechanics and someone explained it to me in a way that's kind of morbid but actually made a lot of
sense to me is uh like let's say you completely cut off ties to, say, your grandmother, for example, right?
Assuming your grandmother is alive.
Then, as soon as you do that, your grandmother is, like, 99.99% alive,
but, like, some small, like, epsilon, you know, like, 0.0001% dead.
Like, she's in the superposition state where she's part dead
because you don't know if she's alive or dead now if you never speak to your grandmother for
let's say 80 years and let's say assume you're young enough where you can live 80 years and
still be around then your grandmother you don't know that she's dead but she's in a new superposition
state where she's you know 99.999 percent dead and you
know some small percent alive right because most people don't live to whatever she would be let's
say 180 right so extremely rare so once you go and visit her or her grave or what have you
then you know immediately and then as patrick said the superposition state collapses and now it's
it's either zero or one and so but what the important thing here is that they're sort of
like this gradient right so it's like it went from 99 you know uh false zero percent true and
then over time it like slowly shifted to to the opposite and so this is what sort of quantum programming is all about
is sort of taking advantage of the stochastic nature of various problems to create these
superposition states and then hopefully the end goal is to sort of observe these superposition
states you know multiple times and then aggregate those results into an answer.
So there's a lot of connections between ideas of confidence and probabilities and these kind of things in the quantum world.
So there's this idea of an actual quantum computer, which is like a current computer we have now,
but does all the operations possible in parallel or something like this, right? And you do things really really fast and that's kind of like a general purpose computer but they
have now things that are claiming to do quantum computing which is more like along like what
jason's saying which is like if you take the traveling salesman problem and you represent
the initial you know state of the world then Then you perform in a quantum fashion some set of operations.
And then you get to the end.
And you have a whole bunch of possible outcomes.
But some of them will be optimal.
And you want to observe which ones those were by having tried a whole bunch in parallel.
And that relies on needing this probability distribution at the end.
But if things lost their
superposition along the way like something bad happened in the device and a accidental measurement
was taken by another particle colliding with the qubit then the operations at the end don't work
out right exactly and so you can know that something happened wrong and you won't but you
don't know what the right answer would be you just know that something bad happened and um so the important thing about having a qubit which
lasted 39 minutes is that like at room temperature is the other thing because typically you keep it
really really cold because things move slower and so then i i'm probably butchering this but like
no no the way i understand it is like at really cold things
move slower right so it's easier to keep things from colliding with the particle but at room
temperature you know things are zipping around right and so it's much more likely that a particle
will collide with the qubit or something will happen that will cause the position to collapse
right exactly I mean so so just to to complete the thought like if something collides with a qubit
that means you know where that qubit is that means it's not in a superposition state so yeah you've taken some
measurement of it right whether you meant to or not exactly because you could then observe that
particle and yeah it's sort of like you know if you ever watch like the world series of poker
any of these like any of these like poker you know shows on television and you see sort of
the person's chance of winning right and then as soon as they draw a card all of a sudden like it
it's it's like it goes from you know 30 70 it's like 99 zero or something right so it's that kind
of thing where um if you know as soon as you see that card all all of the dynamics change. And so if you have a card on table and you don't flip it over,
now you're exposed to a wide variety of outcomes.
These things are all really fascinating and really interesting to me.
I wish I had more time to understand it better and explain it better.
But yeah, if you're interested, you should go read more about it.
Yeah, definitely.
Yeah, maybe we should look into this and next book of the show should be Quantum.
We should put the onus on ourselves to find some.
Or you should go watch every YouTube video about this,
and then we can have an actual show,
and you can just tell us about it.
Yeah, yeah, exactly.
Okay.
Okay, so last story of the show, Hacking Candy Crush.
I thought this was totally awesome.
Actually, the title is technically winning at Candy Crush, but it's pretty great. Basically, this guy who... So what is Candy Crush. I thought this was totally awesome. Actually, the title is technically winning at Candy Crush, but
it's pretty great. Basically, this guy
So what is Candy Crush?
Oh yeah, so Candy Crush is
an online game that is built
in Flash, but it uses
JSON
XML
HTTP requests to send
data to a server.
So, for example, you play this game in Flash, you beat a level,
and then it actually packages some information on how that level had progressed and terminated,
sends that as a JSON string to the server.
The server then sort of decides whether to give you a new level
or to have you repeat the current level, etc sends that back to you and then etc and more things happen
so you know the server actually will send you the content of the levels one
at a time so you don't actually have the complete game but yet this person was
able to pretend like he beat a level by sending the right JSON to the server, getting the new level content, and then repeating.
And it's pretty awesome.
Actually, the person's profile picture is just him, like, with his goofy grin.
And he just seems like the perfect person to do something like this.
And even if you read further down, the content is great.
And the comments, he replies to almost all the comments
and it is pretty hilarious actually the whole thread i thought was really amusing so if you
want to see how to how to hack online games this is pretty it's pretty epic or how not to design
your online game oh yeah that's true yeah um there's this cool thing called encryption
i mean but uh but And not trusting clients.
Yeah, exactly.
Because somebody could write a malicious client.
That's actually an extremely good point.
I mean, for people who are designing any kind of server
side apps, you have to expect your client to do.
One thing is if you encrypt the string,
then usually the decryption algorithm
will will just bomb out right um but uh but if you're not doing anything like that yeah you at
least want to make sure that the person's doing something sane there was actually a fascinating
article i'll see if i can find it um you know for another episode we're all about sort of the
arms race between uh chinese hackers who were hacking World of Warcraft so that they could get loot
and sell it for real money,
and the World of Warcraft security team.
And really interesting.
Basically, they had a rule-based system
where if any of the rules fired,
they had a human evaluate the activity and then ban the account
um then so one of the rules for example was if you uh if you moved more than say you know
a thousand strides in less than a second or something like that right then they they fired
some rule saying this person's doing something which isn't physically possible in the game right um and these guys got around the rule by they started reverse engineering
the rules by after getting so many accounts banned and they'd move 999 units and then wait a second
and they wrote had scripts which did that and so i know the whole thing was really interesting i'll
see if i can pull it up so this is actually really common this is a whole thing i was reading something similar about when you can like take your you
know xbox 360 controller and modify the electrical contacts where the button presses happen to have
rapid fire right so everybody's probably seen these like on old consoles you could buy rapid
fire game pads yeah instead of when you push the button it just making one electrical connection
it would sit there and make it break it make it break it make it break it and give you rapid fire but that you could use
that to cheat in some games and so they actually like tried to detect on the server side for online
play for local play they don't really care but for like online play and you know people gaming
the system to get better rankings they tried to do things like detect the distance between key presses,
the time between key presses.
There we go.
And so if you're pressing too regularly and fast,
then they know you must be cheating, right?
And so then they can ban you.
So then the people who did these illegal mods to the controllers
had to embed little microcontrollers, which would vary the timing
so that it looked
human enough and be just fast enough that it was helpful but not too fast that you would get caught
gotcha that's so yeah some gaussian noise or something to the to the clicks so that they
weren't all but it's crazy that people would spend time doing this right like making microcontrollers
and then selling them and i i wonder if it's profitable. I have no idea.
Yeah, who knows?
I mean, I remember at one point I had a mouse where you could hit the button.
There's a button you get on the mouse
that would make the scroll wheel have no friction.
And you could just spin indefinitely
and it would just keep spinning.
So I used this button and then I bound the mouse wheel
to like firing a pistol in Counter-Strike.
And that was pretty fun.
But I mean, that was a long time ago.
I bet you get banned for that now.
All right.
So enough about hacking video games.
So now we're doing the book of the show.
My book of the show is mahout in action which is uh you know there's many of
these in action series uh of books um mahout we i believe we talked about it in the machine learning
one of the machine learning podcasts but mahout is a uh machine learning suite of algorithms
some of them run on Hadoop,
which is, as we talked about, like a MapReduce framework.
Some of them actually just are meant to run on a single machine.
So if you just have, you know, a machine sitting around or, you know, you want to do some coding,
you can actually use the algorithms in Mahoot
without having to set up, you know, a bunch of nodes,
a bunch of clusters, a bunch of clusters
or anything kind of complicated.
So I've recently using this a lot.
It's pretty awesome.
It has a bit of a learning curve.
Mahout does, which is why this book is so great.
It actually walks you through how to use many of the algorithms in Mahout.
And I feel like it's a pretty good read.
I'm not all the way through yet
but i'm pretty happy with what i've read so wait so you're recommending a book and you don't know
the ending yeah i have a feeling it ends with uh in the appendix that's oh spoiler what if it's a
cliffhanger check out our book two actually i found I found out. There's a microtransaction at the end of the book.
You can't read the last chapter until you pay $5 more.
You know, they actually have that.
It's kind of sad.
But my wife was reading a free book from the Play Store.
And sure enough, a few chapters in, it was like, oh, why don't you do an in-app or, you know, in-book transaction to get the rest of the book? I was like, that sucks. Oh, that's, oh, that's pretty devastating.
I mean, they should at least tell you. Maybe they did. Yeah, yeah. If they're upfront about it,
it's like, oh, you know, this book isn't free, but we give you the first three chapters for free.
Yeah, they might have said that, but it's, you know, in that small text that nobody ever reads.
Oh, okay. Or at least, at least your wife doesn't read. Yeah, exactly might have said that, but it's, you know, in that small text that nobody ever reads. Oh, okay.
Or at least your wife doesn't read.
Yeah, exactly.
Yeah.
Oh, all right.
So my book is Bebop to the Boolean Boogie.
That sounds awesome.
And if you could say that five times fast, I will give you a thumbs up.
So this is in theme with our episode topic topic and it was a book i read actually many
years ago i think i might have found at the library i'm not sure where i found it at and
it was when i before i had taken up much programming and it describes just like it's
saying well it doesn't actually say but boolean boogie is talking about a lot about boolean logic
and specifically about boolean logic in reference to how it would be used in circuits.
Oh, wait.
So this isn't like a fiction sci-fi book or something?
No.
Oh, okay.
Sorry.
I have a legitimate, actual, useful book this time.
No, no.
It's not a dig on you.
I saw the title, and I just thought, for sure, this was a sci-fi book. So why it attracted to me when I guess I was in probably middle school or early high school was that, yeah, so it's a really fun approach.
So similar to the recommendation of the Design Patterns book, Head First Design Patterns, it takes a somewhat lighthearted approach to design patterns.
But it is a serious learning.
It's just like you do learn the design patterns that they go over.
This is very similar.
It takes a lighthearted approach. Yeah, it uh really good reviews on uh on amazon a couple
other websites so yeah okay awesome i'll definitely yeah it actually got a perfect five stars with
with uh on amazon so yeah that's pretty awesome so i haven't i i'm vaguely remembering it from
a long time ago and there's this cover isn't the cover that I remember seeing.
So I'm sure there's a new edition now or something.
Um,
but yeah,
so it goes over like if you're new to programming,
especially it could be helpful or if you're interested in,
um,
so a lot of people talk about like circuits and electronics and electrical
engineering.
Um,
and so there's analog stuff and digital stuff and to do any,
you know,
digital stuff, you are going to get into kind of Boolean logic and learning about that kind digital stuff. And to do any digital stuff,
you are going to get into kind of Boolean logic
and learning about that kind of stuff.
And we'll go over that.
Like what is an AND gate and how does it function?
What is an OR gate?
How does it function?
What about exclusive OR?
How do you count in binary?
How do you do binary math at like a gate level?
How do you do like,
how do you call them cardinal maps or whatever like
optimizing if you what's called a truth table so like you have inputs that are either zero or one
and you have many of them and here's the output you want for each set of inputs how would you
devise a set of gates to do that um and so this will come into play we'll talk about this maybe
more in a little bit level and a little bit later uh and in the episode but uh this book goes over that and it does it in a light-hearted and fun way
that uh i remember being fond of when i was younger not that you have to be young to read
it i'm sure it's equally fun now and i should bring it back out and uh read it again but
that's my recommendation cool cool yeah it awesome. I'll give it a go. All right. Tool of the show.
Tool of the show.
So my tool of the show is actually a website.
It's Kaggle, K-A-G-G-L-E.
And it's pretty amazing.
So basically, so Kaggle is a data science competition website.
And so it's funny.
A lot of people don't really know what a data scientist is or what that even means.
I mean, they think it's someone like a lab coat who mixes data from one vial to another.
And so this is pretty interesting. The site has a handful of competitions that are fake competitions meant to sort of teach you about data science, which I think is extremely extraordinary because it really sort of helps you understand that it's not about programming in a certain language or something like that.
It really sort of tells you sort of it gives you a list of sort of data science problems and then walks you through several solutions, which is pretty great.
Now, they also have serious competitions with real rewards.
And the way it works is they provide you with a data set.
So there's a competition going on right now where they provide you with a bunch of data from Stack Exchange. So Stack Exchange is
the sort of mothership for Stack Overflow, Math Exchange, and all these other websites where you
can ask questions, right? So people generally tag their questions. So you might ask a question like,
oh, I keep getting this Java runtime exception. And then you tag the question Java so that people looking to answer questions will be
able to do filtering, right?
So Kaggle has a competition where they give you a bunch of questions with the tags.
And then they give you another set called the test set of questions, but you don't know
what the tags are um so you are supposed to produce the tags for
that test set and then um send your your uh um your predicted tags to them to their server and
they will score them and give you a score back and the goal is to to get the highest score um
so all of these have a deadline each of these competitions and the scores
are pretty awesome like here's one flight
one thing too about these competitions
I don't know for a fact but I believe
pretty strongly that
the people that are
posting these competitions have like a vested
interest in the algorithms
well considering the reward for this one's like
let's just say $200,000
I'm pretty sure somebody has a vested interest in it yeah so so general electric i
guess that's who this is right they are offering 220 000 for somebody who can um solve this data
set as completely as possible over the next 30 days um that's actually pretty extraordinary most
of the most of the rewards are, are pretty small.
Actually, Facebook has a competition and the reward is allegedly a job at Facebook.
Um, which is, I think, pretty interesting.
But, uh, you know, most of the time the rewards are, you know, $5,000 or something.
The ones where the rewards are knowledge, that's sort of a special case.
That means these are ones that are meant to teach you data science
and how to be a data scientist nice um so is it the case that like this ge1 or whatever i didn't
read it but like is it the case some of these like they require like what was that the netflix
prize was a while back like they require a certain threshold of embeddement to be reached before they
award a prize or somebody will get the
prize at the end of this time period.
Yeah, that's a really good point.
So if you look at the leaderboard for any of these competitions, they actually have
some special spots on the leaderboard which denote sort of milestones and they expect
all of those milestones to be completed. Like, for example, looking at the GE one,
they had a sample submission benchmark.
And I guess you have to do,
if you don't do better than the benchmark,
then you won't get an award.
Like, for example, the Stack Exchange,
their benchmark is,
they pick the four most popular tags
and see if it's any one of those.
And if you can't do better than that,
then they, you know, if no one can do better than that,
then no one gets a prize.
Ah, okay.
But from the competitions that I've seen thus far,
everyone, every one of the competitions
has been won by somebody.
Okay.
So, yeah, it's pretty interesting.
I mean, I don't know sort of how competitive it is um anytime
you have something like this with the whole internet involved um you have to expect that
you'll get the best and the brightest and so um you know although they're offering this 220 000
dollars uh i wouldn't go in there expecting to win it or wanting to win it i'm sure there's like whole armies of people
are working on but it's still phenomenally cool to work on this and or on any of these and get
some good results and test your if nothing else it's more data for you to test your system on you
know well test your system on learn these techniques and like i'm sure this kind of thing
is even if people don't know what this site is when you go for a job or to change jobs that you know it'll let you talk about things
very confidently and you can point people to like oh here's stuff i did like i did these type of
analyses yeah exactly exactly um i do there's also a forum for each of
these competitions
and you can post you can
answer questions ask questions etc
on the
forum and yeah
I think it's phenomenally interesting
I definitely recommend everyone check it out
that's awesome
there's 34 days to go on the
Facebook recruiting competition.
So by the time you hear this, you're not going to have much left.
Yeah.
No, I'm just kidding.
Yeah, so these competitions are actually pretty interesting.
Yandex, which I believe is the Russian search engine,
is offering $9,000 to somehow do a better job ranking
given the personal preferences of the users.
I don't know.
I think this stuff is really interesting.
And it's pretty cool that the data is right there
for you to access.
Usually you have to go scraping Wikipedia
or doing something painful to get data.
But here's just a bunch of really awesome data
just waiting to be downloaded.
Cool.
Yeah, definitely.
So now we're on to FPGAs.
Wait, we're skipping my tool of the week?
Okay.
Oh, man, I'm so sorry.
You know what?
They both started with K, and I think I just, I don't know, my eyes just skipped it.
It's okay.
So my tool of the week is KiCad, or KiCad.
I don't know how you pronounce
it k-i-c-a-d okay and this is a tool again in theme with the show how apropos that rhymed um
is a tool for designing uh electrical circuits and building pcbs printed circuit boards um so
if you're gonna make your own circuit which if you get involved in any kind of hardware
microprocessor stuff you'll eventually kind of want to do this is an open source tool that's free
no limitations and lets you kind of lay out i want to have a resistor and i want to have this
processor chip and i want to have these inputs and outputs and plop them down arrange them connect
them up and then build a board
that would represent that schematic. And that's something that's normally done by very expensive
software. So a lot of people use this tool called like Eagle, or there's another one, I think it's
called Altium. But these are like very expensive, like thousands of dollars to have these boards.
And people use these to build like the motherboard in your computer right so like oh i need slots for ram and a slot for this processor
and you know i need these ports over here and this north bridge it's like all those things get laid
out and may have like you know four layers of different planes of circuit copper um in the
single board that is your motherboard or six or I don't even know how many
are in a motherboard okay but I don't want to learn any of that that sounds way too complicated
but I have been doing some projects like with an Arduino we've talked about Arduino before a
Raspberry Pi and you want to like connect things together and you don't want to have to use little
wires you could use a tool like this and either make your own printed circuit board which is something i actually want to try to do sometime or send it
to a company so i actually did this before i had an rgb led that so it's one led device but it has
three leds embedded inside of it one red one green one blue so you can make it any color you want um and i print i made a little circuit board
that's like an inch square or less um and connects pins so you can plug it on a breadboard to the
pins of the led which didn't fit on a breadboard well um and so i was able to design that in the
tool and get it ship it off to a company and they sent it back to me my little pcbs and
i got like three of them um from this place and how much did that cost it's like three dollars
wow so you can basically you can make you can make like a single board computer that does
something relatively simple for you know 20 bucks or something so it depends like it's based on the
size of the board you need how many
layers you need it gets complicated really fast but if you don't know about this tool it's cool
you should check it out this one's open source and so you don't run into limitation of size so
some of the other ones are limited like you can't go bigger than three inches by two inches
and if you do then like you'd have to pay but if you're designing something simple and only having
like one surface you might want to make something actually pretty big that you could do yourself and you couldn't
choose that tool so when i've been teaching my stuff myself this stuff i wanted to do it on
something where i wouldn't ever have to worry about running into some limitation and feeling
bad because i'm not going to spend thousands of dollars to buy the tool. Yeah, right, definitely. This is super interesting. It's actually, I love these Olo stats.
They're on many different open source sites,
but it says that it's 585,000 lines of code in KiCad.
So I don't know what that's doing,
but it's doing, there's a lot of effort there.
So there's a lot of things around like place
automatically routing the little electrical paths and stuff like that it's pretty cool you should
check it out um and actually uh recently cern um got involved with the project and they want to use
it for doing a lot of their circuit designs and so they're starting to contribute to the project
oh very very cool this is super interesting. Yeah, check it out.
How do you deal with like,
so I noticed on the picture here,
it has like a physical switch
and a physical serial,
like serial, you know, serial out.
How do you, I mean,
the company that you send the schematic to,
do they also,
do they do the switch part too and everything?
No, so typically you
decide in advance like i want a switch and then there's like common switches or they may have it
in a library or you may you know specify it yourself based on the data shade of the switch
that you've picked out and then when you get it back there are companies which will populate the
board for you like go ahead and solder everything on but that's typically much more expensive i
don't even i've never even looked into that but basically what i do is like oh i have these common parts already around and i've
made some example circuit and i just want to put it on a you know board and so you solder it on
yourself so you know in advance like i have this switch and you drop it on so you take a few of
the parts from your nuclear submarine that you use to hunt for superman's body and use that to build your next
project i'm gonna say yes i don't know what you just said um but yeah check it out if you're into
hardware it's pretty cool you probably already know about it and if you don't uh and it strikes
your interest or the things i said pique your interest uh you should look into it one more
thing on this
and then i'll let you off the hook but where do you go to buy the uh things like like switches
like very basic things like this like so okay motors how do you get any of that yeah so the
internet of course that's one answer so most of the electronics yeah so it's actually kind of
difficult so there's a couple like you'll learn about like these places digikey mauser uh element 14 like there's like different places you'll learn
about and maybe we can talk more about this in another episode because it's actually really
fascinating i'm really into this presently um but yeah so like there's websites like that but they
serve like people who are literally doing this for a job, right? Like building motherboards or building the electronics that go into cars or
just TVs,
anything.
Right.
And so they're getting parts for them.
And they just literally,
if you search for like a resistor,
they'll have a million different kinds of resistors.
That's really overwhelming.
So then there are other places like spark fund that are more hobbyist
oriented where they have the most common ones.
Like we know you'll probably want this. Like this is most basic switch if you just need a switch just choose this
switch so you could go to spark fun like find a few things and then go to digi key to like complete
the collection or something yeah like if they didn't have something and then you can also go
there's local electronic stores so there's like a place here specifically that i've gone to in the bay area of california that has like what they call surplus electronics so companies go out of business
or um there's like old equipment and they sell it to this place and then they allow you to come in
and you can buy stuff really cheap and they just have like bins and bins of resistors and you know
various capacitors yeah it's actually awesome to go to it oh my gosh we
gotta go okay are you uh is it is it baby safe like if we were holding the baby no no you would
reach out and electrocute himself or something well not electrocute but like swallow it's tons
of tiny components right oh yeah all right we'll have to find some time to do this. This sounds pretty epic. Okay. It is pretty cool. It's a lot of fun.
So anyways, so on to FPGAs.
Yeah, FPGAs.
So I actually, I think I know.
So of course, you know, just some background.
I did almost entirely theoretical computer science.
And Patrick majored in computer engineering.
And as a result, I am a complete Luddite when it comes to any of this but i know a few things i will try my best to keep up uh so fpga is uh programmable gate array
what's the f field oh yeah field programmable gate array and um i'll let you take it from there
so this is going to be an interesting topic we'll talk a little bit about programming because um
programming fpgas is is kind of interesting and different but also just about like how fpgas may
interact with processors so if you're ever doing any what's called embedded systems programming
you often um deal with fpgas or can deal with fpgas at a company so it's they're
very common um in a lot of commercial applications or um just depending on what you're trying to do
you you may come across it and it's good to know because you'll see it out there and people talking
about it uh if you're doing any non-theoretical or only high level application programming
so so a little bit of history is that um so we talked a little bit, and when we were talking
about the book of the show about Boolean logic and AND gates and OR gates, and these are the
things which kind of represent when you have like a one and a zero, and you want to say,
if only if both of them are true, do I want the output to be true? And so you have that Boolean
logic and you can use Boolean logic to describe, you know, ever growing complicated components.
So with just a few AND and OR gates, you can describe a thing called a multiplexer.
And a multiplexer says like I have five different input lines and I want to specify which of those five get put onto the output.
Or I have two numbers and two what's called registers, little bits of memory, and I
want to add them together. So you can specify that with just a handful of AND and OR gates.
And once you have all of those components defined, you can add those components together
and actually build CPUs. So that's how a processor gets built is from a collection of these digital
gates. And in fact, there are a couple gates that can be used to make all other gates.
So with only a single type of gate, you could actually build an entire CPU. And if you ever
take any classes of it or follow any tutorials about this, it is actually really rewarding.
One of the things I did when I was in school is start from those ANDs and OR gates and actually
build up to a whole, I think we made a four-bit processor. And you actually had memory and an
instruction set, and you had had memory and an instruction set
and you had to learn like what assembly programming really is about and a little switch that you were
at the clock like you would switch the switch up and down and actually clock the cpu so it was like
a one hertz four-bit processor um and the final exam for the lab part of the class was actually the TA for the lab would bring in a piece of memory
on a chip, plug it into your CPU that you had built, and you would sit there and clock it,
and you would have LEDs that represented the output. And he would write down after 10 clicks
of the clock, like what the LEDs were after 20, after 30. And then they had to be right in order
for you to pass and it represented the
instructions actually being executed and the results being displayed um and you had no idea
what was in his instruction set that was on his you know what the instruction set was because
they gave it to you but you didn't know what specific program he had just run on your processor
oh i see so yeah so i think i mean so from and correct me if i'm wrong i think the reason why
you know one would want to program their own fpga is because when you work with just a regular
processor you're doing things in serial and the processor can do anything you know you want it
can do you know multiplication add division you know many other operations but uh but it's designed to do like to do any of those
and it's not really balanced one way or the other or i guess it is balanced it's not biased one way
or the other and so if you need to do you know 40 add operations they're just all going to queue up
one after another um now the processor will try to do like out of order execution and you know processes have
gotten very complex but the reality is you know you need to add an entire array of numbers at once
that's the way that's the way your program is designed or your the algorithm you want to create
its design then with an fpga you can literally have eight copies of the ad, you know,
mechanic all running at the same time.
Yeah. So it's like a really good idea.
So like if you have like a 32 bit processor and you want to add two 64 bit
numbers, right?
So the 32 bit processor there means like the width of the data coming through
is, this is a lot of hand-waving,
but basically that you can have 32 bits per number
and you can add two of those numbers together.
But you have 64 bit numbers.
Well, that means you have to do the adding twice,
you know, once for each pairing.
But like you said, you could in an FPGA
have 256 bit adding.
So add 256 bits twice at one time.
And if you wanted to do custom things like,
oh, I want to multiply this,
add it to the previous result,
and also do this other custom thing
that's only to me,
a processor won't have that special logic.
Processors sometimes do have specialized logic
if it's not too specialized
and they think it's useful to everyone.
But an FPGA can have whatever logic you want.
So it can do custom things that are crazy
and don't make sense and do them all in parallel all at once because there isn't uh the way the
clocking works it isn't like this thing feeds to that thing feeds to that thing feeds to that thing
by necessity it can just be like I want to do all this stuff at once all at the same time yeah
exactly and so that is the reason why you would you know have FPGA. And it's going to get a little...
We could go into a lot of the history and stuff
and ways of representing it,
but I think I'm actually going to skip over it
because I think it'll end up being kind of boring.
One other thing I'll mention about the FPGA
is that it saves a lot of power, right?
I mean, as we talked about,
the processor is a general-purpose machine
that has many, many different instructions,
and it's actually extremely
complex and does has what's called a pipeline where it can be working on several instructions
at the same time but if you're working on you know building a phone or a small device that
you know you want to put in your car or something like that then power becomes an issue and and so
you know writing your stuff in FPGA
might make the difference between something running
for an hour on battery or four hours or longer, right?
Yeah, and there's other things that, you know,
processors just don't do good at
because the idea with a processor is it's like set,
like whatever gates they put into a processor,
because processors and FPGAs are both kind of gates fundamentally. Whatever they put into a processor because processors and FPGAs are both
kind of gates fundamentally whatever they put into a processor they select one set of gates and that's
all you get and so they have to optimize for a lot of cases so they can sell it to a lot of people
and they don't know what you're going to do but the FPGA is just the raw collection of gates
so you could take that collection of gates and build the same processor in it.
And they actually do that.
It's called like a soft core.
So you can take an ARM processor
like is in your cell phone
and manifest it in an FPGA.
So arrange the collection of gates in FPGA
to be an ARM processor.
And if you want like extra floating point ability,
you could add it in.
If you wanted extra like, you know, like an extra wide pipeline, you could add that part in or take parts out.
Oh, interesting.
That's what the field programmable part is about is like in the field, not in the factory.
Like you can change the combination of gates.
So you can bring in and drop out your own processor or even things which we wouldn't normally do in a processor oh i always wondered where the field came from and yeah it makes sense
like the field as opposed to the factor i like that so we can get into yeah it's it's a long
discussion talking about like the kind of actual like engineering things behind this and what
happens but you can define like an fpga to do any kind of things you
might want to do in a processor or things which you wouldn't want to do in a processor and the
ways that you kind of program them like write the programs one is we were talking about like logic
gates and logic gates have symbols um and you can kind of draw a circuit a schematic that describes
what you want the fpga to. So I want it to look at
switch number one and switch number two. So switch being, as an example, like a light switch.
So I only want to turn on the lights in my living room if both light switch one is on and light
switch two is on. So I have an AND gate that looks at light switch one and light switch two,
ANDs them together, and the output goes to determine if the light is going to be on or off.
And you could draw a little picture of that,
and the FPGA would be able to replicate that logic.
But as you get to bigger and bigger and bigger and bigger devices
and more complex logic,
those gates become even worse than writing an assembly code,
like even lower level.
So then what they have is some sort of
what they call hardware definition language.
So you'll hear VHDL or Verilog.
And VHDL and Verilog are,
without getting into specifics on there,
are ways of describing how the FPGA should function
and how things should have,
you could use, I want to add what's in place number one to place
number two when the clock ticks so every time the clock ticks whatever's in location one and location
two add them together and put them in location three every time i get a clock tick oh i see so
and so it implements the ad operation i guess for you right so it determines how to configure the technology inside the FPGA to basically do
the add operations every time you have a clock tick so that's one of the things that's interesting
about FPGAs versus processors is that an FPGA like you have to talk about the clock so in the
processor you talk about like oh my clock speed is 16 megahertz or one gigahertz and that means that like some operation an
operation that completes in one cycle completes in one one millionth of a second for a megahertz
and i can count how long a certain set of operations will take so if you need to do
something really fast you need to know how long each instruction takes when fpj it's even more
prevalent that you have to think about long each instruction takes. When FPGA, it's even more prevalent that
you have to think about clocks and how fast your clock is running and that each time the clock
ticks, because you're kind of defining this pipeline, like a step A, I want to do this,
step B, I want to do this, and step C, I want to do this. So every time the clock ticks,
things are moving down the pipeline, but the next set of things are coming in right behind them.
And that's for what you call kind of like streaming operations
So FPGAs are used heavily and in streaming operations like if you imagine a video camera
Has data coming in every time it takes a picture
so a video camera is just taking lots of pictures one right after the other and
Those pictures just keep coming in and coming in and coming in and coming in and in a processor if you spend slightly too long
Processing one of those frames all of a sudden all those other frames after you get pushed down the line and
you end up with a problem and an fpga you're defining that like every i'm doing this then
this then this and those frames just keep feeding in and you it's doing the same thing pretty much
every time and um yeah it can't really get backed up because
there's no pipeline or buffer well it's like you're but you've no you define it so strictly
right so it's not like there's oh i see there's not it's not like branching right like oh if i
see you know the color blue do this if i see the color green do this you know you don't do those
kinds of things fpga is fpga is much more about doing like
a known set of operations like i want to you know divide every pixel by you know three and then add
it to what the value of the previous pixel was so it's kind of like you want to define that and we
talked previous about like gpu programming and how gpus don't like having branches in them right because when you do general purpose gpu programming the branches make it
more difficult to kind of to do and so fbgas are are similar in that regard they're really good for
when you know precisely what you want to do every time and you don't have a lot of complex
logic and and algorithm around it so so that that talks about what it's really
what about yeah like if you have so if you're writing this VHDL or Verilog and
you so it sounds like you're almost writing arithmetic like add these two
registers and do this how do you specify like these things can be done together
but this thing needs the other thing I mean does it figure out all the data
dependencies for you so partly right you're defining yeah so you're defining together, but this thing needs the other thing. I mean, does it figure out all the data dependencies
for you? So partly, right, you're defining, yeah, so you're defining, like, oh, here's kind of, like,
this component, and this component feeds into this component. So kind of like functions, right? So
that's the equivalent. But it is a data flow language, right? So you're describing how the
data flows through the system, and so you you're describing that flow and it is something kind of starkly different from writing a imperative
program uh it's much more functional programming kind of style okay so so the reason why like fpjs
are good it's like we talked about that you know doing things in parallel so you have one processor
so you can add one set of numbers but if you wanted to do like 10 of those at the same time you might have like
10 cores in your processor then you could do it but like an fpga if you're doing some simple thing
you could just create a hundred of these cores where a core does some very basic operation over
and over again and you can just keep creating more and more and more of them and so you can get that parallelism very easy and for like we said certain sets of
algorithms where it's very set what you want to do and you you just want to compute it and you
want to do it really fast and over and over and over again um taking time to implement that
algorithm in fpga can get you a lot of speed. Gotcha. Yeah, it also affects the power greatly.
A lot of the smartphones now do MPEG decompression on,
well, not an FPGA, but on, actually, how does that work?
So if you write something in FPGA, can you turn that into a processor?
Yes.
Okay.
Sort of.
So a lot of those, they called like co-processors you'll
hear about um so like the mpeg encoder so it could be that that's just like another normal processor
but more likely it's a very specialized processor that's called an asic and i don't know what asic
stands for actually something i see which is integrated circuit i will look it up right now
okay all right good so basically So basically in ASIC,
you can take an FPGA description,
a VHDL description,
and synthesize an FPGA,
which means figure out how to take this field programmable,
this reprogrammable set of gates
that you can interlink in different ways
to represent the logic that I've defined
in my VHDL program.
But by the same token,
the tool could also say take that set of
logic and determine the set of masks you would need to make to etch away at the silicon to
actually make a custom chip out of silicon that does that one specific thing but once you do that
asic stands for application specific integrated circuit,
which I don't know what that means. So like I said, so it's like once you make an ASIC, that's
it. Like you can't change it anymore. And it involves a lot of engineering costs to kind of
determine how to go down to the actual gates and determine I only want these sets of gates and it's
not reconfigurable. And once you make it,
that's it.
And you use it for a specific purpose.
And so that's probably what like that MPEG chip is about.
So somebody wrote this description and VHDL of how to do a portion of the
MPEG encoding process really,
really fast.
And then they actually went and had a specific silicon chip made that does just that
and then they put it in all the smartphones i see so an fpga would be like the first step to that
like the prototyping step before moving to an asic but it could also be that you asic is too
expensive for your need and so you just continue to use an fpga so like an asic per unit like per chip would be a lot cheaper
because it's doing you know it's like made and only does one thing but like the initial cost
like you'd have to buy thousands of chips i see you can't just like go buy one so maybe this uh
going back to this the first news story about coin uh i guess maybe they will you know take this pre-order money that we
give them and uh and put the logic for switching the credit card numbers and things like that on
asic yeah so they could does that make sense okay i mean i don't know that that's what they're doing
but yeah right it is like an example of yeah what what you could do gotcha so like there are some much smaller than
an fpga that does the same thing i mean is it is it vastly different or is it about so so yeah i
would say that yeah like if you had an equivalent how big of an fpga do you need to hold a set of
operations versus an asic the asics can be much smaller because the fpga needs to have all this
extra routing and switching logic to be able to be reconfigured
and you don't need that in the asic you're hardwiring one specific configuration okay
um so some of the things that make it difficult is there this fpga programming falls in kind of
a weird space right so computer science people like you know jason was describing himself would be
very uh you know distraught to learn about all these details they had to pay attention to about
clocking and interfacing with external power and those kind of things um and electrical engineers
don't always enjoy programming some do but some know, don't really want to do programming. And so this FPGA programming falls in between those two disciplines. And sometimes it's hard to find people who want
to or have the ability to do it. And it can be difficult sometimes to take the logic of like a
C program and actually determine how to do the same thing with the constraints of FPGA programming and VHDL.
Gotcha, yeah, I mean, to Patrick's point, right,
like the reason why you'd want to do this in FPGA
is to get some kind of like parallelism
or speed benefit or something like that.
So you can't just take your C program
with the four loops and things like that
and just put it directly into VHDL or verilog because you lose all of your benefits so
so when you go to something like an fpga you have to think about uh the data dependency like can i
do all iterations of this for loop at the same time or if i can only do part of them at the same
time uh how do i structure my operations so that i know they're finished in time for the next
batch to start things like that yep and testing is is pretty hard so like i said fpga's uh you
know interface don't have like the processors handle interfacing with outside world with all
this specific logic but like on an fpga they're meant to be used in different ways and so often you have
to worry about uh interfacing the outside world and determining the set of inputs you want to
test against so like what happens if one of the inputs to your fpga isn't zero or one but is
floating around what happens to your like your algorithm and how do you test that? Wait, what does that mean?
How could it not be zero or one?
So, okay, we'll get sidetracked, but it's okay for a second.
So if a processor just for ease is running at five volts,
so you powered it with five volts,
then when it sees a given pin that is called an input pin,
if that pin is at ground, then it says it's a zero.
If it's at five volts, it says it's one.
So that works really well.
Digital says it needs to be either zero or one.
Right.
But what happens if you don't connect anything to that pin
and the pin is just getting electromagnetic interference
and it's varying from zero volts to eight volts
to two volts to six volts oh
oh you have to you have to deal with that while you're programming that so so yeah so like it
could just be flapping around on you right like and typically because of the nature of the way
fpgas sometimes want to handle those kinds of things you have to handle those kinds of things
versus like in a processor people assume you don't want to handle those kinds of things you have to handle those kinds of things versus like in a processor
people assume you don't want to handle those kinds of things so they typically build the board such
that doesn't happen gotcha um also the tools like still there isn't really good like open source
tools for programming fpgas and synthesizing that like what amounts to the compiler, the thing that takes your VHDL and determines
here's how I would program a set of logic gates.
And even I looked around because I wanted to,
as a hobby, really program.
I've done some FPGA programming in the past
for work-related stuff,
but as a hobby, I wanted to do it.
And the boards are typically pretty expensive
to get one and actually try it out.
And the tools themselves are very expensive. So thousands of dollars for these tools that compile these FPGA programs that
you write. And often they're student versions or free versions. And there are even some tools,
and I've used a couple of them before, very limitedly, where you actually can use a restricted set of C language to define
an algorithm and it'll synthesize the FPGA for you. So it'll take your C language, compile it
to VHDL and then take that VHDL and pass it into one of these tools. And that tool will make the
FPGA. And those are getting better. And one day people hope that like, you'll just be able to program an FPGA in C++.
But if you do that, how do you tell it that,
you know, that it should have, you know,
three add modules instead of two?
Yeah, so there's special kind of pre-processor tags you add
and say like, kind of hash, you know,
pound in parallel eight and then a for loop right so
do eight iterations of this for loop in parallel i made that up but like that would be an example
of what you right right yeah so you annotate your code to help right that's pretty cool yeah i'm
looking i'm looking around on on uh shopping google shopping yeah it looks like it'll run you a few
hundred dollars to get fpg which actually
isn't that bad no they have some they have some smaller ones that are sub a hundred dollars so
so yeah um but versus like you know i've played around with little microprocessors and writing
c code like arduino style and you can get an arduino for you know twenty dollars or the
processor that is used on there you can get get for like $1.30 or $1.50 or
something. Yeah, that's true. So one of the interesting things is, you know, a lot of times
you pair an FPGA with a processor because they both have their advantages. And so you can either
talk like, you know, serial to the FPGA and communicate with it.
Or oftentimes what's interesting is
when you go to a memory address in NC,
then you are actually setting some pins on a microprocessor
to hold the address that you specified.
So in binary, these pins will represent
that address you specified.
And then another set of pins will start taking on the values of the data you write to that
address, for instance.
So some of the memory you have is what's called internal memory.
So when you do that, nothing will happen on those pins.
You'll just write to internal RAM.
But then other parts of the address space, it's called, will map to these pins that are
exposed on the outside of the processor.
And when that happens, the FPGA could actually be sitting there.
So one way you can talk to an FPGA is to say like, at address 5000, when you put the number
three, I'm going to go turn this light on.
And when you write the number four, I'm going to go turn it off.
And then you can actually talk to it by writing kind of specific values to specific addresses. And that's a lot you'll see common even when you write like device
drivers are handled that way. I always wondered this, if you try to set the pins that are
connected to the output of an FPGA instruction, what happens then? I mean, does, like, the world collapse?
No, it's handled.
But, yeah, like, you've got to be careful.
So what would happen?
Like, nothing would happen, I guess? So, like, if you – I'm not actually sure what would happen.
So if you had two output pins connected just to each other,
they'll try to drive each other.
So I guess one would win.
Oh, I see.
And so that would take on whatever value
of one of them or some value in between i i don't remember well i guess maybe sorry the question i
was asking is can you do and can you go through an fpga backwards like what what happens if you
like instead of setting the input pins and then reading the output pins, if you set the output pins, what would happen? Would the electricity go backwards through the FPGA?
No.
Okay.
Typically, so it's configured where the outputs are configured in one of three,
a pin is configured in one of three states to be an input, an output,
or what's called disconnected, like a high impedance state
where no matter what you do, otherwise it's not going to affect it.
So when it's an input, it's trying to read the value.
So anything can happen on the thing.
When it's an output, if two things are an output, they'll compete.
And typically there's circuitry built in to protect them
from the current flowing backwards.
But what happened, there's what's called contention on the line
so like whatever that piece of wire between the two will it's undetermined whether it'll be a zero
or a one whether it'll be positive or ground gotcha but yeah they typically protect themselves
from having current to flow backwards that would be bad yeah right okay that makes sense so like i said um you know a processor
and an fpga could be embedded together on a device you can also have a version of the processor
inside of an fpga so some part of the fpga is currently representing a processor and then other
parts other things oh interesting and that's called soft cores and so you can embed like an ARM processor inside your FPGA. And now people even talk about
doing things like if I enter different modes of operation having a processor to
load a different program as it were on the FPGA. So reprogram the FPGA in the
middle of something to behave differently. Oh wow. So you go to
watch a video and the FPGA reprograms to be an MPEG decoder.
That's right.
And now I'm recording a video,
so it switches to be an MPEG encoder.
Wow, that's awesome.
And now I'm doing something else.
How come that isn't widespread?
That sounds like an amazing idea.
I mean, I think it's just one of those
very difficult things to do.
Like how to figure, not only do you have to program the FPGA once,
now you have to like figure out the code for all these different ones
and then when to switch.
Gotcha, gotcha.
And then it might just be easier like as technology gets better and better,
like instead of having reprogramming it between two different modes,
you just have an FPGA that's twice as big and then you can program it to be both at the same time
oh true that makes sense so um but people have talked about it and there's some interesting
stuff around that well this is very cool so what from what you've taught us we should be able to
go on digikey buy some cool motors and electronics and FPGA and go to town.
That's pretty awesome.
I might try this.
Yeah, this isn't our normal episode.
Like I didn't really go through the merits of VHDL or Verilog or how to program them.
It sounds like there aren't really any competition for these two.
Yeah, but hopefully it sparked some interest or explained what it is.
A lot of people have heard the term FPGA and just interest or explain what it is a lot of people
have heard the term fbj and just don't know what it is or what it does or what how it's different
yeah yeah definitely this is awesome i've always wanted to build to do something in the robotic
space um on my own but uh i've never had the talent to do it so maybe this will be even just
something as simple as like if it could just go and open the fridge and get a sandwich like like or
something like that but even if I have to tag the sandwich you know something
very simple it'd be fun to just do it for fun you know yeah that's still
setting your sights a little high yes I like what if I an LED to blink on and off. Yeah, I guess that's true. I should probably start there.
Okay.
All right.
Cool.
I think that's a show.
Yeah, thanks a lot for helping carry this show.
It's a really interesting topic.
I thought it was awesome.
All right. And thanks for all our comments.
People encouraging us to get back on their mics
and record the next episode.
Yeah, definitely. It's pretty hard, right? Because, you know, we've been going through a lot of changes.
I've actually I actually work across town now. So it's a big transition for me.
And actually, yeah, we installed Ticket to Ride in our house.
And so we have trains going by constantly.
So now when I mute that audio, people aren't going to know what you're talking about.
Oh, dear.
Okay.
But yeah, we've had a lot of personal stuff.
Trains are driving by my house.
Yeah.
Now you can't mute it.
Not without everything being awkward.
But yeah, so I've had a lot of personal
stuff going on but i appreciate everybody's patience and uh you know we definitely have a
lot of fun doing this show i learned something brand new every show uh and i'm sure you guys do
too so uh you know thanks for all the support and uh have a good time all All right. Until next time. If you build anything, you have to let us know.
I want to see pictures.
All right.
Bye.
See you later.
The intro music is Axo by Binar Pilot.
Programming Throwdown is distributed
under a Creative Commons Attribution
Share Alike 2.0 license.
You're free to share, copy, distribute,
transmit the work, to remix, adapt the work,
but you must provide attribution to Patrick and I and share alike in kind.