mirror of
https://github.com/elua/elua.git
synced 2025-01-08 20:56:17 +08:00
fbe307e12a
buf.c. The smoothing buffer is still kept separate from the main buffering system, but as samples come in via interrupt, they are placed into a "standard" elua buf. The size of this buf is configured according to whether one is grabbing a bunch of samples rapidly (burst), or singly in order to accommodate the expected number of incoming samples. If smoothing is enabled, incoming samples are claimed until the smoothing buffer is full, and then remaining samples are left in the main buffer until they are collected. This means that whether one is collecting single samples or samples at burst rate, and smoothing is enabled, the filter will only be providing samples that have enough history. Added a function to manually flush both smoothing and main buffers. This would be useful if you know your state has changed and you only want fresh samples that are going to be collected after a flush. Also, a lot of functionality moved into elua_adc.c and common.c (boundaries for what belongs where, might be evaluated), reducing the number of platform.c specific functions dramatically. Basic functionality seems to be working, but some more testing should be done. Also, given that there's now a dynamic buffer behind everything, a shift in the way sampling is handled could be done: sample and burst functions could be made to be non-blocking, and to never return anything except for errors. a separate getsamples function could be used for removing samples collected by either function from the buffer. Suggestions are welcome as it would be nice to keep usage paradigms stable after the 0.6 release.
38 lines
969 B
Lua
38 lines
969 B
Lua
require("LM3S")
|
|
|
|
disp.init(1000000)
|
|
disp.clear()
|
|
|
|
adc.setsmoothing(1,4)
|
|
adc.setsmoothing(1,16)
|
|
adc.setsmoothing(2,32)
|
|
adc.setsmoothing(3,64)
|
|
|
|
adcvals = {}
|
|
ctr = 0
|
|
|
|
while ( true ) do
|
|
ctr = ctr + 1
|
|
|
|
stime = tmr.start(0)
|
|
adcvals[0] = adc.sample(0)
|
|
adcvals[1] = adc.sample(1)
|
|
adcvals[2] = adc.sample(2)
|
|
adcvals[3] = adc.sample(3)
|
|
etime = tmr.read(0)
|
|
dtime = tmr.diff(0,etime,stime)
|
|
|
|
if ( ctr == 100 ) then
|
|
ctr = 0
|
|
outstring = string.format("ADC0 (4): %04d",adcvals[0])
|
|
disp.stringdraw( outstring, 10, 10, 11 )
|
|
outstring = string.format("ADC1 (16): %04d",adcvals[1])
|
|
disp.stringdraw( outstring, 10, 20, 11 )
|
|
outstring = string.format("ADC2 (32): %04d",adcvals[2])
|
|
disp.stringdraw( outstring, 10, 30, 11 )
|
|
outstring = string.format("ADC3 (64): %04d",adcvals[3])
|
|
disp.stringdraw( outstring, 10, 40, 11 )
|
|
outstring = string.format("Tcyc: %06d (us)",dtime)
|
|
disp.stringdraw( outstring, 10, 50, 11 )
|
|
end
|
|
end |