Last active
October 27, 2018 00:48
-
-
Save chuckwagoncomputing/40e174ca9e4ed3d5ac91c4cde07148c7 to your computer and use it in GitHub Desktop.
Bobcat 225G welder idle controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*****************************************************// | |
// welder.c // | |
// 2016-4-11 // | |
// Written By David Holdeman // | |
// Miller Bobcat 225G Idle Solenoid Controller // | |
//*****************************************************// | |
// ATtiny45/85 | |
// +-------+ | |
// !RESET |* | VCC | |
// PB3 | | PB2/INT0 - Signal In | |
// PB4 | | PB1 - Signal Out to MOSFET | |
// GND | | PB0 | |
// +-------+ | |
#include "avr/interrupt.h" | |
#include "util/delay.h" | |
volatile int time = 0; | |
ISR(INT0_vect) { | |
time = 0; // Reset timer | |
PORTB &= ~(1<<PB1); // Drive pin 1 low (switch solenoid off) | |
return; | |
} | |
int main(void) { | |
DDRB = 0b00000010; // Set PORTB pin 1 as output, all others as input. | |
MCUCR |= (1<<ISC00); // Set Interrupt on Rising edge of signal | |
MCUCR |= (1<<ISC01); | |
GIMSK |= (1<<INT0); // Enable INT0 Interrupt | |
sei(); // Activate interrupts | |
PORTB |= (1<<PB1); // Drive pin 1 high (switch solenoid on) | |
while(1) { | |
if (PINB2 == 1) { // Just In Case the input signal is longer than expected, | |
// or we want to run a small/no delay, check whether the input is high | |
time = 0; // And if so, reset the timer | |
} | |
else if(time >= 200) { // If we've counted for 2 seconds | |
PORTB |= (1<<PB1); // Drive pin 1 high (switch solenoid on) | |
} | |
else { | |
time++; // Count up | |
} | |
_delay_ms(10); // Delay 10 milliseconds | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEVICE = attiny85 | |
CLOCK = 1000000UL | |
PROGRAMMER = buspirate | |
PORT = /dev/ttyUSB0 | |
BAUD = 115200 | |
FILENAME = main | |
COMPILE = avr-gcc -Wall -Os -I /usr/share/arduino/hardware/tools/avr/avr/include/ -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) | |
all: usb clean build upload | |
usb: | |
ls /dev | |
build: | |
$(COMPILE) -c $(FILENAME).c -o $(FILENAME).o | |
$(COMPILE) -o $(FILENAME).elf $(FILENAME).o | |
avr-objcopy -j .text -j .data -O ihex $(FILENAME).elf $(FILENAME).hex | |
avr-size --format=avr --mcu=$(DEVICE) $(FILENAME).elf | |
upload: | |
avrdude -v -p $(DEVICE) -c $(PROGRAMMER) -P $(PORT) -b $(BAUD) -U flash:w:$(FILENAME).hex:i | |
clean: | |
rm main.o | |
rm main.elf | |
rm main.hex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment