Shop OBEX P1 Docs P2 Docs Learn Events
How to limit ranges on FRQB in spin. — Parallax Forums

How to limit ranges on FRQB in spin.

T ChapT Chap Posts: 4,223
edited 2012-04-24 13:59 in Propeller 1
PUB iTRipSet(tr) |  f
     Dira[CurrentTripSetPin]~~
     outa[CurrentTripSetPin]~
     ctrb := %00110  << 26 +  CurrentTripSetPin
     repeat
       f :=   (TripLevel * TripLevelBias) - (tempnew * TempBias)  
       if f > 0   ' filter if negative, if positive then limit min
          f #>= 500_000_000 
       frqb := f  

       '   REF output voltages
       'frqb := -1                        '3.265V      4.294B
       'frqb := -2_147483646    '1.655V      2.147B
       'frqb := 2_147483647     '1.655V      2.147B
       'frqb := 0                         '0.000V      0

I know I have posted on this before, but still cannot get my head wrapped around this issue to solve it.

The minimum output of the frqb needs to be 500_000_000 and the code solves that no matter what values the method is receiving. The problem comes from when the frqb rolls over from -1 to anything above. I tried added another line that says

if f < -1
set the max f to -1 to create a cap.

Didn't work, it faulted anyway, maybe the limit max to -1 doesn't behave as I though in this case.

The reason is the DAC output maxes out at 3.265V at f = -1. If the code feeding the method exceeds -1, the voltage drops back to 0, and faults out the system.

I would appreciate if someone could point out a way to limit f to a max of -1, but at the same time allow values to range from 0 to 2.147B?


The values for F need to range from 5_000_000 to 4.294B (-1) only.

Thanks!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-04-23 12:41
    Try this:
           f :=   ((TripLevel * TripLevelBias) - (tempnew * TempBias))  ^ $8000_0000
           f :=  f #> (fmin ^ $8000_0000) <# (fmax ^ $8000_0000) 
           frqb := f  ^ $8000_0000
    

    This has the effect of forcing the min and max operators to act on unsigned longs.

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2012-04-23 13:06
    PUB iTRipSet(tr) |  f, fmin, fmax
        fmin := 500_000_000
        fmax := $8000_0000
         Dira[CurrentTripSetPin]~~
         outa[CurrentTripSetPin]~
         ctrb := %00110  << 26 +  CurrentTripSetPin
         repeat
           f :=   (TripLevel * TripLevelBias) - (tempnew * TempBias)  
           if f > 0   ' filter if negative, if positive then limit min
              f #>= 500_000_000 
           frqb := f  
    
           '   REF output voltages
           'frqb := -1                        '3.265V      4.294B
           'frqb := -2_147483646    '1.655V      2.147B
           'frqb := 2_147483647     '1.655V      2.147B
           'frqb := 0                         '0.000V      0
    
    

    Thanks Phil, I assume you intended me to set the fmin and fmax to the desired range. In this case above, I set fmin to the lower level DAC output of 500_000_000 and fmax to $8000_0000, but it still is rolling over past 3.2V to 0 and above, ignoring the cap. Maybe I didn't implement the fmin and fmax correctly, I clearly do not get the XOR use here.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-04-23 14:16
    The XOR converts the range so that 0 < $7fff_ffff < $8000_0000 < $ffff_ffff when doing the comparisons inherent in the min and max operations. IOW, it converts a signed range to an unsigned range for min and max, after which you convert it back.

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2012-04-23 21:34
    f :=   ((TripLevel * TripLevelBias) - (tempnew * TempBias))  ^ $8000_0000
           f :=  f #> (500_000_000 ^ $8000_0000) <# ($FFFF_FFFF ^ $8000_0000) 
           frqb := f  ^ $8000_0000
    

    I think this is what you mean to do if I want the minimum output to be 500_000_000 and the max to be 4.2B or -1.

    I will try this at the shop tomorrow.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-04-23 21:56
    Yeah, that's the ticket!

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2012-04-24 10:11
    PUB iTRipSet(tr) |  f, fmin, fmax
         fmin := 500_000_000  ^ $8000_0000
         fmax := $ffff_ffff ^ $8000_0000
         Dira[CurrentTripSetPin]~~
         outa[CurrentTripSetPin]~
         ctrb := %00110  << 26 +  CurrentTripSetPin
         repeat
           f :=   ((TripLevel * TripLevelBias) - (tempnew * TempBias))  ^ $8000_0000
           f :=  f #> fmin <# fmax 
           frqb := f  ^ $8000_0000
    


    Still no luck, the DAC output (math) blows past 3.265V and starts back up at 0v and faults out because the DAC is too low. It appears that minimum is fine as it only crashes when setting the trip level at a point so that the math can roll over frqb of 0. If the min value was not operating, the system would fault out on bot. Any suggestions appreciated.

    $ffff_ffff should be -1 right? I need some way to limit max the frqb to avoid rolling back over to 0v output.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-04-24 10:15
    Is the expression, (TripLevel * TripLevelBias) - (tempnew * TempBias) always positive?

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2012-04-24 10:19
    No, that is the source of the math that is rolling over. But I will confirm this.
  • T ChapT Chap Posts: 4,223
    edited 2012-04-24 10:26
    (TripLevel * TripLevelBias) can roll over if set high enough.

    Tempnew*tempbias is always positive, and is always subtracted from the first set of values, but is always a small value in comparison.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-04-24 10:28
    Can either of the two product terms in that expression overflow 31 bits + sign?

    -Phil

    Answered before asked!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-04-24 10:29
    Are TripLevel and TripLevelBias both positive numbers? Also, if their product rolls over, does that automatically mean frqb should be $ffff_ffff, or could subtracting the other product term modify that? Finally, is there ever an instance where the difference could be legitimately negative?

    Another thought: do you really need 32-bit presicion in frqb? If not, why not set the bias values to produce lower numbers for f, then shift it left when assigning it to frqb?

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2012-04-24 13:59
    Ok Phil, I am a dummy. My code allowed for the source of the triplevel * TriplevelBias to exceed 4.2B and roll over past 0 again. Pure dumbness. The original code works perfectly when you don't limit the triplevelbias so that it cannot force the values past $ffff_ffff.

    Thanks for the assistance, your last inquiries set me on the path to see the problem.
Sign In or Register to comment.