2 years agospeedometer.scad: second printed version master
Jan "Yenya" Kasprzak [Mon, 21 Sep 2015 15:18:55 +0000 (17:18 +0200)]
speedometer.scad: second printed version

2 years agoSpeedometer illumination
Jan "Yenya" Kasprzak [Thu, 17 Sep 2015 13:53:42 +0000 (15:53 +0200)]
Speedometer illumination

3 years agorearlight.scad: thicker upper clip
Jan "Yenya" Kasprzak [Wed, 22 Oct 2014 08:08:28 +0000 (10:08 +0200)]
rearlight.scad: thicker upper clip

3 years agoambient.c: fixup, disable shadow code
Jan "Yenya" Kasprzak [Fri, 18 Apr 2014 16:24:06 +0000 (18:24 +0200)]
ambient.c: fixup, disable shadow code

3 years agoambient.c: adjustments for Yenya
Jan "Yenya" Kasprzak [Sat, 12 Apr 2014 20:23:16 +0000 (22:23 +0200)]
ambient.c: adjustments for Yenya

- move the border between evening and dawn to brighter area
- move the border between dawn and day to brighter area

3 years ago5th brightness 2500 mA
Jan "Yenya" Kasprzak [Sat, 12 Apr 2014 20:22:32 +0000 (22:22 +0200)]
5th brightness 2500 mA

- use it in the daylight, and use brighter light in the night.

3 years agofw/Makefile: explicitly set the usbasp speed
Jan "Yenya" Kasprzak [Sat, 12 Apr 2014 20:11:02 +0000 (22:11 +0200)]
fw/Makefile: explicitly set the usbasp speed

4 years agorearlight.scad: printed - hopefully final - version
Jan "Yenya" Kasprzak [Mon, 28 Oct 2013 23:22:38 +0000 (00:22 +0100)]
rearlight.scad: printed - hopefully final - version

4 years agorearlight.scad: first printed version
Jan "Yenya" Kasprzak [Sun, 27 Oct 2013 09:25:24 +0000 (10:25 +0100)]
rearlight.scad: first printed version

- make rear spring a bit stronger
- wall_thickness could probably be lowered to 1.5mm
- fraen_h should be lowered about 0.5-1mm
- side barriers are too high
- clip_angle is too big - about 18 degrees should be enough

- bolt sizes
- side LED hole size
- cable hole

we use elliptical beam lens, so for two lenses it could make sense
to not have the clip and lens axis parallel, but instead to make
it shine more to the side.

4 years agorearlight.scad: new holder, not yet connected to the main object
Jan "Yenya" Kasprzak [Sat, 26 Oct 2013 15:37:48 +0000 (17:37 +0200)]
rearlight.scad: new holder, not yet connected to the main object

4 years agorearlight.scad: another iteration
Jan "Yenya" Kasprzak [Sat, 26 Oct 2013 12:24:24 +0000 (14:24 +0200)]
rearlight.scad: another iteration

4 years agoMerge branch 'master' of ssh://
Jan "Yenya" Kasprzak [Mon, 28 Oct 2013 21:18:09 +0000 (22:18 +0100)]
Merge branch 'master' of ssh://

4 years agorearlight.scad: yet another attempt
Jan "Yenya" Kasprzak [Fri, 25 Oct 2013 06:08:48 +0000 (08:08 +0200)]
rearlight.scad: yet another attempt

4 years agorearlight.scad: rear light holder for AZUB
Jan "Yenya" Kasprzak [Fri, 18 Oct 2013 06:46:25 +0000 (08:46 +0200)]
rearlight.scad: rear light holder for AZUB

4 years agoAdjustments for Yenya
Jan "Yenya" Kasprzak [Tue, 15 Oct 2013 06:43:19 +0000 (08:43 +0200)]
Adjustments for Yenya

4 years agopart/statuslight.scad: holder for AZUB recumbents
Jan "Yenya" Kasprzak [Sat, 21 Sep 2013 20:53:47 +0000 (22:53 +0200)]
part/statuslight.scad: holder for AZUB recumbents

This is a status lights holder for AZUB recumbents (mine is AZUB Apus).
It is supposed to be installed on top of the front derailler tube.
The bottom hole is for speedometer illumination LED, and the rear hole
is for error/status LED.

The front derailler tube is -35 degrees from the horizontal plane,
and the line of sight (for the status LED) is + 15 degrees above
the horizontal plane. It is designed for 3mm LEDs.

This is a quick and dirty work, it is not parametrized enough.
FIXME: It would be better to have the object internal hole as two
cones, each for one of LEDs - it would simplify the LED installation.

4 years agoDatasheet for older white LED
Jan "Yenya" Kasprzak [Thu, 27 Jun 2013 16:09:37 +0000 (18:09 +0200)]
Datasheet for older white LED

4 years agoambient.c: adjustments
Jan "Yenya" Kasprzak [Tue, 23 Jul 2013 23:00:41 +0000 (01:00 +0200)]
ambient.c: adjustments

4 years agoambient.c: adjustments for Yenya
Jan "Yenya" Kasprzak [Mon, 22 Jul 2013 21:15:13 +0000 (23:15 +0200)]
ambient.c: adjustments for Yenya

4 years agomain.c: don't log ambient lights too often
Jan "Yenya" Kasprzak [Mon, 22 Jul 2013 21:00:40 +0000 (23:00 +0200)]
main.c: don't log ambient lights too often

4 years agoambient.c: longer log; adjustments for Pavlina
Jan "Yenya" Kasprzak [Mon, 22 Jul 2013 21:00:19 +0000 (23:00 +0200)]
ambient.c: longer log; adjustments for Pavlina

4 years agopwmled.c: night rear light is too bright
Jan "Yenya" Kasprzak [Sun, 21 Jul 2013 21:47:05 +0000 (23:47 +0200)]
pwmled.c: night rear light is too bright

4 years agoambient.c: settings for my wife's bike
Jan "Yenya" Kasprzak [Sun, 21 Jul 2013 21:45:35 +0000 (23:45 +0200)]
ambient.c: settings for my wife's bike

4 years agomain.c: slower ambient light logging
Jan "Yenya" Kasprzak [Sun, 21 Jul 2013 21:44:14 +0000 (23:44 +0200)]
main.c: slower ambient light logging

4 years agopwmled.c: mode stabilization
Jan "Yenya" Kasprzak [Fri, 19 Jul 2013 21:03:57 +0000 (23:03 +0200)]
pwmled.c: mode stabilization

When changing brightness via pwmled_set_brightness() below,
we want to converge to the target value as fast as possible. Also,
we would like to somehow initialize the mode 3, which is used as
"mode 2 + other PWMLED on". So after the brightness is set,
we also set pwmleds[n].modes_not_yet_stable to MODE_STABILIZATION_TIME.
When modes_not_yet_stable is non-zero, we allow only mode 2 to be set
regardless of what is fed to pwmled_set_mode. We will then converge
to the target value of mode 2 only, and after MODE_STABILIZATION_TIME
ADC measurements, we copy the mode_pwm value to all other modes.
Only then it is allowed to set the other modes.

4 years agoambient.c: "entering shadow" detection
Jan "Yenya" Kasprzak [Fri, 19 Jul 2013 19:45:27 +0000 (21:45 +0200)]
ambient.c: "entering shadow" detection

We try to detect the rapid decrease in the ambient light level,
such as when entering the dark area (tunnel, deep shadow, etc.).
When this happens, we keep the previous (high) ambient zone,
and use the night pattern (front light continuously on) for at least
3 seconds, to give the rider's eyes the opportunity to adapt.

4 years agobuttons.c: faster brake sensor reaction time
Jan "Yenya" Kasprzak [Fri, 19 Jul 2013 16:28:20 +0000 (18:28 +0200)]
buttons.c: faster brake sensor reaction time

If the ADC reads as "brake on" for two jiffies (1/8 of second),
consider it being on. Previously the interval was too long (1/4 s).

4 years agoError flags, error reporting
Jan "Yenya" Kasprzak [Fri, 19 Jul 2013 16:16:20 +0000 (18:16 +0200)]
Error flags, error reporting

- all error flags are in the bit array err_flags, including braking and
  booting (this is unused yet, the idea is to report successful boot and
  pwmled init somehow).
- error status is reported as num_pattern(err, 1) by the status LED
- error status (if any) can be cleared by pressing the button 1
  (which takes precedence over the panic mode)

4 years agoambient.c: logging modification
Jan "Yenya" Kasprzak [Fri, 19 Jul 2013 16:13:40 +0000 (18:13 +0200)]
ambient.c: logging modification

- log min/max based on the slow value
- log unshifted max-min difference (from 0 to 15)

4 years agoambient.c: zone adjustments
Jan "Yenya" Kasprzak [Fri, 19 Jul 2013 16:13:27 +0000 (18:13 +0200)]
ambient.c: zone adjustments

4 years agoambient.c: rewrite
Jan "Yenya" Kasprzak [Thu, 18 Jul 2013 21:29:32 +0000 (23:29 +0200)]
ambient.c: rewrite

We now measure two running averages - ambient_slow and ambient_fast.
The _fast is computed based on the ADC readings and few bits of averaging.
The _slow is computed based on _fast and few bits of averaging.

We don't want to change the zone too often, but on the other hand,
we want fast reaction to the strong ambient light level changes.
So we compute the new ambient zone based on _fast, and when the new
one is current one +1 or -1, we retry using the _slow value.
Only when even the _slow suggests that the ambient zone has changed,
we permit the change to the neighbouring level. Changes to the more distant
zone are permitted immediately.

Also the logging rewritten to accomodate minimum, a few bits of
max-min, and a few bits of level drop.

4 years agocontrol.c: brighter lights in ambient zone 0
Jan "Yenya" Kasprzak [Thu, 18 Jul 2013 20:12:20 +0000 (22:12 +0200)]
control.c: brighter lights in ambient zone 0

4 years agopwmled.c: current adjustments
Jan "Yenya" Kasprzak [Thu, 18 Jul 2013 20:10:40 +0000 (22:10 +0200)]
pwmled.c: current adjustments

4 years agoambient.c: ambient light zone adjustments
Jan "Yenya" Kasprzak [Thu, 18 Jul 2013 20:07:42 +0000 (22:07 +0200)]
ambient.c: ambient light zone adjustments

4 years agoambient.c: user-settable ambient light zone
Jan "Yenya" Kasprzak [Thu, 4 Jul 2013 22:59:21 +0000 (00:59 +0200)]
ambient.c: user-settable ambient light zone

User-settable parameter 0 is now the ambient light zone:
Value 0 means to use the ambient light sensor,
values 1 .. N_AMBIENT_ZONES represent the manually set light level.

4 years agobuttons.c: setup mode rework
Jan "Yenya" Kasprzak [Thu, 4 Jul 2013 22:51:29 +0000 (00:51 +0200)]
buttons.c: setup mode rework

See the comment near the top of buttons.c for the description of how
the setup mode works.

4 years agoadc.c: sub-LSB resolution of PWM
Jan "Yenya" Kasprzak [Tue, 2 Jul 2013 10:06:26 +0000 (12:06 +0200)]
adc.c: sub-LSB resolution of PWM

Simulate a sub-LSB resolution inside the ADC IRQ handler. We do multiple
measurements of PWMLED resistor anyway, so it makes sense to modify the
PWM value after each reading. And indeed, experiments show less flicker
of PWM LEDs with this patch.

It is probably an overkill, and can be called only when measuring the
PWMLED output (and not ambient light sensor, for example). But it works
and it is simple enough.

4 years agoadc.c: abort the current reading when the timer expires
Jan "Yenya" Kasprzak [Tue, 2 Jul 2013 10:03:19 +0000 (12:03 +0200)]
adc.c: abort the current reading when the timer expires

Inside the timer interrupt, we may have changed the PWM outputs,
so the reading of ADC will be useless. Drop it in this case.

FIXME: possible race condition against timer IRQ.

4 years agoambient.c: more hysteresis for "full daylight"
Jan "Yenya" Kasprzak [Mon, 1 Jul 2013 19:58:40 +0000 (21:58 +0200)]
ambient.c: more hysteresis for "full daylight"

4 years agoMerge branch 'sync_patterns'
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 22:21:46 +0000 (00:21 +0200)]
Merge branch 'sync_patterns'

This branch implements handling all three pwmleds in one pattern
in order to avoid having multiple outputs on simultaneously (when possible).

Also, this separates brightness settings from patterns, so we can have
only one blinking pattern for more ambient light levels, and set the
brightness (current) of the pattern separately.

4 years agopattern.c: another attempt at brake handling
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 22:19:52 +0000 (00:19 +0200)]
pattern.c: another attempt at brake handling

- set read pwmled (0) to mode 2 when braking unconditionally

4 years agopattern.c: alternative brake handling
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 22:15:19 +0000 (00:15 +0200)]
pattern.c: alternative brake handling

- when braking, and pwmled0 (read) should be off, we set it to mode 1,
otherwise, we set it to mode 2.

4 years agocontrol.c: night pattern fix
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 22:14:38 +0000 (00:14 +0200)]
control.c: night pattern fix

Use pwmled2 mode 2 for standalone, and mode 3 for pwmled2+0,
to be consistent with brake handling in pattern.c.

4 years agologic for setting brightness
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 21:55:59 +0000 (23:55 +0200)]
logic for setting brightness

We set the brightness in an universal function pwmled_select_brightness(),
and this function is called on various events, such as
- ambient light zone change
- dim mode toggle

For now, dim mode means different brightness only for night-ish modes,
because for day modes, slow_pattern uses level 1 as main brightness.

4 years agopwmled.c: new current values
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 21:53:52 +0000 (23:53 +0200)]
pwmled.c: new current values

4 years agopwmled: verify the input of pwmled_set_brightness
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 21:53:11 +0000 (23:53 +0200)]
pwmled: verify the input of pwmled_set_brightness

Also allow different number of current levels for each output

4 years agocontrol.c: test pattern for debugging pwmleds
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 21:48:54 +0000 (23:48 +0200)]
control.c: test pattern for debugging pwmleds

4 years agobraking is handled behind the patterns inside pattern.c
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 20:35:37 +0000 (22:35 +0200)]
braking is handled behind the patterns inside pattern.c

See the comment above pwmled_update_mode():

This is tricky: we use a single pattern for all three pwmleds,
but on some occasions, we want to be able to modify only a single
pwmled status without affecting other outputs. For example, during
braking, we want to modify only the rear pwmled status. We don't
use a separate "braking" pattern for every other pattern used, but instead
we change the pwmled0 status regardless of the original value when
braking. The rule is the following:
- if during braking the pwmled2 (front) is at mode 2, we switch it to
    mode 3 (which has the same target current) to avoid flicker.
- if pwmled0 (rear) is off, we set it to mode 2
    (if it is with mode 1, we keep it at mode 1)
TODO: something similar should be done for the "entering the dark area"
    condition, where we want to switch pwmled2 (front) on, to mode 2.

4 years agocontrol.c: new multi-pwmled panic pattern
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 20:06:20 +0000 (22:06 +0200)]
control.c: new multi-pwmled panic pattern

4 years agopattern.c: pwmled setting refactorization
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 19:52:33 +0000 (21:52 +0200)]
pattern.c: pwmled setting refactorization

4 years agoCommon patterns rewrite
Jan "Yenya" Kasprzak [Tue, 25 Jun 2013 21:41:04 +0000 (23:41 +0200)]
Common patterns rewrite

slowN_pattern, normalN_pattern, and onN_pattern for N=(1..4)
rewritten to be brightness-independent, and to avoid switching
multiple outputs on at once, if possible.
If not (such as when PWMLED 2 is continuously on), use mode 2 and 3
with the same target current to accomodate for different battery voltages
when more than one output is running.

TODO: actually set brightness based on various conditions, such as
ambient lights, user-requested dim mode, etc.

4 years agoGitignore firmware/version.c
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 12:36:30 +0000 (14:36 +0200)]
Gitignore firmware/version.c

Generated by, ignore it.

4 years agopwmled: do not probe pwmleds
Jan "Yenya" Kasprzak [Tue, 25 Jun 2013 20:20:04 +0000 (22:20 +0200)]
pwmled: do not probe pwmleds

... just wait for them to be used by pattern.c.
TODO: remove the probing code altogether.

4 years agopwmled: faster regulation
Jan "Yenya" Kasprzak [Tue, 25 Jun 2013 20:17:45 +0000 (22:17 +0200)]
pwmled: faster regulation

4 years agopwmled.c: reload ADC target data after setting the brightness
Jan "Yenya" Kasprzak [Tue, 25 Jun 2013 20:16:47 +0000 (22:16 +0200)]
pwmled.c: reload ADC target data after setting the brightness

4 years agoPWMLED: proof-of-concept brightness setting
Jan "Yenya" Kasprzak [Tue, 18 Jun 2013 15:36:41 +0000 (17:36 +0200)]
PWMLED: proof-of-concept brightness setting

In order to save space for patterns, we set the brightness
independently from pattern. Each brightness has only two levels
for PWMLED 0 and 2, and one for PWMLED 1. Patterns can then use
two-bit values for each PWMLED (one-bit for PWMLED 1), with the
following meaning:

0: off
1: level 1
2: level 2
3: also level 2, with a separate state stored. This can be used for
saving regulation value for a single current level with
and without other outputs running, or with different levels
of other output. This is in order to avoid flicker when one
PWMLED (usually the front one) is steady on, and the others
are blinking.

4 years agoPWM LEDs driven by a single pattern
Jan "Yenya" Kasprzak [Tue, 18 Jun 2013 14:34:33 +0000 (16:34 +0200)]
PWM LEDs driven by a single pattern

Pattern sources renumbered:

0 - all three PWM LEDs
1 - status led
2 - illumination LED
4 - laser LED

4 years agoDatasheets added
Jan "Yenya" Kasprzak [Wed, 26 Jun 2013 09:01:25 +0000 (11:01 +0200)]
Datasheets added

Cree XM-L2
Cree XP-G2

LED optics:
Ledil Leila for XP-G and XM-L
Fraen for Luxeons

4 years agoambient.c: zone adjustments
Jan "Yenya" Kasprzak [Tue, 25 Jun 2013 21:51:11 +0000 (23:51 +0200)]
ambient.c: zone adjustments

4 years agoInclude date and git revision in the eeprom variable
Jan "Yenya" Kasprzak [Tue, 25 Jun 2013 20:26:33 +0000 (22:26 +0200)]
Include date and git revision in the eeprom variable

... in order to be able to find out which firmware version is this MCU
running. This roughly corresponds to the commit
of project Tinyboard.

4 years agoambient.c: log maximum and drop instead of min and drop
Jan "Yenya" Kasprzak [Thu, 13 Jun 2013 22:17:53 +0000 (00:17 +0200)]
ambient.c: log maximum and drop instead of min and drop

4 years agoambient zone adjustments
Jan "Yenya" Kasprzak [Thu, 13 Jun 2013 22:13:18 +0000 (00:13 +0200)]
ambient zone adjustments

The system switched to "darkness" mode too early.

4 years agomain.c: log the ambient light stats more often
Jan "Yenya" Kasprzak [Thu, 13 Jun 2013 19:19:10 +0000 (21:19 +0200)]
main.c: log the ambient light stats more often

4 years agologging.c: shorten the log buffer
Jan "Yenya" Kasprzak [Thu, 13 Jun 2013 19:16:51 +0000 (21:16 +0200)]
logging.c: shorten the log buffer

We are overflowing the stack, save the data segment space by
shortening the log double buffer in RAM.

4 years agoambient.c: detect drop of ambient light
Jan "Yenya" Kasprzak [Thu, 13 Jun 2013 19:14:30 +0000 (21:14 +0200)]
ambient.c: detect drop of ambient light

Measure also longer-term running average of ambient light values,
and log instead of minima and maxima of adc readings the diffrence
between this longer-term average and normal avereage (ambient_val).
This is so that we would be able to switch the front light on when
entering a darkish area from the bright sun.

4 years agoambient.c: adjustments for maximum zone
Jan "Yenya" Kasprzak [Thu, 13 Jun 2013 18:50:37 +0000 (20:50 +0200)]
ambient.c: adjustments for maximum zone

4 years agoDatasheet for lxhl-bd01 high-power red LED
Jan "Yenya" Kasprzak [Tue, 11 Jun 2013 10:54:24 +0000 (12:54 +0200)]
Datasheet for lxhl-bd01 high-power red LED

4 years agoTimer handling moved to the main thread
Jan "Yenya" Kasprzak [Fri, 7 Jun 2013 16:15:11 +0000 (18:15 +0200)]
Timer handling moved to the main thread

In order to mitigate the problem with watchdog reset, possibly caused
by timer IRQ handling taking too long, we only increment the jiffies
value in the WDT IRQ handler, and then read this value in the main
loop, compare with the previous one, and if those two are different,
we run the timer-induced operations. We can (probably) detect the
timer overrun (the difference in jiffies being greater than 1), and log

The individual timer-induced operations are run in their own atomic
blocks for now, in order to be safe. The finer-grained locking is
in the TODO list :-).

4 years agomain.c: split up the main() function
Jan "Yenya" Kasprzak [Fri, 7 Jun 2013 16:00:31 +0000 (18:00 +0200)]
main.c: split up the main() function

- early HW setup, run once after reset, is moved to the first_boot()
- main loop iteration is in a separate function main_loop_iteration()
- both functions (and hw_suspend() as well) are made inline

4 years agoDisable WDT as early as possible
Jan "Yenya" Kasprzak [Fri, 7 Jun 2013 15:42:10 +0000 (17:42 +0200)]
Disable WDT as early as possible

Apparently, after WDT reset, WDT is still running, and has to be
disabled. Otherwise it will kick in again during the initialization.

We want to indicate the WDT reset contition somehow. We use the GPIO
LED 0 - we set it to on if the reset source was WDT.

Also, we want to read and reset MCUSR as early as possible. We do it
from main(), and we then send the saved value where needed (init_log()
and power_down()).

4 years agopatterns: fibonacci-scaled step duration
Jan "Yenya" Kasprzak [Tue, 4 Jun 2013 16:04:35 +0000 (18:04 +0200)]
patterns: fibonacci-scaled step duration

We have only three bits for pattern duration now,
use Fibonacci-compressed values: instead of 0-7,
use 0, 1, 2, 3, 5, 8, 13, and 21.

4 years agopatterns: 3 bits for duration, 5 bits for mode
Jan "Yenya" Kasprzak [Tue, 4 Jun 2013 15:46:59 +0000 (17:46 +0200)]
patterns: 3 bits for duration, 5 bits for mode

I plan to use a single mode for encoding all three pwmleds:

2 bits for PWMLED 0
1 bit  for PWMLED 1
2 bits for PWMLED 2

4 years agoadc.c: fix uninitialized value
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 20:07:26 +0000 (22:07 +0200)]
adc.c: fix uninitialized value

4 years agobattery.c: don't report battery critical for now
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 20:05:09 +0000 (22:05 +0200)]
battery.c: don't report battery critical for now

4 years agopwmled.c: start probing with non-zero PWM value
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 20:04:33 +0000 (22:04 +0200)]
pwmled.c: start probing with non-zero PWM value

... in order to kick the ADCs on.

4 years agomain.c: on-demand sleep modes
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 15:56:06 +0000 (17:56 +0200)]
main.c: on-demand sleep modes

4 years agoadc: use only active pwmleds, on-demand switching of other channels
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 15:52:14 +0000 (17:52 +0200)]
adc: use only active pwmleds, on-demand switching of other channels

4 years agopwm.c: channels running - visible from the outside
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 15:11:26 +0000 (17:11 +0200)]
pwm.c: channels running - visible from the outside

Make the status of T/C1 visible from the outside, in order to
make the on-demand ADC channel selection possible, and also
to allow selecting the sleep modes in the main loop.

4 years agoadc.c: reorder ADC channels
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 12:11:23 +0000 (14:11 +0200)]
adc.c: reorder ADC channels

- those which need to be measured more frequently, put at the beginning.

4 years agoAmbient light zones adjustments
Jan "Yenya" Kasprzak [Tue, 28 May 2013 21:52:48 +0000 (23:52 +0200)]
Ambient light zones adjustments

4 years agopwm.c: disable when not needed
Jan "Yenya" Kasprzak [Tue, 28 May 2013 21:07:31 +0000 (23:07 +0200)]
pwm.c: disable when not needed

Timer/Counter 1 eats much power, especially with PLL clock. So let's
try to disable it when no PWM channel is active.

4 years agobuttons.c: handle brake sensor failure gracefully
Jan "Yenya" Kasprzak [Tue, 28 May 2013 20:45:56 +0000 (22:45 +0200)]
buttons.c: handle brake sensor failure gracefully

A common failure mode is that the magnet slips and does not provide
the signal, so it appears as if constantly braking. Avoid this situation
by allowing continuous braking of at most 16 seconds. After that, report
brake off, and wait for the real "brake off" signall from the Hall sensor.

4 years agotmr.c: combine watchdog IRQ and watchdog reset
Jan "Yenya" Kasprzak [Tue, 28 May 2013 20:29:06 +0000 (22:29 +0200)]
tmr.c: combine watchdog IRQ and watchdog reset

Fortunately, WDT reset can be combined with WDT interrupt. The procedure
is to reenable WDIE each time, or the next WDT timeout will be reset.

4 years agoWatchdog-based timing
Jan "Yenya" Kasprzak [Mon, 20 May 2013 22:34:06 +0000 (00:34 +0200)]
Watchdog-based timing

TODO: remove the sub-LSB PWM scaling, add deeper sleep states.

4 years agoambient: log minima and maxima
Jan "Yenya" Kasprzak [Mon, 20 May 2013 21:47:05 +0000 (23:47 +0200)]
ambient: log minima and maxima

In order to be able to tune the ambient light sensor better, I made
it to log the minimum and maximum values read for every three minutes
or so. When the log buffer fills, start over only after the next
off/on cycle.

4 years agoambient.c: adjust the day/dawn values
Jan "Yenya" Kasprzak [Thu, 11 Apr 2013 19:49:42 +0000 (21:49 +0200)]
ambient.c: adjust the day/dawn values

4 years agoambient.c: make the sensor react faster
Jan "Yenya" Kasprzak [Thu, 11 Apr 2013 19:49:12 +0000 (21:49 +0200)]
ambient.c: make the sensor react faster

4 years agopattern+current adjustments
Jan "Yenya" Kasprzak [Wed, 10 Apr 2013 21:48:27 +0000 (23:48 +0200)]
pattern+current adjustments

4 years agocontrol.c: braking pattern for pwmled0
Jan "Yenya" Kasprzak [Wed, 10 Apr 2013 21:16:45 +0000 (23:16 +0200)]
control.c: braking pattern for pwmled0

4 years agopwmled.c: slower response in order to gain stability
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 22:55:02 +0000 (23:55 +0100)]
pwmled.c: slower response in order to gain stability

4 years agopwmled.c: I only have one 350mA spot LED now in production mode
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 22:40:33 +0000 (23:40 +0100)]
pwmled.c: I only have one 350mA spot LED now in production mode

4 years agopwmleds: less measurements per run
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 22:36:26 +0000 (23:36 +0100)]
pwmleds: less measurements per run

With low-pass filters at the input of PWMLED ADC pins, it is now
relatively stable and noise-free, so we can lower the number of readings
to two. Hopefully this will not cause instability.

4 years agoslow ADC inputs
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 22:33:25 +0000 (23:33 +0100)]
slow ADC inputs

The fastest-repeated measurements are needed for PWM LEDs. OTOH,
things like buttons, battery voltage, ambient lights, etc. can be
read less frequently, and should be read in a deterministic time frame.
So we will measure PWMLED current in the free-running mode (as fast
as possible), and the other "slow" ADC inputs with each PATTERN_DIV-th
timer tick.

4 years agoambient light sensor: configurable # of readings
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 21:13:58 +0000 (22:13 +0100)]
ambient light sensor: configurable # of readings

Set the # of readings to 1, and decrease the shift value
for running average in order to get faster reaction.

4 years agoTimer-initiated ADC
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 18:48:01 +0000 (19:48 +0100)]
Timer-initiated ADC

Run ADC synchronously with timer IRQ. This partially reverts
commit 210916486d18b3dc976c65c7b01b44bca446d856 in order to
prepare for selectively enabling and disabling ADC channels.

5 years agoadc.c: configurable number of pre-readings
Jan "Yenya" Kasprzak [Sun, 17 Mar 2013 16:59:23 +0000 (17:59 +0100)]
adc.c: configurable number of pre-readings

When there is a supposed ADC noise problem, it is handful to drop
several first readings, and even discharge the ADC capacitor
by reading the single-ended wire connected to zero. This commit
rewrites the ADC handling to allow exactly this, for each ADC input.

5 years agobuttons.c: magnet for the Hall probe not present?
Jan "Yenya" Kasprzak [Thu, 14 Mar 2013 21:12:33 +0000 (22:12 +0100)]
buttons.c: magnet for the Hall probe not present?

Handle the case when the Hall probe magnet is not present.

5 years agocontrol.c: reset the braking variable
Jan "Yenya" Kasprzak [Thu, 14 Mar 2013 21:12:13 +0000 (22:12 +0100)]
control.c: reset the braking variable

5 years agoadc: fix the button adc number
Jan "Yenya" Kasprzak [Thu, 14 Mar 2013 19:20:48 +0000 (20:20 +0100)]
adc: fix the button adc number

... and use symbolic constants in the switch statement to avoid
this kind of bugs in the future.

5 years agoadc: missing break statement
Jan "Yenya" Kasprzak [Thu, 14 Mar 2013 18:07:02 +0000 (19:07 +0100)]
adc: missing break statement

oh well.