Shop OBEX P1 Docs P2 Docs Learn Events
Opposite of "*/" ?? — Parallax Forums

Opposite of "*/" ??

Turnbull2112Turnbull2112 Posts: 65
edited 2011-11-29 09:23 in BASIC Stamp
How do I work the */ operator backwards? I have an 8 bit reading from an ADC that I'm adjusting with a multiplier and shifting back out a DAC. I need to get my adjusted value back to an 8 bit number (0-255). This is probably a stupid and obvious solution but I'm stuck.

Thanks,
Code attachedExcerpt ADC issue.bs2
Rob

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-11-28 11:48
    I don't see the problem. The snippet you posted does not change the O2result that comes from the ADC. The */ SPAN operator is applied to get a second variable, O2conc, but it is O2result that gets shifted out to somewhere but needs to be changed.

    Could you please explain a little more what you are trying to do?
  • Turnbull2112Turnbull2112 Posts: 65
    edited 2011-11-28 12:33
    Sorry about that, before I added the "RCTIME/SPAN" code is was just using O2conc = O2result */ 1000 to get my numbers. Now that I'm using the "SPAN" to adjust O2result, what would I SHIFTOUT to the DAC? If I use "O2result" the signal generated by the DAC will be uncorrected. I need to SHIFTOUT a 0-255 result to the DAC. How would I get "O2result */SPAN back into a 0-255 number to send to DAC? If I use "O2conc" the DAC sends out crazy values. Sorry if I'm not making much sense, I'm fringing on the limit of my programming vocabulary.... lol

    Thanks,
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-11-28 13:45
    What value of O2result (or O2conc) should cause a value of 255 to be SHIFTed out? That will determine the next scale factor. For me, the issue is not so much programming, rather, a description of the project itself.
  • Turnbull2112Turnbull2112 Posts: 65
    edited 2011-11-28 13:57
    I'm reading an oxygen sensor that gives me a 0-5v output for 0-100% O2. I'm reading that through an ADC0831. I'm displaying the concentration on a serial LCD and also sending the value out of a 4-20mA control loop, 0 = 4mA and 255 = 20mA ( 0-100%). The AD420 which drives the loop is 16 bit but I'm sending it 8 bits, my resolution is a little blocky but not an issue. The O2conc is what's displayed (max value is 1000 to get tenths) but I'm sending 0-255 to the AD420 for remote scaling in a SCADA or PLC. How would I include the trimmed value so that the AD420 can interpret it correctly?
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-11-28 15:21
    Okay, the full scale range is supposed to be 4mA loop output when O2conc=0, and 20 mA when O2conc=1000 (100.0%).

    Into the DAC, that requires input codes from 0 to 65535. It is best if you scale up so that you can send a full 16 bit quantity to the DAC (but still it will have only 256 steps, which you say is okay).
    [B]LOW[/B] latch
    [COLOR=#999999][COLOR=#000000][B]SHIFTOUT[/B] datain, clock, [B]MSBFIRST[/B], [(O2conc */ 16777) \ 16]  [/COLOR]'****new approach[/COLOR]
    [B]HIGH[/B] latch
    [B]DEBUG[/B] ? O2conc */ 16777
    

    The math (O2conc */ 16777) will scale up to 65535 when O2conc=1000. Note the \16, which causes the SHIFTOUT to send all 16 bits.
  • Turnbull2112Turnbull2112 Posts: 65
    edited 2011-11-29 09:23
    Excellent! I will give this a try and post my results. Thanks Tracy!

    Rob
Sign In or Register to comment.