Sawtooth Ramp Using Counter?
T Chap
Posts: 4,223
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:
Post Edited (TChapman) : 11/29/2008 9:46:37 PM GMT
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
Comments
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!
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 .
Any suggestions?
Post Edited (TChapman) : 11/30/2008 1:43:46 AM GMT
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
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:
Post Edited (TChapman) : 11/30/2008 4:30:34 AM GMT