Navigation

    mono community

    Mono

    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Search
    1. Home
    2. malaire
    3. Best
    M
    • Chat with malaire
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Best posts made by malaire

    • RE: Reading battery voltage?

      I created small battery-logger app for Mono, which shows voltage on screen and also logs to SD card -- my first app :)

      After my Mono is recharged, I'll get complete log from full battery until Mono shuts down because of low battery, and then try to determine how to calculate battery-percentage.

      posted in Mono Framework
      M
      malaire
    • RE: Should Alarm Clock be working? [SOLVED]

      I just received new replacement Mono, and after some initial testing I've seen no problems at all with sleep.

      So it seems that my problems were caused by faulty Mono. (I'll update title and first post accordingly.)

      posted in Issues & Troubleshooting
      M
      malaire
    • RE: Reading battery voltage?

      @stoffera said in Reading battery voltage?:

      Gist with code: https://gist.github.com/stoffera/9ce4704c3cb2044b7a017fcced95ab74

      Be aware that the measure is quite noisy - so you will need to do some filtering.

      I'm now experimenting with different filtering methods. I'm currently trying initial delay of 50 µs, then 10 µs delay between samples, and taking average of 64 samples. Result seems quite stable and I can even watch value go down few mV at a time. (This measurement takes a bit under 1200 µs total.)

      Here is current code as single method:

      // BASED ON psoc_battery_voltage.{cpp,h}
      // https://gist.github.com/stoffera/9ce4704c3cb2044b7a017fcced95ab74
      uint16_t AppController::readBatteryVoltage() {
        static const uint32_t RawAdcMax = 0xFFF;
        static const uint32_t ReferenceVoltage = 0x400;
        static const uint32_t CorrectionFactor = 1588;
        static const uint32_t CorrectDenominator = 1000;
        static const uint32_t CorrectionOffset = 440;
      
        static const uint32_t CorrectionScale =
          RawAdcMax*CorrectionFactor/CorrectDenominator*ReferenceVoltage;
      
        static bool isStarted = false;
        if (!isStarted) {
            ADC_SAR_1_Start();
            isStarted = true;
        }
      
        // Disconnect AMUXBUSL ; Connect AG5 / CMP2 to AG5 / vref to CMP2
        CY_SET_REG8(CYDEV_ANAIF_RT_SAR0_SW3, CY_GET_REG8(CYDEV_ANAIF_RT_SAR0_SW3) & ~0x01);
        CY_SET_REG8(CYDEV_ANAIF_RT_SAR0_SW0, CY_GET_REG8(CYDEV_ANAIF_RT_SAR0_SW0) | 0x20);
        CY_SET_REG8(CYDEV_ANAIF_RT_CMP2_SW4, CY_GET_REG8(CYDEV_ANAIF_RT_CMP2_SW4) | 0x20);
        CY_SET_REG8(CYDEV_ANAIF_RT_CMP2_SW3, CY_GET_REG8(CYDEV_ANAIF_RT_CMP2_SW3) | 0x20);
      
        // wait for voltage level to settle
        wait_us(50);
      
        uint32_t count_log = 6;
        uint32_t sum = 0;
        for (uint32_t n = 0; n < (uint32_t)1 << count_log; n++) {
          ADC_SAR_1_StartConvert();
          ADC_SAR_1_IsEndConversion(ADC_SAR_1_WAIT_FOR_RESULT);
          uint16_t reading = ADC_SAR_1_GetResult16();
          
          // After reset value seems to stay at 0 for some time.
          // In that case don't try to calculate average, just return 0.
          if (reading == 0) return 0;    
          
          sum += ADC_SAR_1_GetResult16();
          wait_us(10);
        }
        uint32_t avg = sum >> count_log;
      
        // Disconnect CMP2 from vref and AG5 / AG5 from ADC ; Connect ADC to AMUXBUSL
        CY_SET_REG8(CYDEV_ANAIF_RT_CMP2_SW4, CY_GET_REG8(CYDEV_ANAIF_RT_CMP2_SW4) & ~0x20);
        CY_SET_REG8(CYDEV_ANAIF_RT_CMP2_SW3, CY_GET_REG8(CYDEV_ANAIF_RT_CMP2_SW3) & ~0x20);
        CY_SET_REG8(CYDEV_ANAIF_RT_SAR0_SW0, CY_GET_REG8(CYDEV_ANAIF_RT_SAR0_SW0) & ~0x20);
        CY_SET_REG8(CYDEV_ANAIF_RT_SAR0_SW3, CY_GET_REG8(CYDEV_ANAIF_RT_SAR0_SW3) | 0x01);
      
        // scale from 12 bit ADC to mV
        return CorrectionScale / avg + CorrectionOffset;
      }
      

      EDIT: And I just noticed a bug - the "return 0" special case I added doesn't restore state properly.

      posted in Mono Framework
      M
      malaire
    • RE: Reading battery voltage?

      When calculating percentage of battery remaining, linear error doesn't really matter as long as conversion from mV to percents is calibrated with same error.

      I just got first graph from full battery to Mono shutting off (which took about 3.5 hours). This seems to be quite easy to approximate with few linear parts. At least initially I'm happy with about 10% accuracy and without any temperature compensation (but even that might also be doable since Mono has thermometer - but it would require more data and more complex calculations).

      0_1490951407596_battery-voltage.png

      posted in Mono Framework
      M
      malaire
    • RE: Reading battery voltage?

      With three logs so far, discharge graph is nearly equal between logs, except at around 16% to 23% percent remaining, where there are significant variations.

      The 'Combined' line here is what my script calculates, and battery percentage is then determined based on that.

      0_1491167385280_three-logs.png

      posted in Mono Framework
      M
      malaire
    • RE: Reading battery voltage?

      @stoffera said in Reading battery voltage?:

      @malaire, this is great :-) ! We should put this into the framework!

      May I suggest a class that lives in the namespace mono::power and that can return the remaining percentage of battery charge.

      Maybe just extend the BatteryPower class I sent you some days ago. Tell me what you think.

      Sounds good. I'll test this few days to see if there are any problems, and I'll also add few changes:

      • return <0 when percentage can't be calculated (e.g. -1 when charging, -2 when mV is zero)
      • include internal battery_percent_mV table, but allow overriding it with custom table
      • manually "fix" the graph between 16% to 23% so that it's a straight line there
      posted in Mono Framework
      M
      malaire
    • RE: What editor do you use?

      I've been using Geany for few years, mainly on Linux although it does claim to be cross-platform. (About Geany)

      (And Vim when I have to work on command-line.)

      posted in General Discussion
      M
      malaire
    • RE: What editor do you use?

      @stoffera said in What editor do you use?:

      @malaire does Geany use anything similar to Sublime Text config files?

      I am thinking about adding support for these files in monomake. In Sublime Text the project json config seems to be pretty generic.

      Geany uses ini-file syntax for project files, with .geany extension, which isn't quite as easy to understand as json, especially for build-related options.

      Geany manual has some documentation about syntax at Configuration Files

      I havn't tried build-settings of Geany much as I usually prefer to compile in separate console with custom makefile. I did a quick test with C and generated project-file looks like this:

      [editor]
      line_wrapping=false
      line_break_column=80
      auto_continue_multiline=true
      
      [file_prefs]
      final_new_line=true
      ensure_convert_new_lines=false
      strip_trailing_spaces=false
      replace_tabs=true
      
      [indentation]
      indent_width=2
      indent_type=0
      indent_hard_tab_width=8
      detect_indent=false
      detect_indent_width=false
      indent_mode=2
      
      [project]
      name=Test
      base_path=/home/malaire/
      description=
      file_patterns=
      
      [long line marker]
      long_line_behaviour=1
      long_line_column=80
      
      [files]
      current_page=0
      FILE_NAME_0=23;C;0;EUTF-8;0;1;0;%2Fhome%2Fmalaire%2Ftest.c;0;2
      
      [build-menu]
      CFT_01_LB=_Build
      CFT_01_CM=gcc -Wall -Wextra -o "%e" "%f"
      CFT_01_WD=
      filetypes=C;
      CFT_00_LB=_Compile
      CFT_00_CM=gcc -Wall -Wextra -c "%f"
      CFT_00_WD=
      posted in General Discussion
      M
      malaire