#qi-hardware IRC log for Sunday, 2016-03-27

--- Sun Mar 27 201600:00
wpwrakDocScrutinizer05: discussion of the time-keeping circuits: http://lists.en.qi-hardware.com/pipermail/discussion/2016-March/011020.html04:56
DocScrutinizer05btw did you notice the similarities between the FET in 4 and an "ideal diode"11:42
wpwrakyes, there's a bit of that there11:43
DocScrutinizer05I just wonder what's the ABSMAX for the sMCU11:49
DocScrutinizer05particularly regarding voltage on any pin vs VCC11:49
DocScrutinizer05my final design recommendation is: ADC/GPIO[1] - 3M3 - C1 - GND; [1] - schottky - VCC11:51
DocScrutinizer05the leakage current on ADC/GPIO is basically negligible resp no problem to probe for, after power return11:53
DocScrutinizer05simply charge again until C1 full, then switch to discharge and probe voltage11:53
DocScrutinizer05the temperature and thus leakage of the chip won't change in the timespan from battery change aka discharge, over probing residual charge on C1 after power return, to probing leakage after fully charging C1 after residual charge probing11:55
DocScrutinizer05for 1uA@3V3 leakage current you got an equiv Z of 3M3, what a coincidence ;-)12:03
DocScrutinizer05so your ADC would still probe with a multiplier of 0.5, which is easy to determine after you charged C1 to VCC, *after* probing residual charge after batt swap12:04
DocScrutinizer05and 0.5 "prescaler" also leaves still enough precision in ADC12:06
DocScrutinizer05it's just one bit less12:07
DocScrutinizer05you could even get quarter-bit or even 1/8 bit resolution by polling at high speed and determinin time for first 1digit decrement vs time between 1st and 2nd 1bit decrement12:09
DocScrutinizer05you even can *completely* eliminate prescaler effects of GPIO leakage, by doing a PWM beween charge and discharge to keep C1 voltage steady12:10
DocScrutinizer05your C1 voltage is exactly Vcc * PWM ratio12:11
DocScrutinizer05how much better than this could any other design get?12:13
DocScrutinizer05(and how much simpler, BOM wise and to evaluate)12:15
DocScrutinizer05wpwrak: ^^^12:16
DocScrutinizer05((*completely* eliminate)) not only prescaler effects but also any nonlinearities in ADC12:21
DocScrutinizer05only thing you can't completely eliminate but only mitigate with PWM is ADC noise12:21
DocScrutinizer05to be precise: s/Vcc/Vio/g12:27
DocScrutinizer05even when Vcc doesn't rapidly drop to 0V, it's still a given that the whole circuit is in a quasi static state without any variables, after MCU stopped working. So it should be highly repeatable12:29
DocScrutinizer05IOW discharge is still predictable (by calibration)12:30
DocScrutinizer05factory side calibration12:31
wpwrakthe ADC is 16 bit. so i can make many ADC effects (not quite all, e.g., not non-linearity) vanish into bits that hold no useful value anyway ;-)12:31
DocScrutinizer05you do a test series discharge time vs capacitor voltage, create a tab and that should be good enough12:31
DocScrutinizer05at least for precision in the sub-second range during 60s12:32
wpwrakdictable) dunno. there are elements that may develop their own life before i can fully "neutralize" them. e.g., the OLED.12:33
DocScrutinizer05how long will that take? 1s, or less?12:33
wpwrakthat's what i don't know :)12:33
DocScrutinizer05no matter if 1s or less, the effect on timing is negligible12:34
DocScrutinizer05definitely can't be larger than 1s of error12:34
DocScrutinizer05same for glitches12:34
DocScrutinizer05before trying to eliminate dirt effects, we need to consider if they matter at all12:36
DocScrutinizer05otherwise the cure will be much worse than the disease12:37
wpwrakif system leakage is in the order of 5 uA and we have about 50 uF of caps on the rail, a drop by 1 V would take 10 s12:40
DocScrutinizer05and what are the variables in all this?12:42
DocScrutinizer05I mean, the variables you can't determine even at runtime12:42
DocScrutinizer05or even control at runtime12:42
wpwrakthe MCU loses sight of things around 1.71 V, realistically much earlier, since we want to clean up and close shop as soon as we go significantly below 3.3 V12:43
DocScrutinizer05then system is in a very well defined state from that moment12:43
DocScrutinizer05the only vatiable I see is temperature12:43
wpwrakcomponent variations, component state. e.g., the OLED has its own DC-DC converter that can keep things alive for a while12:44
DocScrutinizer05so what? those won't change over lifetime of a particular device much12:45
DocScrutinizer05you control component state12:45
DocScrutinizer05that's the whole purpose of "closing shop"12:46
DocScrutinizer05if factory side (R&D) calibration isn't sufficient, user needs to do a onetime calibration for the device (if you don't want to do this at factory for each device)12:47
wpwraknot necessarily. e.g., i don't really know what's going on inside the OLED, and i eventually lose the ability to communicate with it. i can still command a reset, though, but i don't know how that affects residual charges and the things they drive12:47
DocScrutinizer05you can however instruct the display to switch on or off all pixels, as long as shop not closed yet12:48
wpwrakmmh. lemme check ...12:48
DocScrutinizer05which I am pretty sure has identical effect on component state on all the OLEDs you ship12:48
DocScrutinizer05there's no HRNG in OLED that creates massive uncertainties in component behavior12:50
DocScrutinizer05when one OLED acts in a particular way once, it will do twice under same (history of) conditions, and other identical OLED components will as well12:51
wpwrakthere is a "quick" display off command. in fact, there are two, with not very clearly spelled out differences12:52
DocScrutinizer05if there are massive fluctuations between components of same bin, you need per-device calibration to cope with those12:52
DocScrutinizer05otherwise one time R&D 'calibration' will do12:53
DocScrutinizer05tbh I'd rather power on all consumers to pull Vcc to GND as fast as possible12:55
wpwrakof course, the more we clean up, the lower the leakage. so we're increasing that slope12:55
wpwrakyes, exactly ;-)12:55
wpwrakhave some 100 uF anti-charge cap somewhere ;-)12:55
DocScrutinizer05there are a number of nonlinear components like PTCs ;-) But honestly I'd not worry too much about all this, I'm pretty sure you can pull Vcc to GND in less than a second12:58
DocScrutinizer05or at least to a steady state of maybe 1V5 above GND12:58
DocScrutinizer05and you can do this very reproducibly12:59
DocScrutinizer05irrespective of any random effects based on history of the component behavior (aka commands issued before)12:59
DocScrutinizer05as I said, there's no HRNG in any of your components that would have massive impact on their behavior on power down13:00
DocScrutinizer05only variable is temperature, yet to get evaluated if it matters at all13:01
wpwrakyou don't need a HRNG. it's enough if there is something that can be in different internal states you don't control. that's what i'm worried about.13:04
DocScrutinizer05particularly system behavior from 1V5 down to 0V on Vcc is pretty reproducible13:04
wpwrakand i can't actually test such things before having a number of devices13:04
DocScrutinizer05you hardly have *any* devices with different internal stages after receiving same sequence of commands13:05
wpwrakhence i prefer a "safe" design that itsn't at risk of needing a redesign at that point13:05
DocScrutinizer05you don't need several devices, random different internal stages are a problem of *one* device13:06
wpwraki don't really have time for elaborate transitions. e.g., the OLED has transitions that are specified to take some 100 ms. i can't risk waiting for such things.13:07
DocScrutinizer05which you can test right away. and designing for a 100% safe circuit no matter which possible nasty properties components might have is not possible13:07
DocScrutinizer05huh? don't you know in which state the OLED is, before as well as after such transition?13:08
DocScrutinizer05isn't that deterministic?13:08
wpwrak(test right away) naw, there are several new components in the new design for which no prototype exists yet13:08
DocScrutinizer05I just can tell you you're massively overengineering this13:09
DocScrutinizer05if time is SOOOOO important, add a cmos clock and a goldcap13:10
wpwraki know the "high-level" state before and i know the state after. what happens in the middle, duh. inside the high-level state, there are internal sub-states that are hidden from me.13:10
wpwrakheh ;-)13:10
wpwrakmay not be so difficult to be able to support page 3 (diode) and page 4 (fet) design in the same circuit, with a minor placement change13:12
DocScrutinizer05both add more complications than they solve13:13
wpwrakso you don't like the diode anymore ?13:13
DocScrutinizer05my final design recommendation is: ADC/GPIO[1] - 3M3 - C1 - GND; [1] - schottky - VCC13:14
wpwrakpage 3 is pretty much that, except that i add a lower R between C1 and ADC/GPIO13:15
DocScrutinizer05[2016-03-27 Sun 13:49:10] <DocScrutinizer05> I just wonder what's the ABSMAX for the sMCU - particularly regarding voltage on any pin vs VCC (when Vcc = 0V and capacitor 3V)13:15
DocScrutinizer05and no, your design is massively different in that respect to mine13:16
wpwrakokay, that's a fair point13:16
wpwrakthe absmax is the usual vdd + 0.3 V but there is no clamping diode. so i don't quite know what happens.13:17
DocScrutinizer05@ occasional lurkes: Vdd is another synonymous name for Vcc13:18
wpwrakwhat really worries me in your design is the huge resistance amplifying even the tiniest GPIO leakage13:18
wpwrakwell, i guess i could always raise C1 to 47 uF or such :)13:20
DocScrutinizer05as I elaborated you got the precision of a 1bit delta-slope converter ( precision of your timebase) for ADC when you do that PWM pattern I suggested. Completely irrespective of any leahage current however large or small13:20
DocScrutinizer05well, actually the precision limit is the noise and resolution of the ADC, but *not* any prescaler formed by resistors and leakage current13:21
DocScrutinizer05when you switch 8PWM) between 25% charging via R from Vcc and 75% discharging via R to GND and that keeps your voltage staedy, then you know your capacitor has exactly 25% of Vcc resp Vio13:23
wpwraki don't see how PWM would help with measuring. charging/discharging is not a problem, since we have low impedance anyway13:24
DocScrutinizer05see above13:24
DocScrutinizer05my final design recommendation is: ADC/GPIO[1] - 3M3 - C1 - GND; [1] - schottky - VCC13:24
DocScrutinizer053 components, one GPIO13:25
DocScrutinizer05capacitor voltage probable to 0.1% precision almost irrespective to size of R13:26
DocScrutinizer05no overvoltage issues at GPIO (when Vdd = 0V). Immune tio glitches13:27
DocScrutinizer05yes, it still has the 'problem' of Vdd not falling to 0V for 20s, but we discussed that thoroughly during last 30min, it can get taken care of by software design13:28
DocScrutinizer05by fast discharge as well as R&D or factory (per unit) calibration13:28
DocScrutinizer05one particular OLED won't suddently start to behave randomly differnet, when you propperly "initialize" it during shutdown13:30
DocScrutinizer05when there are N different states the component can be in, and you can't transition fast between them, all you need to do is to know the current state and apply the according calibration13:31
DocScrutinizer05there is no HRNG13:31
DocScrutinizer05your circuit is mostly deterministic13:32
wpwrak(see above) hmm, that would help with the part of the error that is because of component variation. i wouldn't help with error due to chip temperature. i wonder if we can do such precise temperature compensation. after all, the possible V difference would be basically the whole measurement range, with the leakage current going through 3.3 MOhm.13:33
DocScrutinizer05you know the state it's in so you can predict how it behaves13:33
DocScrutinizer05you still didn't grok the PWM thing?13:34
wpwraki think i get the PWM thing: you charge to a well-known voltage, then measure, and thus calculate the leakage current13:34
DocScrutinizer05when you switch (PWM) between 25% charging via R from Vcc and 75% discharging via R to GND and that keeps your voltage staedy, then you know your capacitor has exactly 25% of Vcc resp Vio - capacitor voltage probable to 0.1% precision almost irrespective to size of R and leakage current13:35
DocScrutinizer05I do PWM charge/discharge to keep the ADC at a steady level that was the value when first probing the voltage of C113:36
DocScrutinizer05leakage current: irrelevant doesn't show up in equation13:36
DocScrutinizer05same for size of R13:37
wpwrakhow does a PWM with fixed ratio hold an arbitrary initial voltage ?13:37
DocScrutinizer05PWM= 42.4711%, so voltage on C = Vio/Vcc * 42.4711%13:38
wpwraksure. but how does this help with _measuring_ ?13:38
DocScrutinizer05the trick is to adjust the PWM so it has same average voltage as C13:39
wpwrakyou're talking about a second RC circuit, for the PWM ?13:39
DocScrutinizer05with a given capacitor voltage (to probe) of 42.4711%, you first get a ADC that results in value 12345, then you start with a PWM of 50% (you can optimize by guessing the needed PWM from 12345) and watch the ADC. It will go up to 12350 or whatever, so you know your 50% are too high and you turn it down to 45%13:41
DocScrutinizer05redu until your ADC again shows 12345 and your PWM vill be 42.4711%13:42
DocScrutinizer05redo even13:42
wpwrakah, i see. so 2 (or more) measurements13:42
DocScrutinizer05all percentages of voltage with respect to Vio/Vdd13:42
DocScrutinizer05yes, multiple measurements13:43
wpwraktemperature may still be an issue. if the MCU is actively moving things around, that may change the chip temperature a little. and since we're extremely temperature-sensitive there, ...13:43
wpwrakbut okay, that could probably be compensated, too13:44
DocScrutinizer05the only variables determining precision are: the *relative* precision of ADC (noise and resolution), Vdd and your timer for PWM13:44
wpwrake.g., meas(temp), meas(Vc1), meas(temp), then do the PWM routing, also all the while measuring the temperature13:44
wpwrak s/routing/routine/13:45
DocScrutinizer05how much could temperature change during 2 minutes? also where is temperature realyl coming in here. For sure not for probing, probbaly for Vcc discharge though13:45
wpwraksure for probing. don't forget that it can go up to 1 uA over a 100 C range. so that's about 1% of the measurement range for each C, assuming the change is linear13:48
wpwrakwe'll be trying to measure differences < 1% of the range13:49
wpwrakrange = [0, 3.3 V]. 1 uA * 3.3 MOhm = 3.3 V, 100% of the range13:49
DocScrutinizer05you're confused :-)13:50
wpwrakso even slight temp changes can throw us off13:50
DocScrutinizer05no, leakage current doesn't show up in the equation13:50
wpwrakmax leakage is 25 nA at 25 C and 1 uA "over full temp range", i.e., at 125 C13:50
DocScrutinizer05this "meter" is completely immune to leakage current13:50
wpwrakbut only if you're assuming constant leakage13:51
wpwrakwhat i'm saying is that it changes13:51
DocScrutinizer05during measuring period13:51
DocScrutinizer05which is <1s13:51
DocScrutinizer05I don't see how temperature could change during this period of time13:52
DocScrutinizer05maybe it helps ro check wikipedia for sigma-delta ADC13:54
wpwrakhmm, i get about 0.7 C, assuming we draw ~2 mA on average. that would be okay.13:55
DocScrutinizer05this is a modified sigma-delta scheme13:56
wpwraki understand the process, my concern is the effect of leakage changing during the process. but it seems that the change would be relatively small.13:57
DocScrutinizer05you can bet on the effect being too small to calculate it without help of an electronic calculator ;-)13:59
DocScrutinizer05it will be serveral magnitudes lower than your demanded precision of 1%14:00
wpwraki get about 1 C = 1%, so, zero magnitudes :) still, that's already14:06
DocScrutinizer05how's the chance for the low power chip to heat up 1°C during less than 1s, in a semi-steady state 2 or 3 seconds after power up14:08
DocScrutinizer05your stability of Vdd is a more concerning issue regarding ADC precision14:09
DocScrutinizer05after all we use Vdd as reference voltage here, all the time14:10
DocScrutinizer05dunno if your ADC has an internal stabilized refernce voltage so you could use ADC to determine actual voltage of Vio14:12
wpwrakVcc should be pretty stable, and when we ramp down, we already assume we fall rapidly, right ? :) i'd set the low voltage interrupt close to 3.3 V, so te MCU reacts within some 10% of the range.14:13
wpwrakand yes, the ADC has a bandgap reference, too14:14
wpwrakthey pretty much all do nowadays ;-)14:14
DocScrutinizer05so you can probe the real voltage during charging, while same time pulling ADC/GPIO high and probing it14:15
DocScrutinizer05and you also can probe the real low voltage on ADC/GPIO = L14:15
DocScrutinizer05now you have a very precise Vhigh and Vlow and a very precise PWM timing, you're set14:17
DocScrutinizer05your capacitor voltage is Vlow + PWM% * (Vhigh - VLOW)14:20
DocScrutinizer05which for 100% PWM = Vhigh ;-)14:20
DocScrutinizer05aka charging14:20
wpwrakVlow (i.e., ADC = 0 V) will be close enough to GND, even if we go for the full 16 bit resolution :) 1 uA * 100 Ohm ~ 2 * 3.3 V >> 16 ;-)14:23
wpwrak(10 or 12 bit probably makes more sense)14:24
DocScrutinizer05well, you have a load current through discharging, via the 3M3, so your Vlow might be higher than 0V0014:25
wpwrakyes, by up to 3.3 V / 3.3 MOhm = 1 uA :)14:25
DocScrutinizer05actually it depends on Vcapacitor too14:25
DocScrutinizer05aaah ok14:26
DocScrutinizer05yes, right14:26
DocScrutinizer05Vcc stability during ramp-down is no problem, after all you're either in charging mode and the slight variation in Vcc will be less than a glitch for this circuit, or you already entered discharging mode where Vcc doesn't matter at all14:44
DocScrutinizer05we also have one 'problem' with this circuit: charging takes as long as discharging, so the recovery window after power return is rather long. No two battery swaps in sequence14:46
DocScrutinizer05well, can get mitigated in software14:47
DocScrutinizer05actually you just need to write history (with timestamps) to storage, to have the complete picture and do the "right thing"14:49
DocScrutinizer05histroy can get deleted as soon as capacitor is supposedly recharged to 100% after a few minutes of charging time14:51
dcht00*************** Announce :)18:20
dcht00New CHT hackbase subseason CHT4-D, MAY/JUNE 2016 @ http://next.totalism.org18:20
dcht00Would be awesome if some of you guys make it18:20
DocScrutinizer05would love to, but seems too much of a dealbraker for my ordinary daywork tasks19:15
whitequarkdcht00: what the hell is that event anyway?19:20
whitequarkI don't get it19:20
dcht00did you try to read from "Start here" ?19:21
whitequarkdcht00: wow that's really interesting19:23
dcht00whitequark thanks - refresh site, i tried to make Context stand out more19:24
whitequarkdcht00: hmmmm i would be interetsted to at least visit19:24
whitequarka few days?19:24
dcht00it's basically hacking in wild canary islands nature ....... on stuff that makes you not die / more comfortable :)19:24
dcht00awesome, all info you need should be on the pad, pls let me know if anything else is unclear19:25
whitequarkdcht00: visa info? I need spanish visa, right?19:30
dcht00whitequark where are you based / nationality?19:31
whitequarklive in hong kong though19:31
whitequarkholy shit the tickets are worth a small fortune19:31
dcht00oh, i have no clue tbh ... i think russians do need a visa for Spain, yeah ... sorry about that19:31
dcht00the whole idea is to have it in Canary Islands which is very cheap and easy to come for EU people19:32
dcht00Hong Kong is quite a stretch19:32
whitequark$1827 and 44 hours one way19:32
dcht00you'd probably make it easier to Hillhacks in India ....... check http://totalism.org/calendar19:32
dcht00another awesome event19:32
whitequark.... I'll pass, a 44 hour flight is too much of a torture itself to pay that much for it lol19:33
DocScrutinizer0544h honestly?19:39
DocScrutinizer05I had a 12h to Teipei from Germany19:40
DocScrutinizer05ok I had a 14h trip from germany to Gomera19:40
DocScrutinizer05this still makes no more than 28h even from HK19:40
DocScrutinizer05also the trip Germany - TPE was a 800EUR iirc19:41
DocScrutinizer05Germany - Gomera was 30019:41
DocScrutinizer05hmm, TPE- Germany twoway might actually be USD 1800 then19:43
DocScrutinizer05anyway, recheck, it sounds like you didn't find the best offer / flight yet19:43
DocScrutinizer05dcht00: I studied the CHT website a few months ago already, thus I knew what it's all about19:47
whitequarkDocScrutinizer05: the others are even more stupidly epxensive and not much shorter20:34
wpwrakDocScrutinizer05: how do you like this one ? https://defuse.ca/b/Get2nVONkfdFVqQaFEkHQc20:39
wpwrakwhitequark: a wild search HKG-LPA, suggests ~USD 1k (in argentina) with 25h10 + 20h15, with KLM and AF. may 5, june 1. (since this seems to be a month-long event ?)20:49
wpwrakthen you just need a boat to make it to lanzarote :)20:51
whitequarkhm, then my search engine fucked up20:54
DocScrutinizer05wpwrak: I'm fixing the code21:01
DocScrutinizer05rather, the algo, I'm prolly fscking up the code ;-)21:02
wpwrakwhitequark: maybe don't search from your iphone ;-)21:04
dcht00DocScrutinizer05 good to see we have friends everywhere :)21:04
dcht00if you send an email saying hi at a random time that'd make my day21:04
whitequarkwpwrak: I don't have an iphone, nor did I search from a smartphone...21:05
wpwrakwhitequark: hehe ;) i was referring to iphone users sometimes getting shown more expensive offers than the rest of humanity21:06
dcht00quick search from me:21:06
dcht0012h + 1200¬ to go from Hong Kong to Germany21:07
whitequarkahhhh, I had no idea21:07
wpwrakDocScrutinizer05: (algo) i used a simple one to illustrate the concept. in real life, there would be more non-linear components, but factoring them in would just make it harder to see the basic idea21:07
dcht00from there it's another 5h to Lanzarote, with some layover21:07
DocScrutinizer05the basic idea needs fixing21:08
dcht00but ....... I honestly wouldn't encourage you to spend 3 grand to travel here :)21:08
dcht00donations of 1% of that are very welcome though21:08
wpwrakwhitequark: it's lanzarote that makes it expensive. to las palmas it's about 1/2 of hkg-lanzarote21:13
wpwrak(didn't try to vary dates. maybe that would change it, too)21:14
wpwrakbut it;s probably best to fly to gran canaria, then make the last hop with a local LCC, or maybe a ferry if that's common there. the local organizers should know21:22
wpwrakthe usual travel sites sometimes don't even list the LCCs, so you miss the most efficient routes21:23
DocScrutinizer05wpwrak: http://paste.opensuse.org/8666984021:25
DocScrutinizer05err linwe 19 is wrong21:26
DocScrutinizer05duty =  ADC_RANGE / adc_0 * 10021:27
wpwrakbtw, argentina just grew some 1.7 million km^2 ;-) http://buenosairesherald.com/article/211476/foreign-ministry-to-unveil-argentinas-continental-shelf-limits-on-monday-21:28
DocScrutinizer05wpwrak: this code is still full of bugs and mess, but it demonstrates the idea21:30
wpwrakno "* 100%" in c-ish syntax ;-)21:30
wpwrakthat's very slow convergence. mine tries to converge much faster. that's especially imporant considering that also PWM goes through 3.3 V, so it may take a lot of time to change Vc1.21:32
DocScrutinizer05yours doesn't converge any way, it's a one time calculation that tries to figure leakage current21:33
wpwrakanyway, in think the main idea is to adjust C1 through PWM and then measure what we got. whether we then operate with deltas or stepwise approximation, is a second order problem21:33
DocScrutinizer05no, the idea is to NOT adjust C1 and keep it at a given ADC value instead. Finmd the PWM duty that matches this condition21:34
wpwrakwell, a bit like euler's method :)21:35
DocScrutinizer05a bit like sigma-delta ADC21:35
wpwrakbut you do adjust C121:35
DocScrutinizer05only temporarily until it changes one tick on ADC so I know if PWM is too high or too low. Then I immediately resore it to its original voltage21:36
DocScrutinizer05actually NOISE_THRESHOLD = 2 ticks21:37
DocScrutinizer05C1's voltage is meant to keep constant (+-2 ticks) during complete PWM-ADC21:38
DocScrutinizer05while PWM gets adjusted so it keeps C1 voltage at that ADC level for long time (NUM_SAMPLES = 20)21:39
DocScrutinizer05you can make NUM_SAMPLES = 2000 if you like21:39
DocScrutinizer05ooh, and that code for sure is no C syntax, rather a tad pythony21:43
DocScrutinizer05only temporarily until it changes one tick on ADC <(abs(adc_t - adc_0) > NOISE_THRESHOLD) ; line25>  so I know if PWM is too high or too low <(adc_t - adc_0) >0; line28>21:47
DocScrutinizer05Then I immediately restore it to its original voltage <lines 29-32, 34-37>21:48
DocScrutinizer05lines 31, 36 are >> // adjust duty TODO: short hack, optimize!<< and actually need optimization21:49
DocScrutinizer05there Euler comes in21:50
DocScrutinizer05N +- N/2 +- N/4...21:50
wpwrakthose duty++ and duty-- should be outside the loops, right ?21:51
DocScrutinizer05not really, I kept them inside the loops since duty needs the more adjustment the longer recovery takes21:52
DocScrutinizer05might overshoot though21:52
DocScrutinizer05you could keep them outside the loops too21:53
DocScrutinizer05but ideally you find some sort of Euler, based on i counter in 22-2521:54
DocScrutinizer05the 22-25 loop will iterate the longer, the closer duty is to the target21:54
DocScrutinizer05so for higher i, the duty adjustment should be lower21:55
DocScrutinizer05duty++ and -- are really just meant symbolic21:56
wpwrakyeah, you'd probably want some t++ and then duty += f(t) or such21:57
DocScrutinizer05((will iterate the longer...)) when it iterates > NUM_SAMPLES times, duty is considered perfect21:57
DocScrutinizer05oops is it t?21:57
DocScrutinizer05no it's i, line 2121:57
wpwrakt for the time you "correct"21:57
wpwraka new variable21:57
DocScrutinizer0525: until ((i++ > NUM_SAMPLES) or (abs(adc_t - adc_0) > NOISE_THRESHOLD))21:58
wpwraksince duty is measured in adc counts, while the correction loops count in loop counts21:58
wpwrak(i++) hehe :)21:59
DocScrutinizer05duty is measured in percent21:59
DocScrutinizer05line 621:59
wpwraki just used a float ;-)21:59
DocScrutinizer05you prolly want to make that ppm21:59
wpwrakpolly some obscure implementation-dependent unit :)22:00
DocScrutinizer05nah, it's a plain simple integer, see line622:00
DocScrutinizer05and line322:01
DocScrutinizer05make line6  usleep(100000 - pw) or whatever you like22:02
DocScrutinizer05it determines range of duty and frequency of PWM22:02
wpwraksure, in the end it's an integer. everything is :)22:02
DocScrutinizer05this one reasonably is a 12 to 16bit integrer, unsigned22:03
DocScrutinizer05it doesn't make sense to have it higher precision than your ADC can do and actually does22:04
DocScrutinizer05you also can't feed a real to usleep22:05
wpwraki have my own timekeeping anyway. well, i do happen to have a function called usleep ...22:08
DocScrutinizer05http://paste.opensuse.org/80816228 even22:17
DocScrutinizer05usleep(MAXPWM) is the frequency (actually period) of your PWM signal22:18
DocScrutinizer05if you need higher resolution (higher MAXPWM) and same time higher PWM frequency, you should divide all parameters to usleep() by a constant factor22:20
DocScrutinizer05one more bug smashed: http://paste.opensuse.org/2051757222:27
DocScrutinizer05now I actually should add (C) GPL2 J.R. to this22:27
DocScrutinizer05the shorter the code, the better ;-)22:28
DocScrutinizer05s/ (adc_t - adc_0) >0)  /  (adc_t > adc_0)  /22:33
DocScrutinizer05wpwrak: ^^^22:34
wpwrakyeah :)22:36
wpwraki just c-ified it22:36
DocScrutinizer05highly welcome22:36
DocScrutinizer05it's crap, syntax wise22:37
DocScrutinizer05heck, I wrote my last c code some maybe 6 years ago22:37
wpwrakmmh. two small bugs22:38
DocScrutinizer05  // sample Vc1 + Ileak(t0) * R1, sounds odd22:39
DocScrutinizer05well, maybe it's actually correct, however puzzling#22:39
wpwrakadd "Vadc =" ?22:41
wpwrakor what is the puzzling bit ?22:41
DocScrutinizer05the equation is puzzling me22:43
DocScrutinizer05yes, it's actually correct22:44
DocScrutinizer05I'd write "sample relative Vc1"22:44
wpwrakmaking it  sample Vadc = Vc1 + Ileak(t0) * R122:44
DocScrutinizer05it's a tad out of scope how Ileak calculates Vadc here22:45
wpwrakelse i need to define what a "relative Vc1" is22:45
DocScrutinizer05now you need to define what Ileak is ;-)22:45
wpwrakoh, didn't i talk enough about leakage current before ? :)22:45
DocScrutinizer05here yes ;-D22:45
wpwrakin the mail, too ;-)22:45
DocScrutinizer05aah ok22:45
DocScrutinizer05well nevermind22:46
DocScrutinizer05I'm ore worried about INCREMENT22:46
DocScrutinizer05and heck, another bug22:46
DocScrutinizer05http://paste.opensuse.org/58706276 fixed22:48
DocScrutinizer05(took the pwm adj out of the loop)22:48
wpwrakposted: http://lists.en.qi-hardware.com/pipermail/discussion/2016-March/011021.html22:48
DocScrutinizer05you also might actually want to probe for (and use) V3_3 instead of using a constant22:49
DocScrutinizer05and line3022:49
DocScrutinizer05the rest looks good to me22:50
wpwrakit's not real code. 3.3 is just 3.3 V :)22:51
DocScrutinizer05s/do pulse(100);/do pulse(1.0);/22:51
DocScrutinizer05yes, but 3.3V is not warranted22:52
DocScrutinizer05this is actually Vio_h22:52
wpwrakyes, fixed in the post22:52
wpwraksure. but Vio_h(I very tiny) is Vcc is 3.3 V22:53
wpwrakelse something is broken :)22:53
DocScrutinizer05for me INCREMENT is (NUM_SAMPLES - i)22:53
DocScrutinizer05for you it's SAMPLES - i22:54
DocScrutinizer05SAMPLES/i ?22:54
DocScrutinizer05a real 0<=duty<=1 is really messy to handle22:55
wpwraki think one would want to calculate the quanta that went into or out of C122:55
DocScrutinizer05duty +- i/SAMPLES, now that looks correct22:56
wpwrakprobably more complicated. but i'm too lazy to do the math now :)22:57
DocScrutinizer05me too ;-)22:57
wpwrakand with a little luck there may be a simple direct temperature correction that works just as well, and we don't need all this ;-)22:58
DocScrutinizer05 During all this, we read back Vc1 with the ADC (which is affected  by leakage) AND COMPARE IT TO INITIALLY READ VALUE. If the values read back stay long enough AT INITIAL VALUE within the  expected noise bounds, our duty cycle matches the correct Vc1  voltage23:00
wpwraksomething like Ileak = 25 nA * max(1, tempC - 25) * (3.3 / 2 - real_Vc1);   // or such23:01
wpwrakit's already posted :) let's see if anyone has questions23:01
DocScrutinizer05s/  For faster convergence, INCREMENT should be a function of the time it  took to pull Vc1 back to the original value./ For faster convergence, INCREMENT should be a function of the time it  took to pull Vc1 AWAY FROM THE original value./23:02
wpwrakthat may be easier, indeed. i was thinking of some f(t, duty)23:03
wpwrakbut again, one would have to do the math. not sure if duty really disappears if you use i23:03
DocScrutinizer05lost me on the second half23:04
wpwraki'm not sure if it's just a function of "i", or if it would still be a function of i and "duty"23:05
DocScrutinizer05duty += i/SAMPLES23:05
DocScrutinizer05resp -=23:05
wpwrakas i said, too lazy to do the math :)23:06
DocScrutinizer05s$ INCREMENT $ i/SAMPLES $23:06
DocScrutinizer05s$ INCREMENT $ (i/SAMPLES / 4) $23:07
DocScrutinizer05or whatever factor works best23:07
DocScrutinizer05it's just an optimization, you can spend weeks to optimize the optimization, or just go 'Meh!'23:08
DocScrutinizer05it just should converge23:08
DocScrutinizer05too high feedback and you get oscillation23:09
DocScrutinizer05anyway, time to search the eggs ;-)23:16
wpwrak(oscillation) yes, and the thing needs some more timeouts anyway, right now, it could easily loop somewhere forever23:34
--- Mon Mar 28 201600:00

Generated by irclog2html.py 2.9.2 by Marius Gedminas - find it at mg.pov.lt!