bike-lights.git
4 days agowip tmp
Jan "Yenya" Kasprzak [Fri, 7 Jun 2013 05:03:07 +0000]
wip

6 days agoanother wip
Jan "Yenya" Kasprzak [Wed, 5 Jun 2013 21:03:42 +0000]
another wip

6 days agotemporary work in progress
Jan "Yenya" Kasprzak [Wed, 5 Jun 2013 07:58:18 +0000]
temporary work in progress

7 days agopatterns: fibonacci-scaled step duration
Jan "Yenya" Kasprzak [Tue, 4 Jun 2013 16:04:35 +0000]
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.

7 days agopatterns: 3 bits for duration, 5 bits for mode
Jan "Yenya" Kasprzak [Tue, 4 Jun 2013 15:46:59 +0000]
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

8 days agoadc.c: fix uninitialized value
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 20:07:26 +0000]
adc.c: fix uninitialized value

8 days agobattery.c: don't report battery critical for now
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 20:05:09 +0000]
battery.c: don't report battery critical for now

8 days agopwmled.c: start probing with non-zero PWM value
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 20:04:33 +0000]
pwmled.c: start probing with non-zero PWM value

... in order to kick the ADCs on.

8 days agomain.c: on-demand sleep modes
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 15:56:06 +0000]
main.c: on-demand sleep modes

8 days agoadc: use only active pwmleds, on-demand switching of other channels
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 15:52:14 +0000]
adc: use only active pwmleds, on-demand switching of other channels

8 days agopwm.c: channels running - visible from the outside
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 15:11:26 +0000]
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.

8 days agoadc.c: reorder ADC channels
Jan "Yenya" Kasprzak [Mon, 3 Jun 2013 12:11:23 +0000]
adc.c: reorder ADC channels

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

2 weeks agoAmbient light zones adjustments
Jan "Yenya" Kasprzak [Tue, 28 May 2013 21:52:48 +0000]
Ambient light zones adjustments

2 weeks agopwm.c: disable when not needed
Jan "Yenya" Kasprzak [Tue, 28 May 2013 21:07:31 +0000]
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.

2 weeks agobuttons.c: handle brake sensor failure gracefully
Jan "Yenya" Kasprzak [Tue, 28 May 2013 20:45:56 +0000]
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.

2 weeks agotmr.c: combine watchdog IRQ and watchdog reset
Jan "Yenya" Kasprzak [Tue, 28 May 2013 20:29:06 +0000]
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.

3 weeks agoWatchdog-based timing
Jan "Yenya" Kasprzak [Mon, 20 May 2013 22:34:06 +0000]
Watchdog-based timing

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

3 weeks agoambient: log minima and maxima
Jan "Yenya" Kasprzak [Mon, 20 May 2013 21:47:05 +0000]
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.

2 months agoambient.c: adjust the day/dawn values
Jan "Yenya" Kasprzak [Thu, 11 Apr 2013 19:49:42 +0000]
ambient.c: adjust the day/dawn values

2 months agoambient.c: make the sensor react faster
Jan "Yenya" Kasprzak [Thu, 11 Apr 2013 19:49:12 +0000]
ambient.c: make the sensor react faster

2 months agopattern+current adjustments
Jan "Yenya" Kasprzak [Wed, 10 Apr 2013 21:48:27 +0000]
pattern+current adjustments

2 months agocontrol.c: braking pattern for pwmled0
Jan "Yenya" Kasprzak [Wed, 10 Apr 2013 21:16:45 +0000]
control.c: braking pattern for pwmled0

2 months agopwmled.c: slower response in order to gain stability
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 22:55:02 +0000]
pwmled.c: slower response in order to gain stability

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

2 months agopwmleds: less measurements per run
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 22:36:26 +0000]
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.

2 months agoslow ADC inputs
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 22:33:25 +0000]
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.

2 months agoambient light sensor: configurable # of readings
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 21:13:58 +0000]
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.

2 months agoTimer-initiated ADC
Jan "Yenya" Kasprzak [Thu, 28 Mar 2013 18:48:01 +0000]
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.

2 months agoadc.c: configurable number of pre-readings
Jan "Yenya" Kasprzak [Sun, 17 Mar 2013 16:59:23 +0000]
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.

2 months agobuttons.c: magnet for the Hall probe not present?
Jan "Yenya" Kasprzak [Thu, 14 Mar 2013 21:12:33 +0000]
buttons.c: magnet for the Hall probe not present?

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

2 months agocontrol.c: reset the braking variable
Jan "Yenya" Kasprzak [Thu, 14 Mar 2013 21:12:13 +0000]
control.c: reset the braking variable

2 months agoadc: fix the button adc number
Jan "Yenya" Kasprzak [Thu, 14 Mar 2013 19:20:48 +0000]
adc: fix the button adc number

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

2 months agoadc: missing break statement
Jan "Yenya" Kasprzak [Thu, 14 Mar 2013 18:07:02 +0000]
adc: missing break statement

oh well.

3 months agofirmware: buttons + hall probe via ADC adc_buttons
Jan "Yenya" Kasprzak [Fri, 8 Mar 2013 21:52:16 +0000]
firmware: buttons + hall probe via ADC

3 months agobattery.c: adjustment for 1.1V internal reference
Jan "Yenya" Kasprzak [Wed, 6 Mar 2013 23:19:43 +0000]
battery.c: adjustment for 1.1V internal reference

3 months agopattern.c: shorten the final delay
Jan "Yenya" Kasprzak [Wed, 6 Mar 2013 21:54:02 +0000]
pattern.c: shorten the final delay

Shorten tne final delay in number patterns and off_pattern.

3 months agopattern.c: synchronized patterns
Jan "Yenya" Kasprzak [Wed, 6 Mar 2013 21:51:55 +0000]
pattern.c: synchronized patterns

- status LEDs should not blink together
- PWM LEDs should start synchronized, in order to allow for compensation
of battery voltage variations when one output is on
compared to when more outputs are on

3 months agoRemove unused PATTERN_FOREVER
Jan "Yenya" Kasprzak [Wed, 6 Mar 2013 10:41:19 +0000]
Remove unused PATTERN_FOREVER

This is not used by any pattern anymore - remove it.

3 months agoMakefile: handlebar schematics for the web pages
Jan "Yenya" Kasprzak [Tue, 5 Mar 2013 13:09:49 +0000]
Makefile: handlebar schematics for the web pages

3 months agoambient zones adjusted
Jan "Yenya" Kasprzak [Wed, 6 Mar 2013 15:05:10 +0000]
ambient zones adjusted

3 months agoHandlebar switches
Jan "Yenya" Kasprzak [Tue, 5 Mar 2013 12:54:34 +0000]
Handlebar switches

I have decided to implement a brake light, which I want to trigger using
Hall-effect sensor mounted in the brake lever. Unfortunately I still
have only three wires for two switches and a Hall-effect sensor, so I
would have to change the digital switch readings (on/off) to ADC
readings (voltages selected using voltage split on resistors).

Here is the schematics for the whole handlebar electronics, and the
symbol file and datasheet for the Honeywell SS341RT Hall-effect sensor.

3 months agolights.h: fix prototype name
Jan "Yenya" Kasprzak [Thu, 28 Feb 2013 00:11:46 +0000]
lights.h: fix prototype name

3 months agocontrol.c: handle "battery critical" state
Jan "Yenya" Kasprzak [Thu, 28 Feb 2013 00:00:57 +0000]
control.c: handle "battery critical" state

3 months agocontrol.c: display battery status on status led by default
Jan "Yenya" Kasprzak [Wed, 27 Feb 2013 23:58:04 +0000]
control.c: display battery status on status led by default

3 months agopattern.c: num_pattern(10) is also allowed
Jan "Yenya" Kasprzak [Wed, 27 Feb 2013 23:57:35 +0000]
pattern.c: num_pattern(10) is also allowed

3 months agobattery.c: rework
Jan "Yenya" Kasprzak [Wed, 27 Feb 2013 23:56:55 +0000]
battery.c: rework

We can use values in mV instead of 100 mV. We can also provide
the battery level on scale from 1 to 10.

3 months agoadc.c: more measurements of ambient light
Jan "Yenya" Kasprzak [Wed, 27 Feb 2013 22:28:35 +0000]
adc.c: more measurements of ambient light

3 months agoambient.c: zone adjustments
Jan "Yenya" Kasprzak [Wed, 27 Feb 2013 22:28:16 +0000]
ambient.c: zone adjustments

3 months agobattery.c: priority of operations
Jan "Yenya" Kasprzak [Wed, 27 Feb 2013 22:27:46 +0000]
battery.c: priority of operations

... in order to fit to an 8-bit value.

3 months agoRevert "adc.c: make the ADC handlers non-atomic"
Jan "Yenya" Kasprzak [Wed, 27 Feb 2013 21:49:42 +0000]
Revert "adc.c: make the ADC handlers non-atomic"

This reverts commit eb2f91ea7806fd8f5b9a5597fcf5c13855911d71.

We will probably not need non-atomic handlers.

3 months agopattern: laser diodes as gpio 4
Jan "Yenya" Kasprzak [Wed, 20 Feb 2013 21:49:36 +0000]
pattern: laser diodes as gpio 4

3 months agopwmled.c: shut down the boost converter later
Jan "Yenya" Kasprzak [Wed, 20 Feb 2013 21:47:24 +0000]
pwmled.c: shut down the boost converter later

4 months agopins.txt: converter response times
Jan "Yenya" Kasprzak [Fri, 18 Jan 2013 21:52:35 +0000]
pins.txt: converter response times

4 months agoambient.c: zones adjusted for photoresistor
Jan "Yenya" Kasprzak [Fri, 18 Jan 2013 21:51:40 +0000]
ambient.c: zones adjusted for photoresistor

4 months agoMerge branch 'master' of ssh://anxur.fi.muni.cz/~kas/html/git/bike-lights
Jan "Yenya" Kasprzak [Fri, 18 Jan 2013 21:50:50 +0000]
Merge branch 'master' of ssh://anxur.fi.muni.cz/~kas/html/git/bike-lights

Conflicts:
firmware/adc.c

5 months agoadc.c: make the ADC handlers non-atomic
Jan "Yenya" Kasprzak [Fri, 4 Jan 2013 16:26:08 +0000]
adc.c: make the ADC handlers non-atomic

will it work?

5 months agoadc.c: routine for synchronous conversion
Jan "Yenya" Kasprzak [Fri, 4 Jan 2013 14:50:14 +0000]
adc.c: routine for synchronous conversion

5 months agocontrol.c: blinking modes update
Jan "Yenya" Kasprzak [Sun, 16 Dec 2012 16:32:32 +0000]
control.c: blinking modes update

5 months agocontrol.c: on_patterns should not last forever
Jan "Yenya" Kasprzak [Sun, 16 Dec 2012 16:31:18 +0000]
control.c: on_patterns should not last forever

5 months agoambient light: make three measurements
Jan "Yenya" Kasprzak [Sun, 16 Dec 2012 16:29:53 +0000]
ambient light: make three measurements

5 months agopwmled.c: do not regulate just after mode change
Jan "Yenya" Kasprzak [Sun, 16 Dec 2012 16:28:39 +0000]
pwmled.c: do not regulate just after mode change

5 months agopwmled.c: disable the disconnected step-up earlier
Jan "Yenya" Kasprzak [Sun, 16 Dec 2012 16:26:50 +0000]
pwmled.c: disable the disconnected step-up earlier

5 months agopattern.c: off_pattern should not last forever
Jan "Yenya" Kasprzak [Sun, 16 Dec 2012 16:22:26 +0000]
pattern.c: off_pattern should not last forever

5 months agobuttons.c: longer keypress
Jan "Yenya" Kasprzak [Sat, 15 Dec 2012 21:22:02 +0000]
buttons.c: longer keypress

... after we have increased the clock frequency

5 months agoambient.c: ambient light hysteresis
Jan "Yenya" Kasprzak [Sat, 15 Dec 2012 21:21:25 +0000]
ambient.c: ambient light hysteresis

5 months agoschematics: more low-pass filters, fuse removed
Jan "Yenya" Kasprzak [Sat, 15 Dec 2012 20:51:23 +0000]
schematics: more low-pass filters, fuse removed

5 months agoMerge branch 'master' of ssh://anxur.fi.muni.cz/~kas/html/git/bike-lights
Jan "Yenya" Kasprzak [Wed, 12 Dec 2012 04:03:59 +0000]
Merge branch 'master' of ssh://anxur.fi.muni.cz/~kas/html/git/bike-lights

5 months agoschematics: bug fixes
Jan "Yenya" Kasprzak [Tue, 11 Dec 2012 16:16:29 +0000]
schematics: bug fixes

- low-pass filters added to the ADC pins measuring LED current
- prog_ena jumper changed to disconnect pwm0 only, as this is what makes
problem during in-system programming
- labels for LED and battery connectors moved outside the footprint

6 months agopwm.c: maximum TOP value of T/C 1 is 0x3FF.
Jan "Yenya" Kasprzak [Mon, 10 Dec 2012 21:00:28 +0000]
pwm.c: maximum TOP value of T/C 1 is 0x3FF.

6 months agobuttons.c - the correct IRQ is PCIE1
Jan "Yenya" Kasprzak [Sat, 8 Dec 2012 21:32:40 +0000]
buttons.c - the correct IRQ is PCIE1

6 months agoAbility to quickly build testing firmware
Jan "Yenya" Kasprzak [Sat, 8 Dec 2012 19:36:27 +0000]
Ability to quickly build testing firmware

Testing is actually development,
and non-testing is "safe" for production use, even with some
features disabled. At least for now :-)

6 months agoADC measurements in mA
Jan "Yenya" Kasprzak [Sat, 8 Dec 2012 19:27:41 +0000]
ADC measurements in mA

6 months agopwm.c: publish only PWM_MAX as non-internal value
Jan "Yenya" Kasprzak [Fri, 7 Dec 2012 22:03:55 +0000]
pwm.c: publish only PWM_MAX as non-internal value

The TOP value of Timer/Counter 1 is computed inside pwm.c and it is
purely internal to this module.

6 months agopwmled.c: factored out probing to a separate function
Jan "Yenya" Kasprzak [Fri, 7 Dec 2012 21:51:20 +0000]
pwmled.c: factored out probing to a separate function

6 months agopwmled.c: save error sum between mode switches
Jan "Yenya" Kasprzak [Fri, 7 Dec 2012 21:03:49 +0000]
pwmled.c: save error sum between mode switches

otherwise it leads to instability when during short blink the error
sum does not manage to increase the stride.

Also, use 32-bit ints to simplify the code and save some branches.

6 months agopwm.c: make it usable from non-atomic blocks
Jan "Yenya" Kasprzak [Thu, 6 Dec 2012 23:10:20 +0000]
pwm.c: make it usable from non-atomic blocks

6 months agopwm.c - remove unused code
Jan "Yenya" Kasprzak [Thu, 6 Dec 2012 20:38:03 +0000]
pwm.c - remove unused code

6 months agopwm.c: PLL clock enabling code
Jan "Yenya" Kasprzak [Thu, 6 Dec 2012 20:34:00 +0000]
pwm.c: PLL clock enabling code

- factored out from init_pwm() in order to be able to suspend PLL also
during normal operation
- use _delay_us(100) instead of _delay_ms(1) as recommended by datasheet
- disable PLL in susp_pwm()

6 months agofirmware: control logic moved to a separate module
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 16:37:53 +0000]
firmware: control logic moved to a separate module

- buttons.c now controls status LEDs only when setting parameters
- pattern.c:
can use NULL instead of off_pattern
has number_pattern() than can also set up inverted patterns
contains only number and boot patterns as static variables
can reload all patterns if some state changes
- ambient.c resets all patterns when ambient zone changes
- control.c:
- now contains almost all pattern strings, only those needed by
other modules are exported
- status LED and illumination LED can be controlled by buttons.c
- separate _pattern_select() function for each LED

6 months agoadc: always-running ADC
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 10:23:27 +0000]
adc: always-running ADC

Don't rely on the timer IRQ to start next round of ADC measurements,
start it immediately after the previous one finishes.

6 months agologging: consistent init function naming
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 10:13:15 +0000]
logging: consistent init function naming

6 months agopatterns: consistent init function naming
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 10:10:04 +0000]
patterns: consistent init function naming

6 months agoambient light: consistent init function naming
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 10:09:11 +0000]
ambient light: consistent init function naming

6 months agogpio: consistent init function naming
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 10:08:33 +0000]
gpio: consistent init function naming

6 months agopwmled: consistent init function naming
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 10:07:02 +0000]
pwmled: consistent init function naming

6 months agogpio: rework
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 10:05:36 +0000]
gpio: rework

use correct swtiching between pin input and output
(as per the datasheet, section 10.1.2),
remove old logic of wakeup LED notifications

6 months agobuttons, wakeup rework
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 09:58:31 +0000]
buttons, wakeup rework

Set up all the pin-change interrupts even for shutdown,
fix the old pins used in the code (main.c),
factor out waiting for button release from main.c to buttons.c,
fix the status LED notification during wake-up.

6 months agopwmled.c: rework
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 01:23:45 +0000]
pwmled.c: rework

Probing and time-averaging works, but several corner cases need to be
polished.

6 months agomake timer faster, sub-1 LSB PWM values need it
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 01:22:58 +0000]
make timer faster, sub-1 LSB PWM values need it

otherwise, the step-up blinks with low pwm settings

6 months agopattern.c: call pwmled.c unconditionally
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 01:14:57 +0000]
pattern.c: call pwmled.c unconditionally

- no not query whether the LED is alive - pwmled.c will handle this
in that case.

6 months agopattern.c: mode1_pattern out of modes 1 and 2 instead of 1 and 4
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 01:14:30 +0000]
pattern.c: mode1_pattern out of modes 1 and 2 instead of 1 and 4

6 months agoadc: measure gain stage offset _slowly_
Jan "Yenya" Kasprzak [Fri, 30 Nov 2012 01:12:05 +0000]
adc: measure gain stage offset _slowly_

use running sum of 1<<6 measurements, and do only one measurement
per loop in order to not disturb other measurements. Also, do not log
timer overruns for ADC, as we do most of the processing in ADC IRQs now.

6 months agopwm.c: typo fixes
Jan "Yenya" Kasprzak [Thu, 29 Nov 2012 20:07:51 +0000]
pwm.c: typo fixes

6 months agofirmware: emulate higher resolution of PWM
Jan "Yenya" Kasprzak [Thu, 29 Nov 2012 13:36:45 +0000]
firmware: emulate higher resolution of PWM

Emulate the sub-1 LSB resolution of PWM by updating the PWM values
in the timer interrupt routine

6 months agoadc.c: keep ADC enabled
Jan "Yenya" Kasprzak [Thu, 29 Nov 2012 13:05:08 +0000]
adc.c: keep ADC enabled

6 months agopwmled: more logging
Jan "Yenya" Kasprzak [Thu, 22 Nov 2012 22:00:00 +0000]
pwmled: more logging

6 months agopwmled: remove old unused function
Jan "Yenya" Kasprzak [Thu, 22 Nov 2012 21:26:08 +0000]
pwmled: remove old unused function

6 months agoambient: new zones
Jan "Yenya" Kasprzak [Thu, 22 Nov 2012 00:11:31 +0000]
ambient: new zones

6 months agobuttons.c: param setup fixes
Jan "Yenya" Kasprzak [Wed, 21 Nov 2012 23:58:01 +0000]
buttons.c: param setup fixes

6 months agopatterns: zero pattern
Jan "Yenya" Kasprzak [Wed, 21 Nov 2012 23:57:03 +0000]
patterns: zero pattern

similar to off, but does not last forever