YouTube2Text

EECS 373 - Fall 2026 - Lecture 10: "Timers Resolution vs Length & Serial Bus Overview ” — Transcript

by Interactive Sensing and Computing Lab · 12,575 words · 1,816 segments · language en · Watch on YouTube

Full transcript

  1. 0:03All right, we'll get started.
  2. 0:05>> So, today we're going to be finishing up
  3. 0:07timers, doing a little bit of a system
  4. 0:09timer stuff, and then Wednesday we'll
  5. 0:12start on serial interfaces.
  6. 0:15So, homework 4 is due today.
  7. 0:18Uh we'll have office hours today after
  8. 0:20class and then uh the big thing is that
  9. 0:23Friday is a team formation event. To get
  10. 0:25prepared for that, you have to submit
  11. 0:26some ideation slides. I'll talk about
  12. 0:28that in a second. Um, and we'll serve
  13. 0:30pizza. And basically the event is you we
  14. 0:34give you an outline of the project. You
  15. 0:35guys pitch your ideas and form teams.
  16. 0:37Um,
  17. 0:39let's see. We we made a new project page
  18. 0:41for the class website. It should have a
  19. 0:45better formation of all the things that
  20. 0:46students need to do for the project. So
  21. 0:48that was a concern last time. The thing
  22. 0:50we haven't done is figured out we're
  23. 0:52have not implemented easy way to
  24. 0:53duplicate all the dates here over to
  25. 0:55here without just doing it manually. So,
  26. 0:58either we will just do it manually or
  27. 1:01we'll figure out a nice way to do it
  28. 1:02automatically, but if you're looking for
  29. 1:04a date something's due, it's on the
  30. 1:05assignment page for now, at least for
  31. 1:07the rest of the week.
  32. 1:09Um, we released the project details.
  33. 1:12It's not particularly different from
  34. 1:13years in the past. I think we're going
  35. 1:15to say that there can be no teams of two
  36. 1:18with a class this size. It's just not
  37. 1:19tractable. So, it's got to be teams of
  38. 1:21three or four. You could do five if you
  39. 1:23had to. Um
  40. 1:27yeah, we changed the format of the uh
  41. 1:30project proposal a little bit. Um but uh
  42. 1:33you guys can read through that and ask
  43. 1:34questions if you need. And then for
  44. 1:38Thursday um you need to submit your
  45. 1:41slides and unfortunately have to do it
  46. 1:43in two places this year. So one is
  47. 1:44submit for grade scope just for uh
  48. 1:47grading purposes and other places you
  49. 1:48need to take a copy of your Google
  50. 1:50slides and put them into a folder uh
  51. 1:53that the class will see. So, just so you
  52. 1:55know, other students, only students in
  53. 1:56this class will be able to see the other
  54. 1:57slides. That's so people can look
  55. 1:59through the slides and start seeing,
  56. 2:01hey, this seems interesting to me. At
  57. 2:03least they get to know who's involved
  58. 2:05and who's thinking about similar ideas.
  59. 2:07Um, if you make your slides in
  60. 2:09PowerPoint or Keynote, you'll have to
  61. 2:11convert them to um
  62. 2:14Google Slides and then I'll run a script
  63. 2:16to make them all into one file before
  64. 2:18the meeting. Uh, yeah. And then yeah, I
  65. 2:23think we'll be on Friday from 4:30 to
  66. 2:256:30 or so, probably 6:00. Do you have
  67. 2:28any logistics questions for what's going
  68. 2:30to happen this week?
  69. 2:41Okay. [snorts]
  70. 2:43Oh, and then next week, the goal is to
  71. 2:46have your teams registered. There's a
  72. 2:47form you have to fill out online. Uh you
  73. 2:50just say, "Here's your team. Here's the
  74. 2:51members. Here's a a quick a name for
  75. 2:54your team. And that can change later.
  76. 2:56Um, and the goal is to have it done by
  77. 2:58Tuesday. If you really can't, well,
  78. 3:00first of all, if you don't have haven't
  79. 3:01found any team members by Monday, come
  80. 3:03see me after class. We'll uh help you
  81. 3:06find a team. You can always advertise on
  82. 3:08Piaza. if you're looking for teammates
  83. 3:10or you're looking for to join a team and
  84. 3:13then you know if you really can't get it
  85. 3:14done by Tuesday then come see me on um
  86. 3:18let me and James know through email or
  87. 3:20come to see us directly so we can make
  88. 3:22sure we find a team for you.
  89. 3:25>> Yeah,
  90. 3:28>> you don't have to. Usually what happens
  91. 3:30is that people have starred slides and
  92. 3:33they're like would anybody like to
  93. 3:34present? Would anybody like to pitch an
  94. 3:36idea? Right? Because it's really like
  95. 3:38no, you're not required to present. No,
  96. 3:40it's not a formal like pitch or
  97. 3:41anything, but you could just go up there
  98. 3:43for three minutes or a minute and just
  99. 3:44say this is my idea. Aren't you excited
  100. 3:46about it?
  101. 3:49>> Yeah.
  102. 3:56>> Sure.
  103. 3:58Hopefully you'll get the forcing
  104. 4:00function of making three good slides
  105. 4:01will get your ideas out. Yeah. Can you
  106. 4:05describe the complexity points like for
  107. 4:07instance for a group of three versus a
  108. 4:09group of five what number of features
  109. 4:11you need?
  110. 4:14>> A course way to think about that is you
  111. 4:15need a number of features plus one for
  112. 4:17your group size. So your group size
  113. 4:19three you need four you need. So you
  114. 4:21just need one extra feature. Now you
  115. 4:23know blinking LED is a lot easier than
  116. 4:26you know make some arbitrary LCD screen.
  117. 4:28So we'll give you advice. will give you
  118. 4:29feedback on like we think that's uh
  119. 4:31meaty enough or maybe you need to add
  120. 4:33something.
  121. 4:35>> Yeah.
  122. 4:36>> Do you require certain communication
  123. 4:38protocols like
  124. 4:41>> No, it's pretty free form. The proposal
  125. 4:45asks you to write a bunch of stuff up,
  126. 4:46but you probably don't know all the
  127. 4:48answers to every single question in
  128. 4:49there as well. It's more of a guideline.
  129. 4:50These are the things you need to start
  130. 4:52thinking about. Um, for instance, you
  131. 4:54may want to uh one of the things we ask
  132. 4:56is like think about what's the power
  133. 4:58requirement, voltage and current of your
  134. 5:00particular device. Well, if you just
  135. 5:02said, I want a mythical uh laser
  136. 5:04rangefinder. I have no idea if we can
  137. 5:06even afford that. You're not going to
  138. 5:08know the answer. But at least you should
  139. 5:10start thinking about like, okay, I'm
  140. 5:11going to have to think about power. So,
  141. 5:12it's not like you have to define the
  142. 5:14entire project, but you have to have a
  143. 5:16clear idea when you come to our your
  144. 5:17pitch meeting with us.
  145. 5:21>> Okay. All
  146. 5:24right. So, I wanted to to finish up
  147. 5:27timers. And I think there was a a
  148. 5:29challenge. I don't know. I thought
  149. 5:31talking to folks, there's this confusion
  150. 5:33between resolution and a timer length,
  151. 5:36like how long a timer can go versus how
  152. 5:39precisely you can measure the passage of
  153. 5:41time. And by resolution, I mean like
  154. 5:42what's the minimum step size that you
  155. 5:44can measure. So, I wanted to kind of go
  156. 5:45over that concept again and see if I can
  157. 5:48uh do a better job this time.
  158. 5:52All right. So, we'll just do a little
  159. 5:54quick review of timer basics here. So,
  160. 5:56you have some clock that's going in. We
  161. 5:58have a pre-scaler. Remember, the
  162. 6:00pre-scaler on at least on your devices
  163. 6:02is just a divide by two uh or divide by
  164. 6:06two to the n. Um, so maybe slightly
  165. 6:09different than a pre-scaler that you may
  166. 6:11see other places, but that's fine. It's
  167. 6:13just a way to reduce the clock speed.
  168. 6:17You never I can't think of a time when
  169. 6:20you ever want to increase your clock
  170. 6:21speed. At least that's not how timers
  171. 6:24typically work. I've never seen one that
  172. 6:25works that way. So, it's always the
  173. 6:27assumption you have a much faster clock
  174. 6:29and you're trying to slow that thing
  175. 6:30down.
  176. 6:33And this is a particular equation for on
  177. 6:35your device uh that you know you're
  178. 6:38going to take your input time or input
  179. 6:40frequency and divide it by a power of
  180. 6:41two to get your output frequency. uh
  181. 6:43other microcontrollers will just have a
  182. 6:45slightly different modality or slightly
  183. 6:46different equation. It doesn't really
  184. 6:48matter. The idea is that you're going to
  185. 6:49slow it down.
  186. 6:51Then you have some counter. This is just
  187. 6:53it's easiest just to think about this as
  188. 6:55a up counter. Although there's lots of
  189. 6:57flexibility. They can go up, they can go
  190. 6:58down, they can go up, then down, but
  191. 7:00really this is just passes
  192. 7:03uh counts each uh clock edge that comes
  193. 7:06into that thing. And this has a running
  194. 7:08value.
  195. 7:10And of course, if you didn't put any uh
  196. 7:13uh period reset in there, it would just
  197. 7:14overflow. Eventually, it'll count up to,
  198. 7:17in this case, you're using 16- bit
  199. 7:18timers. It'll count up to uh 2 to the 16
  200. 7:21or yeah, two to the^ 16, and then it'll
  201. 7:24overflow. But you, it's pretty coarse
  202. 7:26way of controlling the passage of time.
  203. 7:28So, often times you'll have a period
  204. 7:30register. Other microcontrollers will
  205. 7:33call it something else. And so, this is
  206. 7:35just says when you reach this value,
  207. 7:37then reset the timer. Right? That's all
  208. 7:39it's giving you control over how long it
  209. 7:41counts up to.
  210. 7:44And then usually there's some output
  211. 7:46event like when you have hit that thing
  212. 7:49then you can cause some action to occur.
  213. 7:52So you count up to whatever your uh
  214. 7:54period register is and then you get an
  215. 7:56output signal and that can go to uh
  216. 7:58interrupt that could go to another timer
  217. 8:01that could go to another place on the
  218. 8:02chip or it could just be held in a
  219. 8:04register in case um you know maybe that
  220. 8:06the for some reason the core is going to
  221. 8:08come and pull that value. You don't uh
  222. 8:11there's lots of different flexibility
  223. 8:12and your microcontroller gives you a lot
  224. 8:14of different options. So does anybody
  225. 8:16have any questions about the basic
  226. 8:18structure of the timer?
  227. 8:24How how do you feel about this one's
  228. 8:26This one's working. Thumbs up. You have
  229. 8:29no idea what's going on. Don't want to
  230. 8:31raise your hand. Okay, cool. That's
  231. 8:33fine. I'm here to here to try help out.
  232. 8:35All right. So, when we're thinking about
  233. 8:39the pre-scaler, the pre-scaler is just
  234. 8:41trying to and this is so this is just an
  235. 8:43example waveform. There's some uh p
  236. 8:45period register, so it counts up to some
  237. 8:47value and resets. We have an input clock
  238. 8:49and then you have a pre-scale clock. And
  239. 8:51so the idea I really want to think about
  240. 8:53is here. Oh, and here's this initial
  241. 8:55value. So say pre-scaler set to to two
  242. 8:58to the one. We've got 21 clock cycles
  243. 9:01here. And the resolution, the smallest
  244. 9:03me thing we can measure here would be
  245. 9:05something of two clock source clock
  246. 9:07ticks, right? You can't measure
  247. 9:09something smaller than that. And so here
  248. 9:12we can scale that thing, right? This is
  249. 9:14my PowerPoint scaling. You can just make
  250. 9:16this thing really long. And that's just
  251. 9:17by changing your your pre-scale factor.
  252. 9:20So here I just doubled it. It's
  253. 9:22approximately doubled, you know,
  254. 9:23PowerPoint accuracy here, but I've
  255. 9:26doubled the uh the pre-scaler, which
  256. 9:29means now my uh period has gone from it
  257. 9:33was 21 clock cycles before, now it's 41.
  258. 9:36Right? So just by doubling that, now I
  259. 9:38can count things that are much further
  260. 9:39out in time. But I've sacrificed
  261. 9:41something. I've sacrificed my
  262. 9:42resolution. Now the smallest interval I
  263. 9:45can measure is four clock cycles.
  264. 9:49Yeah.
  265. 9:58>> Uh we say let's just say us always on
  266. 10:00the rising edge.
  267. 10:04Why do you think why is that troubling
  268. 10:05you? What are you thinking?
  269. 10:11Uh, it looks like it's rising on rising
  270. 10:13falling edge.
  271. 10:15Okay, maybe my uh my diagram is only
  272. 10:18PowerPoint quality.
  273. 10:21It does look that way, doesn't it?
  274. 10:23Rising falling edge.
  275. 10:25All right. Well, I get to update those
  276. 10:26tonight. But regardless of that minor
  277. 10:29fact, um the real idea here is that uh
  278. 10:33as you increase your pre-scaler, right,
  279. 10:35your period increases. So the longest
  280. 10:37thing that you can measure starts
  281. 10:38increasing, but the amount of time that
  282. 10:40you can measure is decreas or the
  283. 10:42resolution is decreasing.
  284. 10:46All right? And then you can do the
  285. 10:47opposite one. You could decrease your
  286. 10:48pre-scaler,
  287. 10:50right? And here the challenge is you
  288. 10:53know you made your pre-scaler basically
  289. 10:55uh to not divide. Uh you went down to 11
  290. 10:58clock cycles. Uh this is because when
  291. 11:00you're you're counting up you always
  292. 11:02have to count zero as well. And so
  293. 11:04you've gone up 11 clock cycles. Uh so
  294. 11:06you're shorter period but now your uh
  295. 11:09clock resolution is one clock cycle.
  296. 11:14So any okay so uh and then we can go
  297. 11:18back to the normal case and then where
  298. 11:20your um period register comes in here
  299. 11:23this is just allows you to control how
  300. 11:25many clock ticks there are so here we
  301. 11:27just increase the amount of clock ticks
  302. 11:29that you go through and now you can set
  303. 11:31this value to something here 26 uh clock
  304. 11:35cycles for instance now I get to control
  305. 11:36the length of time but you can only
  306. 11:39control up until the point where you've
  307. 11:40overflowed you can't control past that.
  308. 11:52All right. So, this table, which you can
  309. 11:53probably barely see, but it's at least
  310. 11:55in your slides, kind of showed you this
  311. 11:57inherent trade-off. On the top, we have
  312. 11:59our um our pre-scaler values from 0 to
  313. 12:0315. And then you have just in log here
  314. 12:06is the count on your counter. And so
  315. 12:09this is would be your uh uh period
  316. 12:12counter let's say. And so you can see
  317. 12:14that there are lots of different values.
  318. 12:16There's this inherent trade-off between
  319. 12:18uh the values you get. And then the
  320. 12:21trick here is that there just happens to
  321. 12:23be like a lot of duplicates. So why why
  322. 12:26don't you take you know so here I have a
  323. 12:28device that has lots of different
  324. 12:29duplicate values. So there's lots of
  325. 12:31different ways to get to these things.
  326. 12:33So why don't you take 60 seconds talks
  327. 12:35amongst yourself. Why would you make a
  328. 12:37device that has all this duplicated
  329. 12:38functionality?
  330. 12:41What are they trying to offer you?
  331. 12:58It's like
  332. 13:09[clears throat]
  333. 13:46All right. So why why have they made a
  334. 13:48device that has so much duplication? Why
  335. 13:50why not just give you one row?
  336. 14:00>> So in one case for instance on the left
  337. 14:02hand side getting the 655 you have many
  338. 14:05more values you have a higher
  339. 14:06granularity between um like zero and
  340. 14:10that number. If you're doing something
  341. 14:12like PWF and you wanted your period to
  342. 14:15be 55 you have a lot more choices for
  343. 14:19you to recycle
  344. 14:21whereas on the right hand side there
  345. 14:23it's very coarse like you know one step
  346. 14:26you value
  347. 14:28>> and what they what did they give you why
  348. 14:29why would they give you coarseness isn't
  349. 14:31seems like coarseness is always bad so
  350. 14:33what do you get out of this side of the
  351. 14:34of the chart
  352. 14:38>> well on the right hand side you can just
  353. 14:40count for much longer period of time
  354. 14:43there is like you want to count for 21
  355. 14:46seconds and you're going to have to
  356. 14:47expect that your step size is you know
  357. 14:50fairly
  358. 14:52small.
  359. 14:54>> Yep.
  360. 14:55And so kind of to that to your point
  361. 14:58about how long you can go the pre-scaler
  362. 15:00here is assuming this is all assuming
  363. 15:02that you have a a 100 mehz clock. Your
  364. 15:04input clock can be something different.
  365. 15:06Um but here the pre-scaler is telling
  366. 15:08you what's the longest thing you can
  367. 15:10measure. Right? This is before you
  368. 15:12overflow.
  369. 15:14So you want to choose a it doesn't
  370. 15:16matter what the period register is. You
  371. 15:18just cannot count longer than this.
  372. 15:20That's what that that's what that's
  373. 15:21saying, right?
  374. 15:25And then to the resolution question here
  375. 15:27underneath here, you get this is the
  376. 15:29resolution for each one of those period
  377. 15:31or each one of those pre-scaler values.
  378. 15:33This tells you what the resolution is
  379. 15:35for that input frequency. Um so here I
  380. 15:38can measure something. This entire row
  381. 15:40allows me to have the minimum step size
  382. 15:42of 1.8 8 microsconds. So that's the
  383. 15:44smallest interval of time I could
  384. 15:46measure. And so as I go this way, I can
  385. 15:49certainly go longer, but I get coarser
  386. 15:51just to that point.
  387. 15:55Everybody good with this?
  388. 15:58Okay.
  389. 16:01Um,
  390. 16:05okay.
  391. 16:07Um, so it's not, you know, I think it's
  392. 16:09just trying to understand that there is
  393. 16:10this trade-off. That's the big thing I
  394. 16:11want you to take away from this. Um,
  395. 16:14maybe I'll ask this. If you wanted to go
  396. 16:16longer than 21 seconds on your device,
  397. 16:19how would you do it?
  398. 16:21Right? Take 60 seconds and figure out
  399. 16:23some strategies for counting things that
  400. 16:25are longer than 21 seconds.
  401. 17:01>> [clears throat]
  402. 17:04>> I
  403. 17:14>> [clears throat]
  404. 17:30>> What do you think? How can we go longer
  405. 17:32than 21 seconds? Or is that the best we
  406. 17:34could do for our hardware?
  407. 17:39>> Oh, you got to speak loud.
  408. 17:45>> Yeah. Yeah.
  409. 17:57>> Yep. So, that is um that's the idea of a
  410. 17:59virtual counter. We used to teach this
  411. 18:01because it was a bigger part of 473, but
  412. 18:03now they've changed the curriculum and
  413. 18:05that's fine. So this idea of a virtual
  414. 18:07counter is that you could have in
  415. 18:08software the thing that's taking the
  416. 18:10interrupts and uh keeping track of time
  417. 18:13and you could set things like hey uh
  418. 18:16wake me up at this particular or at this
  419. 18:18particular time I have a value that I
  420. 18:20want you to go off and it keeps counting
  421. 18:21up to that uh time. What is what could
  422. 18:24be one challenge of having uh
  423. 18:26timekeeping in a uh IRQ or uh or in
  424. 18:32software?
  425. 18:34>> Sure.
  426. 18:43>> Well, what's the if I'm trying to let's
  427. 18:45say I'm trying to do something very
  428. 18:46precise, what's the problem with going
  429. 18:49uh doing everything with an uh
  430. 18:51interrupt?
  431. 18:58starts.
  432. 19:01>> Yeah. So we uh so there's some amount of
  433. 19:03time to get in and out of a interrupt.
  434. 19:06Uh and then but remember we already
  435. 19:08found out the interrupts aren't
  436. 19:09deterministic, right? You could be
  437. 19:10interrupted by something else. And so
  438. 19:12now you don't want to probably be down
  439. 19:14on the nanconds of timing trying to keep
  440. 19:17that level of time and not have that
  441. 19:20have the ambiguity of when did you
  442. 19:23actually update your virtual timer. So
  443. 19:26uh those sorts of timing events usually
  444. 19:28are longer human scale things. That's
  445. 19:30one way to think about it. Maybe 100
  446. 19:32milliseconds or so. Um or much longer
  447. 19:35than that. But like hours are usually
  448. 19:37minutes are usually what I would think
  449. 19:38about for a virtual timer. Any other
  450. 19:40ways people came up with for extending
  451. 19:43your time?
  452. 19:51>> You could use a wire wider counter.
  453. 19:52That's absolutely true. Um, it just so
  454. 19:56happens that your particular hardware
  455. 19:57has a trick we'll talk a little bit
  456. 19:59about later, but it will allow you to
  457. 20:01concatenate timers together in kind of a
  458. 20:03coarse way, but at least you can make
  459. 20:05effectively a 64-bit timer which would
  460. 20:07allow you to count things that are
  461. 20:08longer period of time. Um, but it's not
  462. 20:12uh yeah, we'll we'll see how that works
  463. 20:14uh when we get there. But um there are
  464. 20:16ways to concatenate things together, but
  465. 20:18usually you don't have much flexibility
  466. 20:19on your piece of hardware. It's whatever
  467. 20:20timer size you get.
  468. 20:23>> Okay.
  469. 20:24So, we'll go on to compare timers. Uh,
  470. 20:27so we talked about capture. Capture,
  471. 20:28we'll step back for a second. Capture
  472. 20:30was just the idea that some external
  473. 20:32event is going to cause the timer to
  474. 20:34start and then when another external
  475. 20:35event occurs, you're going to lock in
  476. 20:37the value of the time that's passed. So,
  477. 20:39that's typically uh a capture timer is
  478. 20:42like a stopwatch. That's how I think
  479. 20:44about it. Um, the compare timer, it's
  480. 20:46not that capture timers aren't used.
  481. 20:49It's just that uh especially for lab and
  482. 20:51a lot of things we do in the beginning
  483. 20:52of embedded systems uh the compare timer
  484. 20:55is the one you want to use because it's
  485. 20:57there to generate PWM waveforms or just
  486. 21:00to generate signals rather than measure
  487. 21:02signals external to the device. And so
  488. 21:04how this works is uh you have that same
  489. 21:07structure we saw above with the addition
  490. 21:09of a compare register. You're going to
  491. 21:11put a value in there and then when your
  492. 21:13counter hits that value, you're going to
  493. 21:15get an event occurs. And that event
  494. 21:17could be something that goes to uh
  495. 21:19interrupt. It could go to other logic on
  496. 21:22your device. You have PWM control logic
  497. 21:24that will cause uh signals to go high
  498. 21:26and low on certain modes and intervals.
  499. 21:29So this you just think about all that's
  500. 21:31happening is you're counting up with
  501. 21:32your timer until some value is hit and
  502. 21:35then an event is going to occur.
  503. 21:38And so how that manifests itself, we're
  504. 21:40back to the same thing. you have we're
  505. 21:42in the C compare register up there and
  506. 21:44then we have some value and we're just
  507. 21:46waiting to see when we hit that value.
  508. 21:48So here uh when it was uh you got to
  509. 21:52your period you overflowed and that
  510. 21:54caused the value to go low and then you
  511. 21:56went along you started counting up
  512. 21:57counting coming up and when your your um
  513. 22:00compare register value hit your counter
  514. 22:02value then the signal went high and the
  515. 22:04polarity of the signal going high or low
  516. 22:06really depends more on how you set up
  517. 22:08your module. That's not what's
  518. 22:10important. It's more important this that
  519. 22:11you have this other method of keeping
  520. 22:13track of this uh time. So now you can
  521. 22:16have your period can be independent of
  522. 22:18this other compare register that's
  523. 22:20happening. And this allows you to make
  524. 22:22uh pulse wave waveforms. And so if you
  525. 22:25reduce that time, the animation kind of
  526. 22:28sucks, but you can you can see here that
  527. 22:30you've changed the pulse width. And so
  528. 22:32now you're up for a longer period of
  529. 22:33time. The pulse width is larger. You
  530. 22:35could say the duty cycle is higher than
  531. 22:37it was when we were here. And all that
  532. 22:40what you really change is you just
  533. 22:42change some value in your CCR register
  534. 22:44or CR register. And so that's a way that
  535. 22:47from you kind of set your timer up and
  536. 22:49then you're just changing this one value
  537. 22:51to change like the dimness of your LEDs,
  538. 22:53the location of a servo or uh whatever
  539. 22:56other peripheral you have.
  540. 23:00Any questions?
  541. 23:04So you guys have questions for each
  542. 23:05other. I can half hear what you're
  543. 23:07saying and you're like, I don't
  544. 23:08understand anything. What does that
  545. 23:09mean? But then we don't have any
  546. 23:10questions for me.
  547. 23:16>> Yeah.
  548. 23:21>> Uh yeah. Yeah, you could say that. You
  549. 23:24could say um
  550. 23:28>> uh you can say more like it causes an
  551. 23:30event to occur and then the the bottom
  552. 23:33line is interpretation of that event.
  553. 23:35And so for this example, it would be
  554. 23:37greater than that. That's a fine
  555. 23:38example. But on your labs and in your uh
  556. 23:41sheets or your your device, you can say
  557. 23:44whether you want it to be greater than
  558. 23:45or less than.
  559. 23:52Okay.
  560. 23:56Uh and so uh let's see the example here
  561. 23:59is that now you will from embed systems
  562. 24:02point of view, you're able to control a
  563. 24:03waveform like this. You're setting the
  564. 24:05duty cycle. Duty cycle from 1 to 100 is
  565. 24:08just kind of arbitrary ways so that we
  566. 24:10can talk about different devices or
  567. 24:12different waveforms without worrying
  568. 24:14about how many micros secondsonds it's
  569. 24:15high or low. But here it's just showing
  570. 24:19that you can control this signal. And
  571. 24:21that's really important because remember
  572. 24:22microcontrollers are only good at
  573. 24:24measuring time. That's a you know not
  574. 24:26good at analog voltages. They're not
  575. 24:28good at current. They're not good at you
  576. 24:30know pressure or temperature. They're
  577. 24:32really good at measuring time. And so
  578. 24:34here you can control other devices or uh
  579. 24:37and you'll see in your one of the labs
  580. 24:39you're going to look at uh distance
  581. 24:41measurement. You can actually measure
  582. 24:42the pulse width to understand uh a
  583. 24:45distance measurement. So that's the goal
  584. 24:46is to to be able to generate these kind
  585. 24:48of waveforms. And what you'll see in lab
  586. 24:50this week is you will use a servo which
  587. 24:53we talked about earlier just to control
  588. 24:55its angle by encoding this pulse width
  589. 24:58that will go through. And you might say
  590. 25:00that's insane. Why not just use a
  591. 25:01digital port or something? Well, the
  592. 25:03digital port would need multiple wires
  593. 25:05to encode the digital information. This
  594. 25:07just makes it simple as a simple
  595. 25:08structure to control. Uh same with many
  596. 25:12motors. Uh DC motors um are easy to
  597. 25:15control with pulsewidth modulation. Uh
  598. 25:17making it it would be harder to do it
  599. 25:19with another method. All right. So any
  600. 25:22questions about timers in general?
  601. 25:33Okay. All right. So, we'll go through
  602. 25:36actually we'll save the example to the
  603. 25:38end, but we'll just kind of go through
  604. 25:40um some of the features uh maybe
  605. 25:43different features of the device that
  606. 25:45you're using. So, uh I partly wanted to
  607. 25:49show this off just so that you could
  608. 25:50understand the nomenclature because I
  609. 25:52found it a little confusing when I
  610. 25:53started off. So on your device you have
  611. 25:56the uh capture and compare units. You
  612. 25:58have capture compare unit 4. You have
  613. 26:00capture compare unit 8. Uh the CC4 CC4U
  614. 26:04or CCU4 is the primary one. The eight is
  615. 26:08really good for industrial automation.
  616. 26:11You might use it in your projects but
  617. 26:13probably not that important for the lab
  618. 26:15section. And how it's constructed is
  619. 26:17that there are four. So the nomenclature
  620. 26:21here is there have four modules in
  621. 26:22there. So uh CCU 441
  622. 26:2642 43 and so that is this whole thing is
  623. 26:29one module and then there's four of them
  624. 26:30there and so each of those modules has
  625. 26:34four timers. So overall you have uh 32
  626. 26:38timers
  627. 26:41and then so they call this thing here a
  628. 26:43slice
  629. 26:45and that slice is here and that in
  630. 26:47itself has four timers
  631. 26:51and uh now they gave you some more
  632. 26:53confusing nomenclature which each one is
  633. 26:55denoted CC4 and then y being the uh the
  634. 27:01uh slice. So that would be the uh one
  635. 27:04two three four up here and then the one
  636. 27:08zero one oh I missed that one. So be 0 1
  637. 27:102 3 is the instance on that particular
  638. 27:13slice. And so each slice has a 16- bit
  639. 27:16timer which is here. And that timer has
  640. 27:20uh or the whole module here sorry the
  641. 27:21module has uh four possible IRQs
  642. 27:25um has different logical units on it uh
  643. 27:28along or sorry four captures only one
  644. 27:31compare. So in here you can have uh four
  645. 27:34capture registers, one compare register
  646. 27:36and then each one can create an
  647. 27:37interrupt
  648. 27:39which is essentially what I wrote here.
  649. 27:41So 16- bit timer. Uh then the the trick
  650. 27:44here is that there's output logic as
  651. 27:45well. And so once you've created that
  652. 27:48event, then you get to decide if you
  653. 27:50want that event to be positive or
  654. 27:52negative. So that's essentially the
  655. 27:53logical greater than or equal to or or
  656. 27:56less than. Uh that can be routed to an
  657. 27:58external or internal device. it can be
  658. 28:01routed to um uh the core. So there's all
  659. 28:06this different compare logic and one of
  660. 28:08those output logics is the PWM generator
  661. 28:10which will set those pins high or low
  662. 28:13and then basically send it out to a GPO
  663. 28:15pin through the alternate function. So I
  664. 28:17think I might have said that a little
  665. 28:18bit backwards, but basically there's a
  666. 28:20unit. The unit has a module for modules.
  667. 28:24So units is the whole thing. This is a
  668. 28:27module here. There's another module
  669. 28:28behind it. module behind it, module
  670. 28:30behind it. And then on a module there's
  671. 28:32a slice. So this is a module. This is a
  672. 28:34slice and this is the example of that
  673. 28:36slice.
  674. 28:41Okay. The other trick for your
  675. 28:43particular devices
  676. 28:46is uh shadow registers. And so the goal
  677. 28:49here is that um they are concerned that
  678. 28:53if you updated a register
  679. 28:56out of sync that you would screw up your
  680. 28:59pulse width modulation. So imagine your
  681. 29:01core is doing whatever it's doing. It's
  682. 29:04you know wakes up in a super loop uh
  683. 29:06gets to a section of code where it's
  684. 29:08been told to update a um pulse with
  685. 29:11modulation value. Now the challenge here
  686. 29:14is if you just go right to that register
  687. 29:16you might change the the width of the
  688. 29:18pulse. You might do that in a really bad
  689. 29:20way. So if we go here
  690. 29:23uh so you might say if you go here to
  691. 29:27change like at this point in time if you
  692. 29:29go and change the pulse width you might
  693. 29:30come up with a very short pulse and that
  694. 29:32pulse could damage your electronics or
  695. 29:34be invalid in some way. And so to ensure
  696. 29:37that you're always uh aligning your
  697. 29:40updates at the correct time for that
  698. 29:42particular timer, they've added this
  699. 29:45idea of shadow registers.
  700. 29:48And so there's uh you only care about
  701. 29:50two shadow registers, but there are five
  702. 29:52shadow registers in general. And really,
  703. 29:54it's for the the period and the compare
  704. 29:57values. And so those shadow registers uh
  705. 30:01have a specific sequence to be updated.
  706. 30:03So you update the shadow register,
  707. 30:05sorry. And then there's a sequence for
  708. 30:06those shadow registers to take the
  709. 30:08values and put it into the actual update
  710. 30:11register. So you basically you load up
  711. 30:13your shadow registers, you send out a
  712. 30:15request that says on the next available
  713. 30:17uh interval then update those uh values
  714. 30:21such that it guarantees there's no
  715. 30:23pulses or or more weird uh events. And
  716. 30:27usually that would happen say on a
  717. 30:28period overflow or something. So now
  718. 30:30you're guaranteed that you're not
  719. 30:32messing up any of the values.
  720. 30:39What do we think? Does that sound like a
  721. 30:41good idea? Is that useful?
  722. 30:44You guys like talking to each other more
  723. 30:46than talking to me? So why don't you
  724. 30:47take 60 seconds and try to explain to
  725. 30:49your neighbor why in the world they
  726. 30:51would even need shadow registers or if
  727. 30:53this is even a problem.
  728. 31:36It seems
  729. 32:17All right. So, you had a chance to talk.
  730. 32:19What any questions arise or why anybody
  731. 32:22wonder why in the world we actually need
  732. 32:24these things?
  733. 32:29>> Yeah,
  734. 32:30>> I have questions.
  735. 32:31>> Yeah.
  736. 32:39Yeah,
  737. 32:46>> I'm sorry. Say that again.
  738. 33:00>> Ah.
  739. 33:04It's a fair question. So, it's not about
  740. 33:06being on the clock edge. It's being it's
  741. 33:09about being on the pulsewidth modulation
  742. 33:11edge,
  743. 33:13right? So, you're in the pulse with
  744. 33:15modulation. You don't want to
  745. 33:18uh let's see, go up here.
  746. 33:30So I can draw. So you don't want to say
  747. 33:33for instance change here,
  748. 33:36right? You say you change right here and
  749. 33:38now that could still be on the clock
  750. 33:40edge, perfectly on the clock edge, no
  751. 33:41problems, right? But that might cause
  752. 33:43this pulse to become very short and what
  753. 33:46you really meant to have happen is it
  754. 33:48just to
  755. 33:50uh I don't know like be here or
  756. 33:52something, right? So like that little
  757. 33:53glitch can occur. Does that make sense?
  758. 33:57Um maybe that's not the perfect example.
  759. 33:59Let me see if I can find a better think
  760. 34:00of a better example here.
  761. 34:05Maybe it would be more more of an
  762. 34:06example of a long pulse. So, say it was
  763. 34:09short.
  764. 34:10Um, say it did come down here and then
  765. 34:15you wanted to change it and you changed
  766. 34:17it over here.
  767. 34:20And so now what would happen if you
  768. 34:22change it to to rise up here, then it
  769. 34:23would come down and rise again up and
  770. 34:26then down. And now you have two pulses
  771. 34:28within that pulse period of time because
  772. 34:30you changed uh your uh boy that's really
  773. 34:33bad drawing but you uh changed your um
  774. 34:37CCR or compare register to push it back
  775. 34:40in time but now it's done two pulses.
  776. 34:43And so that's the sort of thing that
  777. 34:44they're trying to avoid. It's not about
  778. 34:46the clock edges, it's about the period.
  779. 34:51Any other questions? That's a good
  780. 34:53question.
  781. 34:56Yeah.
  782. 35:04>> 200, but then like a period gets
  783. 35:06changed.
  784. 35:08Where does the counter go?
  785. 35:10>> The counter is still going to keep
  786. 35:11going.
  787. 35:14>> No, the period is all it's saying is
  788. 35:16like are these values equal? So, so it
  789. 35:20you bring up a good point. So, say it
  790. 35:22was 200, right? And then you change it
  791. 35:25to 50, but the counter was in between
  792. 35:28those two values, then it's going to go
  793. 35:30in overflow. It's going to wait all that
  794. 35:31time to come back.
  795. 35:33>> Yeah. It just takes longer. Um, it just
  796. 35:36may not be the right thing. It may be an
  797. 35:37error function, right? That your motor
  798. 35:39is not designed to take that signal.
  799. 35:41>> So, it would allow that workflow.
  800. 35:44>> This would wait until the period had
  801. 35:47naturally changed and then it would
  802. 35:49clock it in. So there would be no period
  803. 35:52that was too short or too long.
  804. 35:57>> Yeah. Yeah.
  805. 36:08>> Yeah. I don't know exactly like you we
  806. 36:11can read the manual to see exactly all
  807. 36:13the conditions that can that cause the
  808. 36:15actual update to occur. One of them can
  809. 36:17be period if that's what you set in the
  810. 36:19control registers. Um but basically it's
  811. 36:21you set this global command you first
  812. 36:23you write in yourself and you write the
  813. 36:24this global command update on the next
  814. 36:26possible cycle or valid point.
  815. 36:30>> Yeah the rising edge
  816. 36:33>> uh you get to decide. I think you can
  817. 36:35look through the documentation and
  818. 36:37there's different conditions that you
  819. 36:38can set.
  820. 36:43I think it's the period is really the
  821. 36:45it's it depends how you have your pulse
  822. 36:47with set up if it's positive or negative
  823. 36:49right because you could design the same
  824. 36:51period or PWM and just invert the output
  825. 36:53and then you have you know it doesn't
  826. 36:55matter if it's rising or falling but
  827. 36:57it's really when the period resets
  828. 36:59that's the uh or gets loaded back into
  829. 37:01the counter that's the time when they're
  830. 37:02going to reset or sorry swap from the
  831. 37:04shadow registers to the uh actual
  832. 37:07registers
  833. 37:10okay maybe we'll get to that example
  834. 37:13Um,
  835. 37:17okay.
  836. 37:18So, now we'll move on to the cystic. So,
  837. 37:21ARM has
  838. 37:23uh defined that every microcontroller
  839. 37:26must come with a clock with a timer and
  840. 37:29they give you a 24-bit timer. So, this
  841. 37:32is just like how ARM says everything's
  842. 37:34got to have of a Envvic. Everything's
  843. 37:37got to have a basic bus structure so
  844. 37:39that you can get data from memory to um
  845. 37:42your core. And you know, ARM also lays
  846. 37:45out all the different uh memory regions.
  847. 37:48So they also say you have to have a
  848. 37:49basic 24-bit timer. Why would But
  849. 37:52interestingly, ARM does not say that you
  850. 37:54need to have a debugger.
  851. 37:57That's an optional function that ARM
  852. 37:59says you do not have to have debug and
  853. 38:00trace on your chip. But why maybe a
  854. 38:03question for you is why would the manu
  855. 38:05or arm as the company that sells the IP
  856. 38:08that some other company integrates into
  857. 38:11their circuit why would they care if
  858. 38:12there's a timer for uh as part of the
  859. 38:15mandatory part of their spec. So, take
  860. 38:1660 seconds. Uh, come up with an answer.
  861. 38:29[clears throat]
  862. 38:42>> [clears throat]
  863. 39:01>> Why do we think why would ARM mandate
  864. 39:04that there's a timer?
  865. 39:06And why is this timer treated
  866. 39:08differently than your peripheral timers
  867. 39:10that the man uh device manufacturers
  868. 39:12actually implement?
  869. 39:19>> Yeah.
  870. 39:24>> Oo. Okay. So, that's a good one. Part of
  871. 39:27uh what's built into ARM, which I didn't
  872. 39:29really preface here, is this idea of a
  873. 39:30watchdog timer. So a watchdog timer
  874. 39:33basically uh you usually have to disable
  875. 39:36it. Uh that might be part of just how
  876. 39:37lab the files that you do for a lab, but
  877. 39:40typically there's a watchdog timer that
  878. 39:42says if you don't write a value to this
  879. 39:43register or this memory address, then
  880. 39:45the device will reset, right? It'll just
  881. 39:48go through a power on reset. Why would
  882. 39:50you want that?
  883. 39:56>> Yeah, exactly. So what you find
  884. 39:58especially for like automotive and
  885. 39:59industrial applications is it's not just
  886. 40:01one or two people writing code. It is a
  887. 40:04team. It's a relatively complicated
  888. 40:06system. It might have even have like a
  889. 40:08real-time operating system. And there's
  890. 40:10always these little tricks or issues
  891. 40:12that can arise. Unexpected condition can
  892. 40:14get you to uh stall out, get stuck in a
  893. 40:17while loop or something. And so the
  894. 40:19watchdog timer is just a way to ensure
  895. 40:22that hey every I don't know 100
  896. 40:24milliseconds whatever you set it to you
  897. 40:25need to write to this memory location
  898. 40:27and just write a one or a zero and if
  899. 40:30you do that then it resets the watchdog
  900. 40:32timer which is a piece of hardware and
  901. 40:33this says uh hey if that doesn't happen
  902. 40:36I probably got hung some bad thing
  903. 40:38happened and it'll just force the device
  904. 40:39to reboot. So that's why you have a
  905. 40:40watchdog timer. Um that was a good
  906. 40:43example whoever came up with that one.
  907. 40:45any other reasons why they would want
  908. 40:46this?
  909. 40:48>> Yeah.
  910. 41:08>> So, I I think there's this idea of maybe
  911. 41:10I'm extending a little bit, but the
  912. 41:11interoperability, right? You have one
  913. 41:13device and then you want it to kind of
  914. 41:14operate the same as this other device.
  915. 41:16So, we need to have a timer that is
  916. 41:18flexible to that clock speed. Is that
  917. 41:19what you're kind of thinking?
  918. 41:27>> Well, that's actually Oh, that's also a
  919. 41:29slightly different idea. That's a good
  920. 41:30idea. So now you're saying this one
  921. 41:32since it's built into the core, its
  922. 41:35timer is based on the core function, it
  923. 41:36doesn't even need a pre-scale, all those
  924. 41:38other things and it's not over, you
  925. 41:40know, far away as a peripheral over the
  926. 41:42advanced peripheral bus and high
  927. 41:44performance bus, right? It's really
  928. 41:45close. Okay, so it's a it's a timer that
  929. 41:49for the core itself, for the processor.
  930. 41:51That's true. Anything else? Any other
  931. 41:53ideas why ARM wants this?
  932. 42:02>> Yeah.
  933. 42:10>> Yeah. So what you often that's that I
  934. 42:12think you guys have all figured out all
  935. 42:13the reasons. I even forgot about
  936. 42:15watchdog timer. So but it's really about
  937. 42:17this interoperability. So ARM's thinking
  938. 42:19this not as a when you guys are
  939. 42:22programming typically you're at the
  940. 42:23lowest level you're like can I get
  941. 42:25anything to work can I get this
  942. 42:26peripheral to turn on right and then
  943. 42:29send data back and forth and then
  944. 42:30usually a step above that is you're
  945. 42:32going to run uh you know some sort of
  946. 42:34real-time operating system or something
  947. 42:36and that's really where ARM's thinking
  948. 42:38they want they want devices that are
  949. 42:40interoperable that uh one program can
  950. 42:42work on and and you can hand it off to
  951. 42:44or sorry one a program work on one
  952. 42:46device and you can transfer it to
  953. 42:47another device. And so the goal of cycic
  954. 42:50is to be the processor uh or the timer
  955. 42:53for the core while the peripherals has
  956. 42:55timers for specific functions uh that
  957. 42:58are like related to things outside the
  958. 43:00chip. Uh and that kind of gets to the
  959. 43:02par programming paradigm. So most of
  960. 43:04what you guys have done in lab and I
  961. 43:06think almost every one of your projects
  962. 43:07is going to be this idea of a super
  963. 43:09loop. And a super loop is simply just a
  964. 43:12loop that comes in. You have some setup
  965. 43:14code, right? You're going to initialize
  966. 43:16a bunch of stuff and then you're going
  967. 43:17to go into this looping structure. And I
  968. 43:19never heard the word the phrase super
  969. 43:22loop until I came here. We always used
  970. 43:24to call it a while one. Basically, you
  971. 43:26go into a loop that keeps spinning and
  972. 43:28you've just defined it to be a while
  973. 43:30with a boolean one. Um, and so you're
  974. 43:33just going to go around and you have
  975. 43:34different tasks. One of the tasks could
  976. 43:35be measure the temperature sensor,
  977. 43:37update the screen, look for buttons, and
  978. 43:39you're just going to go through that.
  979. 43:40And that works really well if your tasks
  980. 43:43are generally short and they're
  981. 43:45deterministic. So if they take a really
  982. 43:48long time or could be blocking then uh
  983. 43:50that would be a problem. Uh so just on
  984. 43:53your own projects you want to keep those
  985. 43:55relatively relatively short um and
  986. 43:59deterministic. You don't want them
  987. 44:01fluctuating a lot in time. And then the
  988. 44:04way you get some some flexibilities you
  989. 44:07have already learned about interrupts.
  990. 44:08So now you can use your uh interrupt sub
  991. 44:10routines and typically those will
  992. 44:12interrupt of course your tasks but
  993. 44:14you're not doing a lot of work in there.
  994. 44:16Typically what you'll do is you'll have
  995. 44:17an interrupt interrupt will go off and
  996. 44:18maybe it's something simple like um it
  997. 44:21doesn't involve the main loop where
  998. 44:22you're saying take data from one
  999. 44:24location and put it somewhere else. So
  1000. 44:26your ADC goes off saying that the
  1001. 44:28conversion is done and then you just
  1002. 44:30push it in memory and that's a short
  1003. 44:32thing. It can all live in there. But
  1004. 44:33sometimes you'll have events like hey my
  1005. 44:36um I squared C my communication bus is
  1006. 44:39full and then you just set a flag and
  1007. 44:42then when you're going through your task
  1008. 44:43you'll say okay task two was to check my
  1009. 44:46I squared C bus and then you'll pull the
  1010. 44:48data out of that register. So uh that is
  1011. 44:50one way and probably most the way that
  1012. 44:52you guys will use your programs uh your
  1013. 44:55projects. The the alternate way is what
  1014. 44:57they call a real-time operating system.
  1015. 44:59Um this is mostly what you'll learn in
  1016. 45:03uh 473 and this is where cycic is really
  1017. 45:05important. So a cystic is this timer
  1018. 45:07that the real-time operating system can
  1019. 45:09do and it's really just a scheduleuler
  1020. 45:11you have set up and then each task is
  1021. 45:12effectively its own super loop and it
  1022. 45:15goes through each one and then the the
  1023. 45:16timer uh or the the controller here is
  1024. 45:19selecting which of these uh tasks has
  1025. 45:21the highest priority. That's kind of
  1026. 45:23like your interrupts uh that you set up.
  1027. 45:25So here a task will have different
  1028. 45:26priorities and then they'll get a queue
  1029. 45:28and then it'll go through and allocate
  1030. 45:29time for each one of those to complete
  1031. 45:32its task. Um again it's beyond what
  1032. 45:34we're trying to do here but uh just good
  1033. 45:36to know that this is u kind of the next
  1034. 45:39step beyond this class is real-time
  1035. 45:41operating systems and that's why mostly
  1036. 45:43you have a timer.
  1037. 45:45Um another useful thing uh
  1038. 45:49yeah so another useful idea here is that
  1039. 45:52uh you can use it to measure the passage
  1040. 45:54of time but I think in your own uh
  1041. 45:56projects uh using the timer is a great
  1042. 45:58way to provide structure to your code.
  1043. 46:00So now you can say run your while loop
  1044. 46:02every 50 milliseconds or something and
  1045. 46:04now you're guaranteed that this thing
  1046. 46:06will run on a deterministic time frame.
  1047. 46:08That's very nice compared to say uh just
  1048. 46:11run whenever you get down to the bottom
  1049. 46:13of the loop and now you could have tasks
  1050. 46:15that don't occur and then you you maybe
  1051. 46:17have varying amounts of uh sensor data
  1052. 46:20or some other event you assumed you're
  1053. 46:21going to have a buffer full but because
  1054. 46:23other tasks ended early you don't or
  1055. 46:26maybe task go really long time. So uh
  1056. 46:28having some set time structure for how
  1057. 46:31often your loop goes is a a valuable uh
  1058. 46:34modality.
  1059. 46:37So here you have uh this is just your uh
  1060. 46:40ARM core processor architecture here and
  1061. 46:43ARM built into their idees just says you
  1062. 46:45have this C function that must exist in
  1063. 46:48all the compilers and all the workflows
  1064. 46:50that you have a uh C function that'll
  1065. 46:52give you back this time and you can set
  1066. 46:54delays and those other things. So how it
  1067. 46:57oops so how it generally works there's a
  1068. 46:5924-bit dime counter with a with a
  1069. 47:01reload. You can set that reload value
  1070. 47:04and just like all your other ones, uh it
  1071. 47:06will count away. Basically, have you hit
  1072. 47:08this? Yes or no? There's no pre-scaler.
  1073. 47:10It Oh, there's a divide by 8 pre-scaler
  1074. 47:12on some of them. Uh this always
  1075. 47:14countdown. Uh and then it reloads and
  1076. 47:16then some interrupt or some cy tick can
  1077. 47:18go off. Uh and then it defines a bunch
  1078. 47:22of predefined values that you can uh oh
  1079. 47:25wait, did I miss one? Uh no. Uh so the
  1080. 47:28cyic register structure very basic. You
  1081. 47:31can uh set a count flag. You can set
  1082. 47:32your cystic flags. You get some control
  1083. 47:34bits to enable to define your clock
  1084. 47:37source whether you're dividing by eight
  1085. 47:38or not. That is all you get out of this,
  1086. 47:41but you don't really need a lot more for
  1087. 47:44most basic functions. There are two
  1088. 47:46special little a few special little
  1089. 47:48features here. Uh you have your reload
  1090. 47:50value, you have your current value, and
  1091. 47:53then you have your calibration value.
  1092. 47:54And this is where they're trying to get
  1093. 47:56they're trying to calibrate between
  1094. 47:58different processor types so that a
  1095. 48:01program runs and a programmer is trying
  1096. 48:03to say I always want a certain delay
  1097. 48:05that there's some way to guarantee that
  1098. 48:07this delay is constant because some
  1099. 48:09device could be running at a faster
  1100. 48:11clock speed. Um and it could just be
  1101. 48:13that the manufacturer has
  1102. 48:16um chosen say you know 96 MHz as the
  1103. 48:20clock speed or another one is 144 MHz
  1104. 48:23and they wanted some way to allow some
  1105. 48:25uniformity between them and so the
  1106. 48:27calibration uh timer here provides the
  1107. 48:31uh value that will give you uh a known
  1108. 48:34delay offset and usually it's like 50
  1109. 48:36milliseconds or 100 milliseconds. You
  1110. 48:37can read through the documentation. So
  1111. 48:39that's the value in there that will
  1112. 48:41cause uh that known delay to occur.
  1113. 48:46Um yes. Okay.
  1114. 48:53Yeah. Anyway, so you can read through
  1115. 48:55the I mean that's just a re uh
  1116. 48:56discussion of what we already talked
  1117. 48:58about. And so that is about all I want
  1118. 49:00to talk about with timers. We can either
  1119. 49:02go through example of just thinking
  1120. 49:04through how to set up pulsewidth
  1121. 49:06modulation and um
  1122. 49:10uh period values or we can move on to
  1123. 49:13serial. What would you guys prefer?
  1124. 49:16>> Yeah.
  1125. 49:17>> You want example? Example. Okay.
  1126. 49:22Let's do it.
  1127. 49:25Okay. So, let's say Oh, no builds. Cool.
  1128. 49:29No. All builds. No builds. All right.
  1129. 49:32So, you have half the answers here, but
  1130. 49:33let's just go through an example. Say we
  1131. 49:35have some laser driver that you want to
  1132. 49:37have. You're given a clock driver at 100
  1133. 49:41uh megahertz, and you want the you want
  1134. 49:44a pulse to come out every 200 hertz. So,
  1135. 49:46fairly pulse, fairly slow pulse. And
  1136. 49:49here you have uh a pulse width you're
  1137. 49:52trying to uh hit. So, you're trying to
  1138. 49:54say uh you want it to be between 100 and
  1139. 49:57100 or and 10 microsconds. So I often
  1140. 50:00think is I first thing I usually do is
  1141. 50:02just try and think through what is the
  1142. 50:04shape I'm trying to get. So this to me
  1143. 50:06would be I'm trying to get a shape that
  1144. 50:08looks like this, right? It's fairly long
  1145. 50:11over here. And then I have to I can do
  1146. 50:14this.
  1147. 50:17And so the the shape I'm trying to make
  1148. 50:19is I'm trying to get 100 here or
  1149. 50:21actually is that no 10 microsconds pulse
  1150. 50:23width high here.
  1151. 50:26micro seconds and then the longest one
  1152. 50:30would be from here to here. I guess that
  1153. 50:32would be here.
  1154. 50:34And I'm trying to get 100 microcond. So
  1155. 50:37clearly not to scale. So that's my goal.
  1156. 50:40I'm trying to make a pulse twist that's
  1157. 50:42uh short or a little bit longer. And
  1158. 50:44then uh way over here in time, I need
  1159. 50:47this pulse to come back up high. Does
  1160. 50:49that make sense? And so when they say
  1161. 50:51the pulse rate is 100 hertz that means
  1162. 50:53or 200 hertz that means from here to
  1163. 50:56here is one over 200
  1164. 51:01hertz.
  1165. 51:04What? Yeah.
  1166. 51:07Oh my god, it's horrible. All right. And
  1167. 51:09then you get a 10 uh or 16 bit timer.
  1168. 51:12And then the other piece of information
  1169. 51:14here is they want the resolution.
  1170. 51:15Meaning the minimum step size you could
  1171. 51:18go between when you're going between 10
  1172. 51:21microsconds and 100 microsconds. The
  1173. 51:23minimum step size needs to be 10 nonds.
  1174. 51:26So why don't you talk amongst yourselves
  1175. 51:28for a second and see if if you have any
  1176. 51:30questions about the setup of this
  1177. 51:31problem and the setup of that waveform
  1178. 51:33of what you're trying to um make.
  1179. 51:48Yep.
  1180. 51:58>> Hold on one second. Let everybody can
  1181. 52:00talk talk amongst themselves for a
  1182. 52:02second. Then we can ask questions.
  1183. 52:14All right. So, you had a chance to talk.
  1184. 52:16What's your question?
  1185. 52:19>> Yeah.
  1186. 52:20I was wondering whether or not
  1187. 52:26>> the the the design spec is you need to
  1188. 52:29make a pulse that's between so uh yeah
  1189. 52:31it's anywhere between 10 microsconds
  1190. 52:33long and 100 microsconds long and you
  1191. 52:35need to have resolution. So you're
  1192. 52:36shooting this laser out and you need
  1193. 52:38control over it to control between
  1194. 52:40there. It's not that you can choose any
  1195. 52:42value. It's that you need to be able to
  1196. 52:43control it between those two boundaries
  1197. 52:46within these number of steps.
  1198. 52:51Is that was that your question as well?
  1199. 52:53Okay. Any other questions about the
  1200. 52:54setup?
  1201. 52:58>> All right. So, yeah.
  1202. 53:06>> So, I'm saying so I said the first step
  1203. 53:08was going to go through choose a
  1204. 53:09pre-scaler. So, these were supposed to
  1205. 53:10be builds and I was going to ask you and
  1206. 53:12then you already saw them. It said it's
  1207. 53:13the matter. But, uh, so let's say we're
  1208. 53:15going to choose a pre-scaler. So,
  1209. 53:16there's two problems with a prescaler. I
  1210. 53:18got to be able to choose a pre-scale. If
  1211. 53:20we go all the way back here,
  1212. 53:23right? If I go back to this trade-off, I
  1213. 53:25need to be count able to count long
  1214. 53:27enough in time to get to my period
  1215. 53:29because this laser can only shoot two uh
  1216. 53:31one over 200 hertz, right? That's the
  1217. 53:34longest period of time it can go for.
  1218. 53:37But I also have to hit a particular
  1219. 53:38resolution that you need to hit, right?
  1220. 53:41I got to hit both of these things. So
  1221. 53:42there's not it could be that there are
  1222. 53:44lots of solutions, but I'm going to say
  1223. 53:45that there's only a few solutions that
  1224. 53:47could probably work. And I think there's
  1225. 53:48only one solution that can possibly work
  1226. 53:49for this problem.
  1227. 53:52All right. So, how would we figure that
  1228. 53:53out? Come back.
  1229. 53:57So, I'm saying the first we can go
  1230. 54:00figure out the period that we're want to
  1231. 54:01get. So, one over 200 is 5 milliseconds.
  1232. 54:04Okay. And I need to be able to uh count
  1233. 54:08up. So, in 5 milliseconds, I need to
  1234. 54:11have this many steps. So, I have 5
  1235. 54:12milliseconds and I I have to at least
  1236. 54:14So, why did I choose that number? So
  1237. 54:15that's 2 to the 16, right? So like if I
  1238. 54:18have uh that's my period I'm trying to
  1239. 54:21get and this is the number of steps.
  1240. 54:22This would have to be the minimum size
  1241. 54:25of the tick that's necessary, right? So
  1242. 54:27if I have a tick that's uh shorter than
  1243. 54:30that, no, if I have a tick that is,
  1244. 54:32let's see, if I have a tick that is
  1245. 54:35shorter, if I have a tick that's longer,
  1246. 54:37then I can't meet my period of time,
  1247. 54:39right? Okay. And so now we're saying,
  1248. 54:42okay, this is about where I would have
  1249. 54:44to be. And then I can go over and say
  1250. 54:46okay now I have a resolution that's the
  1251. 54:48other axis here have a resolution
  1252. 54:49problem I need to get around um uh 10 I
  1253. 54:54have to be less than 10 nonds so here we
  1254. 54:57can go look at some values I got so the
  1255. 54:59the clock coming in uh is that many
  1256. 55:03nanconds that's the step size and then
  1257. 55:05I'm going to say here's the resolution
  1258. 55:07and I can choose my pre-scaler here so I
  1259. 55:09have 10 nconds times time 8 equals 80
  1260. 55:12nconds so that's the the smallest If I
  1261. 55:14use a pre-scaler that's effectively
  1262. 55:16eight, then that's the smallest period
  1263. 55:19of time I can measure. That's okay. But
  1264. 55:22here it would be too long. So if I do
  1265. 55:24the next double over, it would be too
  1266. 55:25long. Does that make sense?
  1267. 55:32Yes.
  1268. 55:34Do you want to talk to each other?
  1269. 55:39I think you need to talk to each other.
  1270. 55:40Explain figure out what's wrong with
  1271. 55:42this and then come and ask questions.
  1272. 55:47Convince yourself either this is right
  1273. 55:48or wrong and then ask me a question.
  1274. 55:50Talk to your neighbor.
  1275. 56:34We should get a visit. All
  1276. 56:46>> [clears throat]
  1277. 56:57>> right. What do we think?
  1278. 57:00What questions do you have?
  1279. 57:09No questions. 100% makes sense. Okay.
  1280. 57:13>> Yeah.
  1281. 57:24Well, it's more like I h if I'm any
  1282. 57:26smaller than that, if my my sorry, I
  1283. 57:29should maybe that was confusing. If it's
  1284. 57:30smaller than that, then I'll never get
  1285. 57:32to that period, right? So, if this
  1286. 57:34number was really really small, then I
  1287. 57:37can't count long enough possibly. So,
  1288. 57:40it's got to be at least this big,
  1289. 57:43right? And then over here, we're saying,
  1290. 57:44well, okay, uh, I just choose chose two
  1291. 57:47values. I could we could have exhaustly
  1292. 57:49gone through each value. that that would
  1293. 57:50have been fine. But I said, "Okay, well
  1294. 57:53eight works, but like what if I doubled
  1295. 57:55again? I could get to 16, right? Uh but
  1296. 57:58that's too long. That doesn't hit my
  1297. 58:00resolution requirement." So maybe we can
  1298. 58:02go look at maybe it's on the table.
  1299. 58:05Let's see.
  1300. 58:08Uh so here um what's the longest at 8
  1301. 58:13nano 80 nonds? What's the longest period
  1302. 58:15of time that I can measure with a
  1303. 58:18pre-scaler of it just happens to be 100
  1304. 58:20megahertz the same. So pre-scaler of
  1305. 58:24two. So two to four. Oh, I can't
  1306. 58:26actually do math in my head. So I would
  1307. 58:28need to have the three will get me to 5
  1308. 58:31milliseconds. A little bit longer,
  1309. 58:32right? And remember that's n or two to
  1310. 58:35the n. So a pre-scaler value of three
  1311. 58:38will get me to 5.2 two um nanconds be or
  1312. 58:44milliseconds before I overflow, right?
  1313. 58:47Because if I overflow then I'm done. So
  1314. 58:49I can't do two. Two would be too short
  1315. 58:50and four well four is okay. That will
  1316. 58:54get me I'll definitely be able to count
  1317. 58:55long enough but then I come back over
  1318. 58:57here to four which is here. But now my
  1319. 58:59resolution is too small. So really I've
  1320. 59:02boxed you in. I made the problem so
  1321. 59:04there's only one particular solution you
  1322. 59:06were able to get. And this can be
  1323. 59:07painful because you can go down a false
  1324. 59:10alley if you're not kind of careful. So,
  1325. 59:12of course, I did the problem beforehand.
  1326. 59:13So, I can, you know, make sure
  1327. 59:15everything works, but um you could start
  1328. 59:19choosing a value that was like here and
  1329. 59:21then you do all your math and then you
  1330. 59:22figure out later on that you can't
  1331. 59:24possibly have your uh counter count up
  1332. 59:27to 5 milliseconds for the end of your
  1333. 59:29period.
  1334. 59:37All right. All right. So now we've we've
  1335. 59:39figured out what our pre-scaler is.
  1336. 59:42Right. Uh let's see. So next let's find
  1337. 59:45the value that should go in our period
  1338. 59:48period register. So here we're saying
  1339. 59:50that the number of ticks that we have to
  1340. 59:52do is 8 milliseconds over 80
  1341. 59:55milliseconds or nanconds which is a
  1342. 59:58value numerical value that 8 millisecond
  1343. 1:00:02or sorry 5 milliseconds divided by 80
  1344. 1:00:04turns into this value here. And so
  1345. 1:00:06that's how long my counter has to count
  1346. 1:00:09up. Um and we saw that before because
  1347. 1:00:12the counter only goes to 5.2
  1348. 1:00:13milliseconds at these settings. So it's
  1349. 1:00:15very close to the top of the register.
  1350. 1:00:17So at least that makes sense. And then
  1351. 1:00:19we're going to trick you because uh your
  1352. 1:00:21period registers uh has to be minus one.
  1353. 1:00:24There's always that plus one because you
  1354. 1:00:25you have to count zero. So there's the
  1355. 1:00:28the value for the period register.
  1356. 1:00:32How's that feel?
  1357. 1:00:35So if we go back to do we have our
  1358. 1:00:37ustrious No, our diagram got er Oh, no.
  1359. 1:00:39Our diagram's still there. So now we
  1360. 1:00:41figured out how long what the value is
  1361. 1:00:44for for this thing for the pulse of the
  1362. 1:00:45period or for the pulse of the laser to
  1363. 1:00:47go again. So we know what that value is
  1364. 1:00:49and now we're going to try and figure
  1365. 1:00:50out and we know what the resolution is.
  1366. 1:00:52Now we're going to try and figure out
  1367. 1:00:53the values that would correspond to 10
  1368. 1:00:55microsconds and 100 microsconds.
  1369. 1:01:03All right. Oh, it says it says the wrong
  1370. 1:01:06thing.
  1371. 1:01:08Oh,
  1372. 1:01:11so that should be here.
  1373. 1:01:19Okay. And so that's a relatively
  1374. 1:01:22straightforward calculation in the sense
  1375. 1:01:23that we know what our pre-scaled clock
  1376. 1:01:25is going to be. So the period of our
  1377. 1:01:27pre-scale clock is 80 ns. We saw that
  1378. 1:01:30before. And now we have to figure out
  1379. 1:01:31our target time. Well, how many times
  1380. 1:01:34does 10 microsconds get divided by go
  1381. 1:01:36into or eight 80 nconds go into a 10
  1382. 1:01:39microsconds? Well, it's 25. So, that's
  1383. 1:01:42how many times uh is counted up until
  1384. 1:01:45some event should occur. And that's when
  1385. 1:01:47the beginning of that pulse should uh I
  1386. 1:01:49guess if it's already on should fall uh
  1387. 1:01:51stop when you're going to uh 10
  1388. 1:01:53microsconds and then you can do the
  1389. 1:01:55opposite one where if you wanted the
  1390. 1:01:57pulse to go longer, right? And so I
  1391. 1:02:00should have explained this. Uh you are
  1392. 1:02:02have to set a certain pulse rate and
  1393. 1:02:03then you get to change the width which
  1394. 1:02:05is changing how much power goes to uh
  1395. 1:02:08the the target and then maybe like the
  1396. 1:02:10uh 200 uh uh hertz is really to make
  1397. 1:02:14sure the machine doesn't overheat. So
  1398. 1:02:16here you're saying at the other end this
  1399. 1:02:19is the value the CCR has to go all the
  1400. 1:02:21way up to that because two 100
  1401. 1:02:23microsconds can be divided by 80 ns
  1402. 1:02:261,250 times. And so those would be the
  1403. 1:02:29two ranges and then uh you could scroll
  1404. 1:02:33in between those with that uh 10 nancond
  1405. 1:02:36or 100 ncond precision uh so that you or
  1406. 1:02:40greater than 100 ncond precision so that
  1407. 1:02:42you could provide little steps of power
  1408. 1:02:43that were uh more fine.
  1409. 1:02:47So any questions?
  1410. 1:02:54You guys ready to do it in lab? No
  1411. 1:02:55problem.
  1412. 1:02:58homeworks like yes,
  1413. 1:03:01no exams. You're saying no, we don't
  1414. 1:03:03want exams anymore.
  1415. 1:03:05Okay.
  1416. 1:03:07Uh let's see.
  1417. 1:03:12All right. Well, I think we Well, I'll
  1418. 1:03:14start uh we'll take what a few second
  1419. 1:03:16break. We started ended a little early.
  1420. 1:03:18And I'll start um uh serial buses then.
  1421. 1:03:23Okay.
  1422. 1:03:51All right, we'll do we'll spend like
  1423. 1:03:53five minutes doing a quick uh overview
  1424. 1:03:55of serial buses just to get you primed
  1425. 1:03:57for next week or Wednesday's lecture. Uh
  1426. 1:04:00but we won't go in too deep. All right.
  1427. 1:04:02So this entire
  1428. 1:04:04uh next section is all about how do
  1429. 1:04:07devices communicate with each other.
  1430. 1:04:09This is off device. So this is your PCB.
  1431. 1:04:11So you have your on your chip, right?
  1432. 1:04:13You have uh the advanced peripheral bus.
  1433. 1:04:16And that was all about how modules on
  1434. 1:04:18your chip communicate. And this is how
  1435. 1:04:20do modules off your device communicate?
  1436. 1:04:23So uh from one chip to another one on a
  1437. 1:04:26PCB. So we're going to talk about ways
  1438. 1:04:28to think about serus architectures in
  1439. 1:04:30general and then we'll talk about uh
  1440. 1:04:32three specific architectures that are
  1441. 1:04:34commonly used everywhere.
  1442. 1:04:38All right.
  1443. 1:04:40And so communication buses. So as
  1444. 1:04:42described oh uh I guess I just gave this
  1445. 1:04:45away but uh we're talking about
  1446. 1:04:47devicetodevice communication. Uh so some
  1447. 1:04:50of that includes trying to get off a
  1448. 1:04:52device, but really here uh this is like
  1449. 1:04:54a little microcontroller here and then
  1450. 1:04:56they have this little chip that will
  1451. 1:04:57talk USB and so this chip will help. And
  1452. 1:05:00then these two talk through a protocol
  1453. 1:05:02called UART. You also have these devices
  1454. 1:05:04over here. Um that's a parallel bus,
  1455. 1:05:07right? So they're talking to
  1456. 1:05:09memory cards or video cards similarly.
  1457. 1:05:12So when you're thinking about uh buses,
  1458. 1:05:14we got to think about how's the wiring.
  1459. 1:05:16Is it serial or parallel?
  1460. 1:05:19What's the bus speed? Are we going fast
  1461. 1:05:22or slow? Is it bytes, words, or words
  1462. 1:05:24per second? We have terminologies like
  1463. 1:05:26synchronous and asynchronous. And then
  1464. 1:05:29um another big consideration, are we
  1465. 1:05:31just talking to one other device? Are we
  1466. 1:05:33talking to end devices? And if we're
  1467. 1:05:34talking to end devices, who gets to
  1468. 1:05:36control who talks first? Is it that uh
  1469. 1:05:40there's only one master that's
  1470. 1:05:41designating when other uh devices can
  1471. 1:05:44talk like the advanced peripheral bridge
  1472. 1:05:46or is it that there is decentralized and
  1473. 1:05:48it's more of a mesh network even on
  1474. 1:05:50device where multiple devices can choose
  1475. 1:05:52when to talk and that's I guess that's
  1476. 1:05:55really getting down to arbitration but
  1477. 1:05:57the number of devices is really like is
  1478. 1:05:59it just one to two or is it one to to n
  1479. 1:06:02and then we get to the protocol level
  1480. 1:06:05we're saying how is the data encoded
  1481. 1:06:08Um so is the data you know the simplest
  1482. 1:06:11one would be most significant bit least
  1483. 1:06:13significant bit first which one is that
  1484. 1:06:15but then there's uh extra protocol on
  1485. 1:06:17top that that could be like is there a
  1486. 1:06:19header is there uh CRC is there any uh
  1487. 1:06:22ability for redundancy where the packet
  1488. 1:06:26of data itself encodes if there was an
  1489. 1:06:28error involved right so you could have
  1490. 1:06:30uh one or n bits that could help uh
  1491. 1:06:34detect errors in the in data data
  1492. 1:06:36transfer there.
  1493. 1:06:38And so we're talking about bus
  1494. 1:06:40topologies. We already talked about
  1495. 1:06:42parallel. So parallel is uh nice in the
  1496. 1:06:46sense that uh it's very fast. You get
  1497. 1:06:49lots of uh you can get a whole word or a
  1498. 1:06:52bite across in one clock cycle.
  1499. 1:06:56Uh is more expensive in terms of pins
  1500. 1:06:58and more expensive in terms of wiring.
  1501. 1:07:00But there examples are usually reserved
  1502. 1:07:03for really fast things. So PCI Express,
  1503. 1:07:05Compact Flash, those sorts of things.
  1504. 1:07:08And so here's this example of, you know,
  1505. 1:07:11parallel buses. So this is a processor
  1506. 1:07:13that's running out all these parallel
  1507. 1:07:15lines out to these uh sodium packages
  1508. 1:07:18here so that they can have high
  1509. 1:07:19bandwidth transfer.
  1510. 1:07:24What why what's the downside of having
  1511. 1:07:27parallel buses? Does anybody remember
  1512. 1:07:29why why would you not want to have a
  1513. 1:07:31parallel bus if you could avoid it when
  1514. 1:07:33you're trying to get devices off chip?
  1515. 1:07:37>> Yep. I still when I was undergrad, I
  1516. 1:07:40still didn't believe it. My professors
  1517. 1:07:42would say, "Wait a second. We're bound
  1518. 1:07:44by pins. I just cannot get enough IO off
  1519. 1:07:46this thing." And I was like, "How could
  1520. 1:07:47that possibly be?" Um, it just happens
  1521. 1:07:50to be that like physically there's just
  1522. 1:07:52not enough space. And sometimes now they
  1523. 1:07:54have chips where they actually put it's
  1524. 1:07:55not just on the edges, they put a whole
  1525. 1:07:58array of um pins just over the entire
  1526. 1:08:01top and it's still not enough. And so
  1527. 1:08:03they really are bound by how much data
  1528. 1:08:06they can get on and off device by the
  1529. 1:08:08physical location of pins. How many pins
  1530. 1:08:11can they put on that piece of silicon?
  1531. 1:08:12It is a driving bottleneck of the
  1532. 1:08:15industry and there's no physical way out
  1533. 1:08:17of it. this mostly because uh you can
  1534. 1:08:20the mechanics of trying to get an IO
  1535. 1:08:23like a a bond wire off your piece of
  1536. 1:08:25silicon off device. It just takes up
  1537. 1:08:27enough area that you can't put a lot in.
  1538. 1:08:30So that remains a significant challenge.
  1539. 1:08:35The counter example is serial. So serial
  1540. 1:08:38is uh one uh bite per clock cycle as
  1541. 1:08:42compared to parallel which is multiple
  1542. 1:08:44or multiple bits per clock cycle where
  1543. 1:08:46this is one bit per clock cycle. And the
  1544. 1:08:49nice thing here is that you don't have
  1545. 1:08:51to have lots of pins. You just have one
  1546. 1:08:53pin for data. Now you're still going to
  1547. 1:08:55probably have to have a clock in these
  1548. 1:08:56other devices but um it is very uh
  1549. 1:09:00compact. you do need some form of
  1550. 1:09:02synchronization so that this thing knows
  1551. 1:09:04when to clock in data and in fact
  1552. 1:09:06parallel does as well
  1553. 1:09:09and so you're going to need extra wires.
  1554. 1:09:11Sometimes you need extra wires for
  1555. 1:09:12handshaking and all those other things.
  1556. 1:09:14It's inexpensive in terms of connections
  1557. 1:09:16which is good. It's also particularly
  1558. 1:09:18good for long distances. Uh and this
  1559. 1:09:20might not be obvious but if you have a
  1560. 1:09:22really long cable uh the propagation
  1561. 1:09:24delay through it is not the same for
  1562. 1:09:29every bit structure. So if a 8 bit
  1563. 1:09:31parallel bus or I don't know 32-bit
  1564. 1:09:34parallel bus and you're sending across a
  1565. 1:09:36a set of wires, different
  1566. 1:09:39um bits can have different propagation
  1567. 1:09:41delays. So some some bits are like all
  1568. 1:09:44zeros versus one 0 1 0. They will
  1569. 1:09:46actually propagate at different rates
  1570. 1:09:48which seems counterintuitive but it just
  1571. 1:09:50means that it's much more complex to go
  1572. 1:09:52long distances. And this is more from an
  1573. 1:09:54ENM point of view where you have you're
  1574. 1:09:56going so fast it's actually more like
  1575. 1:09:58fields going over a bus, electric and
  1576. 1:10:00magnetic fields rather than just uh
  1577. 1:10:02voltage signals. But regardless of that
  1578. 1:10:05um it's much easier to go a long
  1579. 1:10:07distance with uh serial cables uh
  1580. 1:10:10because even if one bit is slightly
  1581. 1:10:12delayed or there's some errors in one
  1582. 1:10:14thing, it happens to all the devices all
  1583. 1:10:16the bits. It's not a group propagation
  1584. 1:10:18delay.
  1585. 1:10:21And this is why you have longer
  1586. 1:10:22protocols like these are a little bit
  1587. 1:10:24older ones RS232 FireWire but USB um
  1588. 1:10:28Ethernet sure I squed C but even like
  1589. 1:10:30LEDs so like your remote control on your
  1590. 1:10:33uh for your TV. This is a serial
  1591. 1:10:36protocol that's been well defined. It
  1592. 1:10:38just happens to be the medium just
  1593. 1:10:40happens to be optical.
  1594. 1:10:44All right. And then uh you often see
  1595. 1:10:46this here's just an example of that same
  1596. 1:10:48chip we saw before where this is the
  1597. 1:10:50chip that communicates between uh the
  1598. 1:10:52microcontroller and the USB. So it does
  1599. 1:10:54all the USB connection and functioning.
  1600. 1:10:56And then when you start ripping these
  1601. 1:10:57things apart, which I assume you'll do
  1602. 1:10:59at some point probably for your
  1603. 1:11:00projects, um there's only there's two
  1604. 1:11:03lines in here. There's data plus, data
  1605. 1:11:05minus, and then ground uh power, and
  1606. 1:11:09then a couple different shields and
  1607. 1:11:10ground things. And the reason they have
  1608. 1:11:12data plus and data minus, they carry the
  1609. 1:11:14exact same information. It's just one's
  1610. 1:11:16a negative version of the other one. So
  1611. 1:11:17that from a signal integrity point of
  1612. 1:11:19view, um it's not just that one signal
  1613. 1:11:21goes up or down. It's said that that
  1614. 1:11:23you're looking at the delta between the
  1615. 1:11:24two of them. And that from makes the
  1616. 1:11:27detector much more robust to to noise.
  1617. 1:11:30So uh that's what's inside USB cable.
  1618. 1:11:36All right. So uh terminology. So, uh,
  1619. 1:11:40here are the things you're going to have
  1620. 1:11:41to think about when you're thinking
  1621. 1:11:42about your bus topologies. The encoding,
  1622. 1:11:45how's the data encoded, what's the
  1623. 1:11:46transfer speed, uh, cost of pins and
  1624. 1:11:49wiring modu modularity, and then error
  1625. 1:11:52detection. Um, so we didn't really talk
  1626. 1:11:54about that, but uh, what you want for
  1627. 1:11:56error detection is one of those bits or
  1628. 1:11:58multiple bits in that packet could
  1629. 1:12:00encode. So, say like the seventh bit
  1630. 1:12:02there could be a par bit. And that's
  1631. 1:12:04just that you count up all the bits and
  1632. 1:12:05if you're over if all the bits are even
  1633. 1:12:08then say you get a a one for a parody
  1634. 1:12:10bite and say all the bits are odd you
  1635. 1:12:12get a zero for a parody bit and then the
  1636. 1:12:13receiver can check the packet that came
  1637. 1:12:15in and see is that true is the packet
  1638. 1:12:18got corrupted in some way.
  1639. 1:12:23uh serial is typically much slower than
  1640. 1:12:26u parallel for obvious reasons just you
  1641. 1:12:29know n number of bits going through but
  1642. 1:12:31also they are in different domains in
  1643. 1:12:33the electronics world so parallel is
  1644. 1:12:36from on module right or on PCB from one
  1645. 1:12:39PCB one component to another component
  1646. 1:12:42DDR is example uh you're trying to get
  1647. 1:12:44memory speeds that are very very fast um
  1648. 1:12:47that's very different than trying to
  1649. 1:12:48connect over a long distance to your
  1650. 1:12:50computer so they've parallel buses
  1651. 1:12:52versus serial buses like USB and
  1652. 1:12:54Ethernet. They're just also at different
  1653. 1:12:56domains in the space. And so, uh, serial
  1654. 1:12:58is really long data transfers or long
  1655. 1:13:01distances, and we don't really care so
  1656. 1:13:03much, uh, about speed. Of course, you
  1657. 1:13:05want it to be as fast as possible, but
  1658. 1:13:07you're trying to optimize for distance
  1659. 1:13:09rather than uh just breakthrough speed.
  1660. 1:13:13All right. Um, yeah, we talked about
  1661. 1:13:16length of wire, attenuation.
  1662. 1:13:18Um,
  1663. 1:13:20yep. Okay. Uh, one more thing. Let's
  1664. 1:13:23see. Now we have a little time. So, uh,
  1665. 1:13:26how do you synchronize these two devices
  1666. 1:13:28is a big deal as well. So, most uh,
  1667. 1:13:32serial and parallel protocols have a
  1668. 1:13:34clock that goes along with them and say
  1669. 1:13:36that you pre-arrange that you're always
  1670. 1:13:38going to clock data in on the positive
  1671. 1:13:39or negative edge. Great. But there's
  1672. 1:13:42also other protocols that are
  1673. 1:13:43asynchronous and that just means there
  1674. 1:13:45is no clock. So, it's the receivers's
  1675. 1:13:47responsibility to recover the clock
  1676. 1:13:49timing and figure out when it's supposed
  1677. 1:13:51to sample the bits. And that's uh
  1678. 1:13:53challenging. We'll talk about the
  1679. 1:13:55protocol that that uses this the most,
  1680. 1:13:56which is UART. But it does mean that
  1681. 1:13:58that start bit encodes timing and then
  1682. 1:14:01the receiver has to figure out when to
  1683. 1:14:03clock everything else in. This is nice
  1684. 1:14:05in the sense that you didn't need to
  1685. 1:14:07send a clock bit over. So, you've gained
  1686. 1:14:10um
  1687. 1:14:12uh you've reduced the bit. So, you've
  1688. 1:14:13gained an improvement here by not having
  1689. 1:14:16to have so many wires that go around,
  1690. 1:14:17but now the receiver has to be much more
  1691. 1:14:20complicated or at least a bit more
  1692. 1:14:21complicated to make up for the lack of
  1693. 1:14:23the clock signal. And then you also see
  1694. 1:14:25that because of that, there's going to
  1695. 1:14:27be more of a lower bound on how fast
  1696. 1:14:30these things can do because you're
  1697. 1:14:31asking the receiver to do more. So, uh,
  1698. 1:14:33asynchronous is usually not as fast as
  1699. 1:14:36synchronous.
  1700. 1:14:39All right. So, terminology here. So
  1701. 1:14:42synchronous is you need an extra wire
  1702. 1:14:43for your clock. Uh there's no
  1703. 1:14:45synchronization overhead. Um and
  1704. 1:14:47typically uh you can be tightly coupled
  1705. 1:14:49between the CPU and the disk which is
  1706. 1:14:51nice. Uh meaning that you don't you're
  1707. 1:14:54you can clock data in and out based on
  1708. 1:14:56your processor's own clock. You don't
  1709. 1:14:58have to wait for some other event. The
  1710. 1:15:01problem with synchronous is well the
  1711. 1:15:02advantage is that you have less wires.
  1712. 1:15:05there's no clock skew to interrupt
  1713. 1:15:07things, but you have the synchronization
  1714. 1:15:08overhead and now you have to have
  1715. 1:15:10something deviceed in between the CPU
  1716. 1:15:12and uh the the parallel bus or the sorry
  1717. 1:15:15the the data bus which means in your
  1718. 1:15:18world your CPU is going so fast that
  1719. 1:15:20you're probably not waiting necessarily
  1720. 1:15:22but there is this decoupling effect that
  1721. 1:15:24can happen. So that that is the the
  1722. 1:15:26common issue.
  1723. 1:15:29All right. So, timing considerations
  1724. 1:15:32uh we talked a little bit about oh uh
  1725. 1:15:34other considerations. So, we have clock
  1726. 1:15:35and wire delay. Um flow control and
  1727. 1:15:39power consumption and handshaking. So,
  1728. 1:15:40flow control is like uh do you have to
  1729. 1:15:43acknowledge the the data is coming over?
  1730. 1:15:45Does there have to be some communication
  1731. 1:15:47between the two devices? So, we think
  1732. 1:15:49about the advanced peripheral bus. Um
  1733. 1:15:51there were
  1734. 1:15:53uh we had the uh P ready line and P
  1735. 1:15:57enable line. Those were flow controls
  1736. 1:15:58saying which device could talk when and
  1737. 1:16:00then the hand shaking essentially is P
  1738. 1:16:02and P P ready saying okay yes I I really
  1739. 1:16:05am ready now but uh you lose some of
  1740. 1:16:07that functionality in these serial
  1741. 1:16:09protocols because you're trying to
  1742. 1:16:10reduce wire um so you just have to look
  1743. 1:16:12at as we look through all the different
  1744. 1:16:14protocols which one has that particular
  1745. 1:16:16functionality
  1746. 1:16:18and then the last almost last uh almost
  1747. 1:16:21last part here is uh number of devices.
  1748. 1:16:24So you could have pointtooint. Um you
  1749. 1:16:26could have one source and multiple
  1750. 1:16:28destinations. This is probably the most
  1751. 1:16:30common one. Um the one of the challenges
  1752. 1:16:32pointtooint is good but it's very
  1753. 1:16:35dedicated and often times what you want
  1754. 1:16:37is you want to have on your PCB one
  1755. 1:16:39serial protocol or one communication bus
  1756. 1:16:41to everything. And so having a single
  1757. 1:16:44source and multiple destinations is
  1758. 1:16:46nice. and very complicated devices or
  1759. 1:16:48things with multiple uh CPUs on it. You
  1760. 1:16:51may need to have multiple uh sources
  1761. 1:16:53that can control and talk to different
  1762. 1:16:55devices. This is more rare, but
  1763. 1:16:58certainly on a big motherboard that
  1764. 1:16:59could happen where you have some power
  1765. 1:17:01management unit needs to talk to a
  1766. 1:17:02sensor, but then also maybe the core
  1767. 1:17:04processor needs to talk to a particular
  1768. 1:17:06sensor as well.
  1769. 1:17:08Uh and then uh this is kind of some of
  1770. 1:17:10the topologies that exist. We talked
  1771. 1:17:12about pointto-oint. This is like a
  1772. 1:17:13dedicated bus. Um older technologies
  1773. 1:17:17like rings is where data is transferred
  1774. 1:17:20from one device through another one
  1775. 1:17:21through kind of a loop. Um that's more
  1776. 1:17:24for networking. You have mesh topologies
  1777. 1:17:27where it's uh undefined or they they
  1778. 1:17:30reassign themselves. Uh that happens
  1779. 1:17:32more rarely. Probably it's really the
  1780. 1:17:34most common ones are bus and star that
  1781. 1:17:36you will see uh bus star and pointtooint
  1782. 1:17:39that you'll see uh here.
  1783. 1:17:43Okay. And then uh for arbitration
  1784. 1:17:46methods um
  1785. 1:17:49we talked about with the advanced
  1786. 1:17:51peripheral bus that the bridge will do P
  1787. 1:17:54select. It will say that this particular
  1788. 1:17:56device should be listening now or not.
  1789. 1:17:59That's a modality that still exists uh
  1790. 1:18:02in some of the serial protocols or uh
  1791. 1:18:05device protocols that we'll talk about
  1792. 1:18:07where there's actually a select line.
  1793. 1:18:08Other ones are based on packet headers
  1794. 1:18:10or structures where you're actually
  1795. 1:18:11saying this device has an address and
  1796. 1:18:13I'm going to talk to it specifically.
  1797. 1:18:17All right. Um yeah, and who and there's
  1798. 1:18:19questions about centralization. Who's
  1799. 1:18:21controlling the arbitration process?
  1800. 1:18:25All right. And the last line. So, uh
  1801. 1:18:30Sierra protocols that are particularly
  1802. 1:18:32relevant. I think the only one I want to
  1803. 1:18:33add, I don't know if we'll have time
  1804. 1:18:35this year, is to add CAN, but UART uh is
  1805. 1:18:39a well-defined standard that's you will
  1806. 1:18:41see no matter what. SPI and I squared C.
  1807. 1:18:44Um both of those are becoming so common
  1808. 1:18:47and silicon is getting so cheap that
  1809. 1:18:49you'll find almost every one of your
  1810. 1:18:50peripherals will have the capability of
  1811. 1:18:52doing either one. It used to be that
  1812. 1:18:53you're lucky, you know, if if you have
  1813. 1:18:55one or the other, you're not going to
  1814. 1:18:56get both. But now it's so cheap that
  1815. 1:18:58you're going to get both of them. Um,
  1816. 1:19:01Ethernet, uh,

About this transcript

This page contains the full transcript of EECS 373 - Fall 2026 - Lecture 10: "Timers Resolution vs Length & Serial Bus Overview ” by Interactive Sensing and Computing Lab , generated from the public captions YouTube serves with the video. The transcript has 12,575 words across 1,816 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.