Compare commits

..

No commits in common. "a29e16963f573714e2901716c6ed5fc8b67f67b9" and "4d229a973c269edf43a7cbeee8dc064a84bc59e7" have entirely different histories.

5 changed files with 16 additions and 24 deletions

View file

@ -71,7 +71,6 @@ include_directories(
./inc ./inc
/usr/local/avr/include/avr /usr/local/avr/include/avr
/usr/local/avr/include /usr/local/avr/include
/usr/local/avr/avr/include #for Linux
) )
add_subdirectory(src) add_subdirectory(src)

View file

@ -15,10 +15,9 @@ set(AVR_MCU attiny13a)
#set(AVR_MCU avr64dd28) # Newer DX series, avrxmega2 #set(AVR_MCU avr64dd28) # Newer DX series, avrxmega2
#set(F_CPU 16000000UL) #set(F_CPU 16000000UL)
#set(F_CPU 8000000UL) #set(F_CPU 8000000)
#set(F_CPU 9600000UL) set(F_CPU 9600000)
set(F_CPU 1200000UL) #set(F_CPU 4800000)
#set(F_CPU 4800000UL)
add_compile_definitions(F_CPU=${F_CPU}) add_compile_definitions(F_CPU=${F_CPU})
# add_compile_definitions(MCU=atmega328p) # add_compile_definitions(MCU=atmega328p)

View file

@ -3,7 +3,7 @@ add_executable(${PROJECT_NAME}
) )
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
RegEdit #RegEdit
#timer #timer
) )
@ -36,11 +36,10 @@ add_custom_target(bin ALL
endif() endif()
# Setup for default 9.6MHz
if(NOT TARGET upload) if(NOT TARGET upload)
# Upload command (adjust according to your programmer) # Upload command (adjust according to your programmer)
add_custom_target(upload ALL add_custom_target(upload ALL
COMMAND avrdude -c ${PROGRAMMER} -P ${PORT} -p ${AVR_MCU} -B 125kHz -U lfuse:w:0x6a:m -U hfuse:w:0xFF:m -U lock:w:0xFF:m -U flash:w:${CMAKE_PROJECT_NAME}.hex COMMAND avrdude -c ${PROGRAMMER} -P ${PORT} -p ${AVR_MCU} -B 125kHz -U flash:w:${CMAKE_PROJECT_NAME}.hex
DEPENDS hex DEPENDS hex
) )
endif() endif()

View file

@ -1,10 +1,8 @@
#ifndef F_CPU #ifndef F_CPU
#error "F_CPU not defined: defaulting to 9.6MHz" #define F_CPU 4800000UL
#define F_CPU 1200000UL
#endif #endif
#include "main.h" #include "main.h"
//#include "ADC.h"
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <util/delay.h> #include <util/delay.h>
@ -51,7 +49,6 @@ int main() {
while (1) { while (1) {
UpdateButtonOutput(&btn1); UpdateButtonOutput(&btn1);
UpdateButtonInput(&btn1); UpdateButtonInput(&btn1);
//MotorMoveTo(0);
} }
return 0; return 0;
@ -88,7 +85,6 @@ void InitProg(void) {
uint8_t ReadSpeed(void) { uint8_t ReadSpeed(void) {
// Initialize ADC // Initialize ADC
ADMUX = (0 << MUX1) | (1 << MUX0); // Select ADC1 (PB2) ADMUX = (0 << MUX1) | (1 << MUX0); // Select ADC1 (PB2)
ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8 ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8
@ -98,8 +94,10 @@ uint8_t ReadSpeed(void) {
uint8_t val = (uint8_t)(ADC >> 2); uint8_t val = (uint8_t)(ADC >> 2);
//Map the speed value to the 100%-50% duty cycle range. // We want to set a minimum acceptable speed.
//val = (uint8_t)( (float)val / 255.0 ) * 100; if (val < 32) {
val = 32;
}
return val; return val;
} }
@ -141,12 +139,11 @@ uint8_t MotorGetSavedPos(void) {
void MotorMoveTo(uint8_t target) { void MotorMoveTo(uint8_t target) {
uint8_t on_delay = ReadSpeed(); uint8_t on_delay = ReadFader();
uint8_t off_delay = 255 - on_delay;
uint8_t pos = (uint8_t)(ReadFader() >> 2); uint8_t pos = (uint8_t)(ReadFader() >> 2);
uint8_t idx =0;
while (diff(target, pos) > 8) { while (diff(target, pos) > 8) {
on_delay = ReadSpeed();
pos = (uint8_t)(ReadFader() >> 2); pos = (uint8_t)(ReadFader() >> 2);
if (target > pos) { if (target > pos) {
MotorMove(1); MotorMove(1);
@ -155,11 +152,11 @@ void MotorMoveTo(uint8_t target) {
} }
// The delay ratio controlls the PWM waveforms. // The delay ratio controlls the PWM waveforms.
for (idx = 0; idx < on_delay; idx++) { for(uint8_t i = 0; i < on_delay; i++){
_delay_us(MOTOR_PULSE); _delay_us(MOTOR_PULSE);
} }
MotorCoast(); MotorCoast();
for (;idx < 255; idx++) { for(uint8_t i = 0; i < off_delay; i++){
_delay_us(MOTOR_PULSE); _delay_us(MOTOR_PULSE);
} }
} }
@ -168,7 +165,6 @@ void MotorMoveTo(uint8_t target) {
} }
// Using the compatable bool type. // Using the compatable bool type.
// The motor being used seems to stop working below a 50% duty cycle.
void MotorMove(uint8_t fwd) { void MotorMove(uint8_t fwd) {
if (fwd) { if (fwd) {
PORTB |= (1 << PWM_PIN1); PORTB |= (1 << PWM_PIN1);

View file

@ -13,6 +13,5 @@ target_link_libraries(test_ADC
#Needed for the tests to function #Needed for the tests to function
include_directories( include_directories(
/usr/local/avr/include/avr /usr/local/avr/include/avr
#/usr/local/avr/avr/include #for Linux
#/usr/lib/avr/include/avr #/usr/lib/avr/include/avr
) )