Compare commits

..

10 Commits
v0.2.2 ... main

Author SHA1 Message Date
jakeg00dwin b377eab7c0 Updated with comments on prescaler usage for F_CPU 2025-02-20 16:05:23 -08:00
jakeg00dwin 43d15247ad Updated version number from changes. 2025-02-20 15:55:34 -08:00
jakeg00dwin a29e16963f Merge branch 'dev' 2025-02-20 15:50:00 -08:00
jakeg00dwin d3d69ca180 Added linux include dir for AVR. 2025-02-20 15:46:12 -08:00
jakeg00dwin 05b6de17d0 Added new F_CPU define. 2025-02-20 15:45:55 -08:00
jakeg00dwin b2a3dcbed4 Added line for inclusion of AVR stuff on linux machines. 2025-02-20 15:45:44 -08:00
jakeg00dwin 49d8ca037b Adjusted file to use F_CPU after DIV8 and allow speed control during movement. 2025-02-20 15:45:29 -08:00
jakeg00dwin c2ed2cead0 Added fuse flashing commands for default 9.6MHz 2025-02-20 15:44:55 -08:00
jakeg00dwin 4d229a973c updated version number 2025-02-18 19:30:01 -08:00
jakeg00dwin cc57692a1d Updated the motor pulse define, too fast of a pulse doesn't wakeup the motor driver. 2025-02-18 19:29:30 -08:00
6 changed files with 27 additions and 18 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)
# Use the fancy version substitution # Use the fancy version substitution
project(main project(main
VERSION 0.2.2 VERSION 0.2.4
DESCRIPTION "template for cmake + cpputest" DESCRIPTION "template for cmake + cpputest"
LANGUAGES C CXX LANGUAGES C CXX
) )
@ -71,6 +71,7 @@ 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,9 +15,11 @@ 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 8000000) #set(F_CPU 8000000UL)
set(F_CPU 9600000) #set(F_CPU 9600000UL)#AVR without prescaler
#set(F_CPU 4800000) set(F_CPU 1200000UL) #AVR (9.6MHz) with prescaler 8DIV
#set(F_CPU 4800000UL) #AVR without prescaler
#set(F_CPU 600000UL) #AVR (4.8MHz) with prescaler 8DIV
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

@ -49,7 +49,7 @@
#define SPEED_PIN PB2 // Pin 7/ADC1 #define SPEED_PIN PB2 // Pin 7/ADC1
#define BUTTON_PIN PB4 // Pin 3 - Button input #define BUTTON_PIN PB4 // Pin 3 - Button input
#define MOTOR_PULSE 1 //uS motor base pulse #define MOTOR_PULSE 6 //uS motor base pulse
/*The timing of "ticks" is dependent on the AVR timer's counter register /*The timing of "ticks" is dependent on the AVR timer's counter register

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,10 +36,11 @@ 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 flash:w:${CMAKE_PROJECT_NAME}.hex 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
DEPENDS hex DEPENDS hex
) )
endif() endif()

View File

@ -1,8 +1,10 @@
#ifndef F_CPU #ifndef F_CPU
#define F_CPU 4800000UL #error "F_CPU not defined: defaulting to 9.6MHz"
#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>
@ -49,6 +51,7 @@ int main() {
while (1) { while (1) {
UpdateButtonOutput(&btn1); UpdateButtonOutput(&btn1);
UpdateButtonInput(&btn1); UpdateButtonInput(&btn1);
//MotorMoveTo(0);
} }
return 0; return 0;
@ -85,6 +88,7 @@ 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
@ -94,10 +98,8 @@ uint8_t ReadSpeed(void) {
uint8_t val = (uint8_t)(ADC >> 2); uint8_t val = (uint8_t)(ADC >> 2);
// We want to set a minimum acceptable speed. //Map the speed value to the 100%-50% duty cycle range.
if (val < 32) { //val = (uint8_t)( (float)val / 255.0 ) * 100;
val = 32;
}
return val; return val;
} }
@ -139,11 +141,12 @@ uint8_t MotorGetSavedPos(void) {
void MotorMoveTo(uint8_t target) { void MotorMoveTo(uint8_t target) {
uint8_t on_delay = ReadFader(); uint8_t on_delay = ReadSpeed();
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);
@ -152,12 +155,12 @@ void MotorMoveTo(uint8_t target) {
} }
// The delay ratio controlls the PWM waveforms. // The delay ratio controlls the PWM waveforms.
for(uint8_t i = 0; i < on_delay; i++){ for (idx = 0; idx < on_delay; idx++) {
_delay_us(MOTOR_PULSE); _delay_us(MOTOR_PULSE);
} }
MotorCoast(); MotorCoast();
for(uint8_t i = 0; i < off_delay; i++){ for (;idx < 255; idx++) {
_delay_us(MOTOR_PULSE); _delay_us(MOTOR_PULSE);
} }
} }
@ -165,6 +168,7 @@ 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,5 +13,6 @@ 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
) )