Shop OBEX P1 Docs P2 Docs Learn Events
Question about propeller education kit labs — Parallax Forums

Question about propeller education kit labs

4x5n4x5n Posts: 745
edited 2011-09-04 22:52 in Propeller 1
Once upon a time in a former life and past career I did a lot of interrupt driven machine control programming for the 68hc11 microcontroller in assembly. During that time I did a lot of ladder logic programming for a few different types of PLCs. Recently I've gotten involved in a couple of projects that have the potential for small scale production (400-500) that I think the propeller would be ideal for. I've got a proto board on order for $25 which would put the price of the control electronics including power supply, motors, heaters, etc at about $100.

In preparation for programming the prop for this project I got the Propeller Education Kit Labs to learn how to program it. After a couple of hours or working through the labs in the beginning of the book I got to page 64 in which a technique is presented for improving long term timekeeping. The problem I having is the I don't understand how or why it either works or improves the long term time keeping with the "waitcnt" command. I've been going through the text and there's only a sentence or two explaining it and I'm just not following it. While long term time keeping isn't an concern for the projects I'm working on I'm afraid I'm missing something very basic and fundamental that will hurt me later on. Can someone give me a paragraph or two explaining it to me or point me to a web page that explains it?

Comments

  • 4x5n4x5n Posts: 745
    edited 2011-09-04 17:22
    After making my initial post I read, reread and reread the book again and think I had an epiphany and figured out what the difference is and why the modified code on the page gives better long term timing. Right now I'm going to reflect on it and sleep on it and if I can still make sense of it in the morning and there's interest I'll post code snippets along with my understanding of the differences for those that don't have the book.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-04 22:52
    WAITCNT waits for a particular value of the system counter to occur, whatever you supply. Normally, you provide a "future" system clock count based on the current system clock (CNT) plus some offset (X). For example, one second in the future would be CNT + CLKFREQ. The problem that you run into is that it takes a little bit of time to do that calculation and start or finish the next WAITCNT and that accumulates over time to produce a small error. You can avoid that error by using the original system clock count plus multiples of your offset. Essentially you're saving the original CNT (with oldCNT := CNT), then waiting for oldCNT+n*CLKFREQ (with WAITCNT(oldCNT += CLKFREQ)). The result is a one second wait with no creep. Each wait finishes exactly one second after the other (to the nearest 12.5ns).
Sign In or Register to comment.