Shop OBEX P1 Docs P2 Docs Learn Events
first project — Parallax Forums

first project

devincoxdevincox Posts: 9
edited 2009-04-17 20:42 in General Discussion
I am currently learning to program the SX, with the help of Gunther's excellent book; programming the SX Microcontroller.

I am planning a project to help me learn programming the SX microcontroller.
I want to display,one at a time, information from my motorcycle during an on-track event.

Signals to display:
lean angle - memsic 2125
g-force - memsic 2125
mph - bike's ecu 0-5v
rpm - bike's ecu 0-5v
throttle position - bike's ecu 0-5v
gear - bike's ecu 0-5v
O2 - wideband O2 sensor 0-5v

I am a programmer by trade and have had some asm experience, many years ago, so Gunther's book is a good fit for me.
I wanted to ask some questions to make sure I am on the right path.

Is there a way to make an educated guess at the possible speed/resolution I will be able to capture the above mentioned sensor/values with an SX28, or am I better off with another chip?

I am wanting to just start with capturing one signal and understanding the process/design/code involved and then applying what I learned to the next input.
I have searched the forum but cannot find an asm example of what is involved in displaying an analog signal, does anyone have a link to one?

I have tried to answer these questions by searching the forum, and so ask your forgiveness if I am asking repeat questions. (c:

Regards,
Devin

Comments

  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2009-04-08 09:31
    Devin,

    for reading analog signals from 0 to 5 V, you can find an example in my book, starting at page 301. The dual ADC described there can be easily extended to handle more inputs, although you need two SX port pins for each analog input. As shown in my book, the ADCs do have an 8 bit resolution. In case you need a higher resolution, this is also possible with similar code, and the same external hardware.

    Starting at page 314, you can find examples how to drive 7-segment displays. Maybe, this gives you some ideas for the display section of your application.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • devincoxdevincox Posts: 9
    edited 2009-04-09 13:57
    Perfect.
    Thank you Guenther.

    Devin
  • devincoxdevincox Posts: 9
    edited 2009-04-16 16:12
    I have a question about a code snippet from the ADC example in Guenther's book mentioned above.

    mov w, >>rc ;read current state of adc's
    not w ;turn inputs to outputs
    and w, #%01010000 ;mask adc1 and adc0
    or port_buff, w ;save new value in buffer
    mov rc, port_buff ;refresh charge/discharge lines

    I understand what the mov commands are doing and how the logical operations affect various bytes/registers, but I can't figure out why it is done this way. Perhaps I am overlooking something extremely basic, but I am still learning, so it's escaping me. Could someone go into some detail on the code above?

    The input and output bits are staggered so that when the mov w, >>rc line occurs it shifts the input bits into the location where the output bits were located. Then the next command flips everthing....?

    I indented the code/comments but when I posted it removed the formatting. sorry.

    Thanks in advance,
    Devin
  • pjvpjv Posts: 1,903
    edited 2009-04-16 23:16
    Hi Devin;

    I don't have the book or code in front of me but I suspect the answer goes as follows:

    mov w, >> rc reads a shifted copy of the ADC alternating input and output lines..... we are only interested in those that were the inputs.

    not w flips all pins that were read, so those inputs that were high will now be low, and those that were low will now be represented high in the w register. The ADC program requires that if an input reads high, its associated output (hence the shift to translate this to the output pin)·must be driven low, and vice versa.

    and w,#%0101_0000 eliminates all except the outupt pins.

    or port_buf,w merges the new output state into a register which may have other non-ADC outputs in it.

    mov rc, port_buf refreshes the output pins to the desired condition.

    Each count represents 5Volts/256,· approximately 20 millivolts per count.

    Post edit:
    The purpose of all this is to continually, rapidly and consistently·drive the ADC's digital to analog converter (DAC) output stage in the direction that would cause the input stage to hover at its input switching threshold, namely Vcc/2. Then the ratio of the number of·lows out of any particular period (say 256 counts for an 8 bit ADC) is the ADC value with respect to Vcc.

    So in a 5Volt system, if 32 lows were counted out of a cycle of 256 then that would represent 32/256*5Volts = 0.625 Volts. As Guenther suggests, making the counters longer can give better resolution. Nine bits would give 5Volts/512 = 10 millivolts; 10 bits gives 5Volts/1024 = 5 millivolts and so on. Each extra bit doubles the theoretical resolution, and also doubles the time it takes to make a conversion. For simple work, 8 bits work great. Expanding that to 10 or more bits will cause significant fluctuation in the last bits.· I'm running some 14 bit units with reasonable success, but have to be very particular about clock stability, speed, and code determinism. Then do sume further tricks and mathematical processing to beef up the stability.



    Hope that helps.

    Cheers,

    Peter (pjv)

    Post Edited (pjv) : 4/16/2009 11:45:23 PM GMT
  • devincoxdevincox Posts: 9
    edited 2009-04-17 20:42
    Peter,
    Thank you for the explanation. It makes perfect sense now.

    Devin
Sign In or Register to comment.