Shop OBEX P1 Docs P2 Docs Learn Events
BS2pe Mobo Tach question - Page 2 — Parallax Forums

BS2pe Mobo Tach question

2»

Comments

  • jsaddictionjsaddiction Posts: 84
    edited 2012-01-07 06:18
    how difficult was it to write the code for the AVR? I have downloaded AVR studio 5 I even opened your Hex file in it to see if the IDE could decipher any of it and well .... I got the hex arranged in what appears to be addresses. Anyway. I really like the way your software is set up but as said before I really want to learn how to write the code for that AVR. Do you know of any documentation that could start me off In the right direction?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-01-07 09:35
    Sorry this took so long. I finally found the source for the encoder program (attached). It's written in AVR assembly. If you've never programmed in assembly before, the AVR is probably not the best micro to start with, since it has a very non-orthogonal architecture. However, you can also program the AVR in C, and I believe the C compiler is included in Atmel's free dev package. I don't know what's out there as far as instructional materials go. I started with the Tiny13 datasheet and the AVR Assembly manual, but that was with a strong background in assembly programming for microcontrollers.

    -Phil
  • jsaddictionjsaddiction Posts: 84
    edited 2012-01-08 12:12
    You are right that code looks pretty complicated. I think i may be able to figure it out though. Thank you so much for that. Initially I will use the original firmware for the avr untouched and then I will try to add some functionality. If you have any pointers or any other documentation that can help with this particular asm file please let me know. Otherwise I will get to work on this. My Command has approved the money for this project and as soon as our new quarterly funds get approved the hardware will be purchaced. I have most of everything built except the BS2PE code to interface avr and display. The prototype circuit for the encoders and avr interface is complete and working at twice the speed nessisary. Thank you so much for your input You have helped greatly.
  • jsaddictionjsaddiction Posts: 84
    edited 2012-02-21 18:08
    Ok Phil i finally got all the hardware and I assembled the protoboard containing the dual comparator. I flashed both coprocessors slot a with your enc1 file and the other with the 7seg display firmware. I got everything to work pretty well as a counter. As i powered the card up my display showed 0000 as i move the light beacon counterclockwise the number increased by 600 every revolution and decreased with counter clockwise movement. After ensuring everything was working correctly i started on the code to calculate RPM. I think i have it pretty well figured out except I just can't figure out how to average an array of one second long counts. I also can't figure out how to display the decimal point on the 7seg daughter board.
    TIA
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-21 20:13
    The way to average an array of counts, using "boxcar" averaging, is the following:
    1. Have a Nib counter that runs from 0 to 9, then recyles back to 0, continuously. That will be your index into the array of one-second readings.
    2. For each reading, add it to a running total, subtract the currently-indexed reading from the total, and write the current reading to the array at the current position.
    3. Increment the array index, mod 10.

    Your total will equal the number of ecnoder ticks accumulated over the last ten seconds worth of readings. Multiply that by six, and you will have the number of readings over one minute. Divide that by 600, and you will have the RPM.

    But ti's easier than that. your total is the RPM x 100. So output total/100 first to the LED as two decimal digits, followed by a ".", then followed by total//100 as two decimal digits (with leading zeroes). The LEDs will display your RPM as a decimal in the form xx.xx.

    -Phil
Sign In or Register to comment.