Shop OBEX P1 Docs P2 Docs Learn Events
Sawtooth Ramp Using Counter? — Parallax Forums

Sawtooth Ramp Using Counter?

T ChapT Chap Posts: 4,223
edited 2008-11-30 03:38 in Propeller 1
Thinking out loud, trying to determine the most efficient method to do this:

Is there a trick to get a counter and pin to output this type of ramp with adjustable time period(T)... without using software, using counter only? The AN001 shows assembly oversight in all examples to generate waveforms.

The plan is to use the ramp to trip a comparator wherever when it hits the level of an external DC (dynamic) voltage. When it trips, an input stores the iTrip voltage as one of 1024 or 2056 samples in an array. The array is "learned during a "LEARN" method. The array gets stored in eeprom for future recall after boot. On every other subsequent run, the values of the sample get sent back to the comparator with a slight offset upwards (RunOffset) so that theoretically the comparator stays tripped under normal circumstances, and stays low if the analog input is greater. If there is an upwards deviation of > RunOffset, there is a fault.

Not actual code, just ideas:


CON tripPin = 0  'input pin monitoring comparator

VAR  long SampleRef[noparse][[/noparse] 1024], Offset, iTripValue
       word  SampleIndex

PUB Main        'over simplified
    repeat 1024
     LearniTrip(SampleIndex) 
     SampleIndex++

PUB LearniTrip(x) 
        'waitpeq  tripPin to = 0, meaning wave form ramp has exceeded analog input
        SampleRef[noparse][[/noparse]x] := iTripValue    'get value of most recent iTrip val(voltage the sawtooth was at when tripped comp)
        return SampleRef[noparse][[/noparse]x]

PUB GenerateSawtooh
      'preferably some counter only process to create fixed T waveform 

PUB WriteSampleToEeeprom
     'write SampleRef  array to eeprom

PUB GetSampleFromEwprom
   'get the array back from eeprom on each boot

PUB CompareiTrip       
      if GetTripPinState == tripped   'compare stored value to actual new value
         'do something

PUB SetOffset
       Offset := 5   'arbitrary number  

PUB GetTripPinState
      if tripPin == 0
       return tripped
    else
      return untripped


Post Edited (TChapman) : 11/29/2008 9:46:37 PM GMT
264 x 514 - 42K

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-11-29 22:03
    The ramp would have to be mediated by code. This is done by gradually increasing FRQx in a DUTY-mode counter.

    With an external op-amp integrator, however, you could use FRQx to set the slope of the ramp, which would be a fixed value; then use an analog switch to discharge the integration cap, thus starting a new ramp.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Just a few PropSTICK Kit bare PCBs left!
  • T ChapT Chap Posts: 4,223
    edited 2008-11-29 22:32
    Thanks Phil, I assumed it wasn't possible, but thought maybe some of you guys had some counter tricks to get around using a cog to do it. Your other idea is interesting, I will explore an external idea like that.
  • T ChapT Chap Posts: 4,223
    edited 2008-11-30 00:19
    Here is an idea using PLL Video mode to generate a rising value at FRQa X:

    ctra :=    '  duty mode @ itrip pin
    frqa := 0  
    
    ctrb := %00001 << 26   'does not use any pins in this mode
    frqb := 100
    
    



    This generates a number from -2b to 2b in a loop.

    I have an existing repeat loop doing other things that I can drop the Read iTrip Pin inside to always monitor the comparator. This way, it uses no extra dedicated loops, cogs, etc.

    ex.

    EDIT .

    Dira[noparse][[/noparse]pin] := 2
    ctra := %00001  'this ramps at any desired speed(set at frq)   from -2b to 2b, no pins used in PLL
    frqa := 1  'very slow ramp
    
    ctrb := %00010
    frqb := 0
    
    repeat
       'frqb := frqa   
      'some code to translate the PLL -2b to +2b ramp into voltage 0 - 3v3
    
    
    



    Any suggestions?

    Post Edited (TChapman) : 11/30/2008 1:43:46 AM GMT
  • T ChapT Chap Posts: 4,223
    edited 2008-11-30 03:38
    This may be common knowledge, but I find this interesting that I can set any fixed voltage using a counter only show below.

    So, using 2 counters I am sure there is a way to generate a sawtooth at any fixed ramp time(based on the speed of the loop used modifying PHSb).

    Counter 1 is the PLL %00001 mode, incrementing at 1, it does not use a in. It counts (at least on my LCD) from -2b to 2b, then repeats.

    Counter 2 is %00100, and outputs to a pin iTrip.

    If I can somehow do some math to convert PHSa -2b - 2b into the correct numbers shown, I can generate the waveform needed with no code:

    Here are the fixed voltages I get from counter B using a 10K resistor and .01 filter cap both meter and scope:

    Set pin to out, %00100

    FRQb := 5000


    
    
    
    Repeat
       PHSb := y
    
    
    



    if Y = the following, the respective voltage appears at pin:


    Substitute for y

    -1000 .08vdc
    -25000 .09
    -50000 .10
    -100000 .13
    -200000 .17
    -300000 .22
    -400000 .265
    -500000 .310
    -600000 .355
    -700000 .4
    -800000 .446
    -900000 .491
    -1000000 .536
    -1500000 .761
    -2000000 .98
    -2500000 1.21
    -3000000 1.437
    -3500000 1.662
    -4000000 1.88
    -4500000 2.11
    -5000000 2.33
    -5500000 2.56
    -6000000 2.78
    -6500000 3.01
    -7000000 3.22
    -7500000 3.22 same
    -8000000 3.33

    Just some minor non linear issues, but adequate for the task.

    Can anyone think of a formula to convert the PHSa values -2b - 2b into a range of -1000 to -8_000_000 respectively?

    Thanks for any ideas!


    Nice reverse sawtooth wave:

    
    FRQb := 5000
    repeat
      y := -1000
      repeat while y > -8_000_000
         phsb := y
         y := -1000
    
    
    
    

    Post Edited (TChapman) : 11/30/2008 4:30:34 AM GMT
Sign In or Register to comment.