Coder Social home page Coder Social logo

jonny999999 / ihc-control_fw Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 14.33 MB

Firmware for custom PCB to upgrade and replace the complex, broken relay-based control system of an IHC tractor

Home Page: https://pfusch.zone/control-pcb

CMake 15.97% C++ 77.87% C 6.16%

ihc-control_fw's Introduction

Firmware for a custom pcb with an Atmega8 microcontroller, that controls the electrical components of an IHC-Tractor.

TOC

Links

Usage

Initial setup

Install required packages:

yay -S cmake avr-gcc avr-libc

Build enviroment:

git clone [email protected]:Jonny999999/ihc-control_fw.git
cd ihc-control_fw
mkdir build
cd build
cmake ..

Compile

cd build
make

Note: currently the latest version of avr-gcc produces the following error:

/ihc-control_fw/include/GPIO/a2d.c:11:15: error: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Werror=array-bounds]
   11 |         ADMUX &= ~(1<<REFS1);  //Vcc RefU

downgrading the package avr-gcc (12.1.0-1 => 11.3.0-1) e.g. with sudo downgrade avr-gcc is the current workaround

Upload

Connect avr controller using USBASP V2.0 ISP programmer

cd build
sudo make hello_upload

Pin Assignment

Inputs

3x switch to 12V inputs (terminal TOP-LEFT)

Pin Object Variable Description
PB2 sPB2 S_LOW_BEAM key switch low beam
PB1 sPB1 S_BRAKE brake switch to 12V
PB0 sPB0 S_WORK_LIGHT Toggle switch work light left dashboard
GND - - -

Note: Switch parking light directly powers lights since controller is off in this key position (no input necessary)

5x switch to GND inputs (terminal BOTTOM-LEFT)

Pin Object Variable Description
PB3 sPB3 S_HIGH_BEAM Momentary switch high beam in right dashboard
PB4 sPB4 S_HORN Momentary switch for horn in right dashboard
PC0 sPC0 S_BLINK_LEFT Toggle switch blink left in right dashboard
PC1 sPC1 S_BLINK_RIGHT Toggle switch blink right
PC2 sPC2 S_WARNING_LIGHTS Toggle switch warning lights in left dashboard
GND - - -

Outputs

Relay outputs (separate terminals RIGHT)

Pin Object Variable Description
PD5 k1 OUT_BLINK_LEFT blinker rear + connector
PB7 k2 OUT_BLINK_RIGHT blinker rear + connector
PB6 k3 OUT_BLINK_LEFT_FRONT front blinker only
PB4 k4 OUT_BLINK_RIGHT_FRONT front blinker only
PD3 k5 free
PD2 k6 OUT_WORK_LIGHT rear worklight
PD1 k7 OUT_HIGH_BEAM High beam in front
PD0 k8 OUT_LOW_BEAM Low beam in front

Mosfet outputs (Terminal BOTTOM-CENTER)

Pin Object Variable Description
PC4 mos1 OUT_HORN Horn can be switched with mosfet (2 cables and measured max ~4A)
PC3 mos2 OUT_CONTROL_LAMP Control lamp in dashboard (originally unused - intended use "gearbox oil pressure")

Custom Libraries

GPIO Related

GPIO_evaluateSwitch.hpp

'GPIO_evaluatedSwitch' class for initializing a GPIO pin as input and debouncing it, with options to invert or enable pullup. features:

  • debounce (minOn minOff ms)
  • edge detection (risingEdge, fallingEdge)
  • invert input (e.g. when switching to VCC)
  • enable pullup (default enabled => ON state = gnd level)
  • count time on/off (msPressed, msReleased) -> see header file for detailed description

GPIO_output.hpp

'GPIO_output' class for initializing and turning a avr GPIO pin on/off in a abstracted way

  • The constructor initializes/defines the specified pin as output
  • With methods .on(), off() or .setState(bool) the pin can be set to the desired state
    -> see header file for detailed description

a2d.h

read adc channel

uint16_t ReadChannel(uint8_t mux);

Time Related

time.h

Add possibility to get current timestamp and calculate difference between timestamps.
(Used quite much in this project)

void time_init(void);  
uint32_t time_get(void);
uint32_t time_delta(uint32_t a, uint32_t b);

clock.hpp

'clock' class to generate a pulsing signal with specified frequency or on/off durations
e.g. for blinker to have a single/equal pulsing signal that can be used multiple times for left and right without delaying the program with any delay function
-> see header file for detailed description

pulse.hpp

'pulse' class to generate a certain count of pulses with specified durations
e.g. for buzzer without delaying the program with any delay function
-> see header file for detailed description

ihc-control_fw's People

Contributors

jonny999999 avatar rainerschoe avatar

Watchers

 avatar

ihc-control_fw's Issues

Optimize low voltage notification: earlier, longer, more frequent

Today the low voltage situation actually happened, and the beep notified me that the ignition was on for a week. The following should be optimized to make it more practical:

  • longer beeps
    Since the beep is not that loud when mounted inside the tractor it could be longer and even more frequent

  • voltage thresholds
    Today there was only 1 beep - the battery was quite weak already but would still start
    But when emptying the battery even more until it does not start anymore, i still got only 1 beep and sometimes 4

  • interval
    beep more frequent when low already

Add timeout notification

Currently there is only low voltage notification using the buzzer.
This usually happens when ignition was not turned off.

This situation could be detected earlier without draining the battery for weeks:
-> An alternative could be to detect when there was no activity for several hours. Or uptime for more than a day

Method to disable buzzer

Buzzer might get annoying for some reason
e.g. low voltage warning triggers all the time, or intentionally blinking right for a very long time.

-> Add a way to disable the buzzer
Ideas:

  • when button highbeam is pressed during startup, buzzer is disabled
  • when several buttons are pressed at the same time

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.