From 83ac9e297994b6dc83906b1b08534bf503252e49 Mon Sep 17 00:00:00 2001 From: "Ishan S. Patel" Date: Fri, 17 Sep 2021 15:13:02 -0400 Subject: [PATCH] yacwc --- .../1a8b631988403d72167c8d6baec2a73bac7faf7 | 1 - .../2adc7fbb2135c78f19d1a1b2028996567fb9053 | 1 - .../41672a6e402df6011c74e1ae975d7490093855fc | 1 - .../5580302ab4be68f0bc49bf4b1ff420d2f7107178 | 1 - .../687cfc15b1583ba4f8b41f2e61825e1ceba0a3f8 | 1 - .../76643e2f2dd3e91a2db2be5bb80d347d7acaddab | 1 - .../8682dd81be42c9dbff6320a6e76b466c66323e74 | 1 - .../8ed3d0c329f6d5902874651213f7016c3a965cfa | 1 - .../a8f3fbb525877d0d30c84aaf9893fa33f8b025c5 | 1 - .../dd22591090474e37abeef990af4d577cd8e2ffd0 | 1 - .../f5b4f3c1b2460fb4f304c807ea4f51f1d7479b5e | 37 -- graveyard.c | 236 +++++++ main.c | 608 +++++++----------- nbproject/configurations.xml | 3 +- 14 files changed, 468 insertions(+), 426 deletions(-) delete mode 100644 .generated_files/flags/default/1a8b631988403d72167c8d6baec2a73bac7faf7 delete mode 100644 .generated_files/flags/default/2adc7fbb2135c78f19d1a1b2028996567fb9053 delete mode 100644 .generated_files/flags/default/41672a6e402df6011c74e1ae975d7490093855fc delete mode 100644 .generated_files/flags/default/5580302ab4be68f0bc49bf4b1ff420d2f7107178 delete mode 100644 .generated_files/flags/default/687cfc15b1583ba4f8b41f2e61825e1ceba0a3f8 delete mode 100644 .generated_files/flags/default/76643e2f2dd3e91a2db2be5bb80d347d7acaddab delete mode 100644 .generated_files/flags/default/8682dd81be42c9dbff6320a6e76b466c66323e74 delete mode 100644 .generated_files/flags/default/8ed3d0c329f6d5902874651213f7016c3a965cfa delete mode 100644 .generated_files/flags/default/a8f3fbb525877d0d30c84aaf9893fa33f8b025c5 delete mode 100644 .generated_files/flags/default/dd22591090474e37abeef990af4d577cd8e2ffd0 delete mode 100644 .generated_files/flags/default/f5b4f3c1b2460fb4f304c807ea4f51f1d7479b5e create mode 100644 graveyard.c diff --git a/.generated_files/flags/default/1a8b631988403d72167c8d6baec2a73bac7faf7 b/.generated_files/flags/default/1a8b631988403d72167c8d6baec2a73bac7faf7 deleted file mode 100644 index c3421eb..0000000 --- a/.generated_files/flags/default/1a8b631988403d72167c8d6baec2a73bac7faf7 +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/birdptz.X/helpers_uart.c \ No newline at end of file diff --git a/.generated_files/flags/default/2adc7fbb2135c78f19d1a1b2028996567fb9053 b/.generated_files/flags/default/2adc7fbb2135c78f19d1a1b2028996567fb9053 deleted file mode 100644 index dd4938f..0000000 --- a/.generated_files/flags/default/2adc7fbb2135c78f19d1a1b2028996567fb9053 +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/camera_ptz.X/mcc_generated_files/examples/twi0_master_example.c \ No newline at end of file diff --git a/.generated_files/flags/default/41672a6e402df6011c74e1ae975d7490093855fc b/.generated_files/flags/default/41672a6e402df6011c74e1ae975d7490093855fc deleted file mode 100644 index 6979274..0000000 --- a/.generated_files/flags/default/41672a6e402df6011c74e1ae975d7490093855fc +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -g -DDEBUG -gdwarf-2 -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/birdptz.X/helpers_i2c.c \ No newline at end of file diff --git a/.generated_files/flags/default/5580302ab4be68f0bc49bf4b1ff420d2f7107178 b/.generated_files/flags/default/5580302ab4be68f0bc49bf4b1ff420d2f7107178 deleted file mode 100644 index 8974f83..0000000 --- a/.generated_files/flags/default/5580302ab4be68f0bc49bf4b1ff420d2f7107178 +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -g -DDEBUG -gdwarf-2 -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/birdptz.X/helpers_uart.c \ No newline at end of file diff --git a/.generated_files/flags/default/687cfc15b1583ba4f8b41f2e61825e1ceba0a3f8 b/.generated_files/flags/default/687cfc15b1583ba4f8b41f2e61825e1ceba0a3f8 deleted file mode 100644 index 668fc0c..0000000 --- a/.generated_files/flags/default/687cfc15b1583ba4f8b41f2e61825e1ceba0a3f8 +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -g -DDEBUG -gdwarf-2 -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/birdptz.X/main.c \ No newline at end of file diff --git a/.generated_files/flags/default/76643e2f2dd3e91a2db2be5bb80d347d7acaddab b/.generated_files/flags/default/76643e2f2dd3e91a2db2be5bb80d347d7acaddab deleted file mode 100644 index 862b462..0000000 --- a/.generated_files/flags/default/76643e2f2dd3e91a2db2be5bb80d347d7acaddab +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/birdptz.X/main.c \ No newline at end of file diff --git a/.generated_files/flags/default/8682dd81be42c9dbff6320a6e76b466c66323e74 b/.generated_files/flags/default/8682dd81be42c9dbff6320a6e76b466c66323e74 deleted file mode 100644 index 8289fc1..0000000 --- a/.generated_files/flags/default/8682dd81be42c9dbff6320a6e76b466c66323e74 +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/birdptz.X/helpers_i2c.c \ No newline at end of file diff --git a/.generated_files/flags/default/8ed3d0c329f6d5902874651213f7016c3a965cfa b/.generated_files/flags/default/8ed3d0c329f6d5902874651213f7016c3a965cfa deleted file mode 100644 index 6fedea5..0000000 --- a/.generated_files/flags/default/8ed3d0c329f6d5902874651213f7016c3a965cfa +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -g -DDEBUG -gdwarf-2 -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/camera_ptz.X/mcc_generated_files/examples/twi0_master_example.c \ No newline at end of file diff --git a/.generated_files/flags/default/a8f3fbb525877d0d30c84aaf9893fa33f8b025c5 b/.generated_files/flags/default/a8f3fbb525877d0d30c84aaf9893fa33f8b025c5 deleted file mode 100644 index 0a36e5e..0000000 --- a/.generated_files/flags/default/a8f3fbb525877d0d30c84aaf9893fa33f8b025c5 +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/camera_ptz.X/mcc_generated_files/src/twi0_master.c \ No newline at end of file diff --git a/.generated_files/flags/default/dd22591090474e37abeef990af4d577cd8e2ffd0 b/.generated_files/flags/default/dd22591090474e37abeef990af4d577cd8e2ffd0 deleted file mode 100644 index d3743d5..0000000 --- a/.generated_files/flags/default/dd22591090474e37abeef990af4d577cd8e2ffd0 +++ /dev/null @@ -1 +0,0 @@ - $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -g -DDEBUG -gdwarf-2 -x c -D__$(MP_PROCESSOR_OPTION)__ -mdfp="${DFP_DIR}/xc8" -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD) -gdwarf-3 /home/thebears/Seafile/Designs/AVR/camera_ptz.X/mcc_generated_files/src/twi0_master.c \ No newline at end of file diff --git a/.generated_files/flags/default/f5b4f3c1b2460fb4f304c807ea4f51f1d7479b5e b/.generated_files/flags/default/f5b4f3c1b2460fb4f304c807ea4f51f1d7479b5e deleted file mode 100644 index 150f3b1..0000000 --- a/.generated_files/flags/default/f5b4f3c1b2460fb4f304c807ea4f51f1d7479b5e +++ /dev/null @@ -1,37 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# -# This file contains information about the location of compilers and other tools. -# If you commmit this file into your revision control server, you will be able to -# to checkout the project and build it from the command line with make. However, -# if more than one person works on the same project, then this file might show -# conflicts since different users are bound to have compilers in different places. -# In that case you might choose to not commit this file and let MPLAB X recreate this file -# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at -# least once so the file gets created and the project can be built. Finally, you can also -# avoid using this file at all if you are only building from the command line with make. -# You can invoke make with the values of the macros: -# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ... -# -PATH_TO_IDE_BIN=/opt/microchip/mplabx/v5.50/mplab_platform/platform/../mplab_ide/modules/../../bin/ -# Adding MPLAB X bin directory to path. -PATH:=/opt/microchip/mplabx/v5.50/mplab_platform/platform/../mplab_ide/modules/../../bin/:$(PATH) -# Path to java used to run MPLAB X when this makefile was created -MP_JAVA_PATH="/opt/microchip/mplabx/v5.50/sys/java/zulu8.40.0.25-ca-fx-jre8.0.222-linux_x64/bin/" -OS_CURRENT="$(shell uname -s)" -MP_CC="/opt/microchip/xc8/v2.32/bin/xc8-cc" -# MP_CPPC is not defined -# MP_BC is not defined -MP_AS="/opt/microchip/xc8/v2.32/bin/xc8-cc" -MP_LD="/opt/microchip/xc8/v2.32/bin/xc8-cc" -MP_AR="/opt/microchip/xc8/v2.32/bin/xc8-ar" -DEP_GEN=${MP_JAVA_PATH}java -jar "/opt/microchip/mplabx/v5.50/mplab_platform/platform/../mplab_ide/modules/../../bin/extractobjectdependencies.jar" -MP_CC_DIR="/opt/microchip/xc8/v2.32/bin" -# MP_CPPC_DIR is not defined -# MP_BC_DIR is not defined -MP_AS_DIR="/opt/microchip/xc8/v2.32/bin" -MP_LD_DIR="/opt/microchip/xc8/v2.32/bin" -MP_AR_DIR="/opt/microchip/xc8/v2.32/bin" -# MP_BC_DIR is not defined -DFP_DIR=/opt/microchip/mplabx/v5.50/packs/Microchip/ATmega_DFP/2.3.126 diff --git a/graveyard.c b/graveyard.c new file mode 100644 index 0000000..f6aa65f --- /dev/null +++ b/graveyard.c @@ -0,0 +1,236 @@ + +//#include "helpers_i2c.h" +//#include +//uint16_t adcVal; +//uint8_t val; +//void ADC0_init(void); +//uint16_t ADC0_read_a(void); +//uint16_t ADC0_read_b(void); + + + + +//uint16_t step_n_zoom = 0; +//uint16_t step_n_focus = 0; +//uint16_t step_n_iris = 0; + +// +//#define max_zoom_steps 2994 +//#define max_focus_steps 5180 +//#define max_iris_steps 77 + +// +//int8_t last_dir_zoom = 0; +//int8_t last_dir_focus = 0; +// +//bool focus_iris_max; +//bool focus_iris_min; +//bool focus_zoom_max; +//bool focus_zoom_min; +//bool focus_past_max; +//bool focus_past_min; +//// Zoom +//#define m1_p1 2 +//#define m1_p2 3 +//#define m1_p3 4 +//#define m1_p4 5 +//#define deltime1 750 +// +//// Focus +//#define m2_p1 5 +//#define m2_p2 4 +//#define m2_p3 1 +//#define m2_p4 0 +//#define deltime2 750 +// +//// P-Iris +//#define m3_p1 4 +//#define m3_p2 5 +//#define m3_p3 6 +//#define m3_p4 7 +//#define deltime3 2500 + + + // + // for (int i = 0; i < abs(steps); i++) { + // phase = abs(step_n_iris % 4); + // focus_iris_max = (step_n_iris >= max_iris_steps) && (steps > 0); + // focus_iris_min = (step_n_iris <= 0) && (steps < 0); + // + // if (focus_iris_max || focus_iris_min) { + // return; + // } + // + // step_phased(&PORTC, &PORTC, &PORTC, &PORTC, m3_p1, m3_p2, m3_p3, m3_p4, phase); + // _delay_us(deltime3); + // if (steps > 0) { + // step_n_iris++; + // } else if (steps < 0) { + // step_n_iris--; + // } + // } + //} + // for (int i = 0; i < abs(steps); i++) { + // phase = abs(step_n_zoom % 4); + // focus_zoom_max = (step_n_zoom >= max_zoom_steps) && (steps > 0); + // focus_zoom_min = (step_n_zoom <= 0) && (steps < 0); + // if (focus_zoom_max || focus_zoom_min) { + // return; + // } + // + // step_phased(&PORTA, &PORTA, &PORTA, &PORTA, m1_p1, m1_p2, m1_p3, m1_p4, phase); + // _delay_us(deltime1); + // if (steps > 0) { + // step_n_zoom++; + // } else if (steps < 0) { + // step_n_zoom--; + // } + // } + + // for (int i = 0; i < abs(steps); i++) { + // focus_past_max = (step_n_focus >= max_focus_steps) && (steps > 0); + // focus_past_min = (step_n_focus <= 0) && (steps < 0); + // if (focus_past_max || focus_past_min) { + // return; + // } + // + // phase = abs(step_n_focus % 4); + // step_phased(&PORTB, &PORTB, &PORTC, &PORTC, m2_p1, m2_p2, m2_p3, m2_p4, phase); + // _delay_us(deltime2); + // if (steps > 0) { + // step_n_focus++; + // } else if (steps < 0) { + // step_n_focus--; + // } + // } +// +//void home_focus() { +// step_n_focus = max_focus_steps + 200; +// step_focus_phased(-100); +// for (int i = 0; i < max_focus_steps; i++) { +// step_focus_phased(-1); +// if (update_focus_limit()) { +// break; +// } +// } +// step_n_focus = 0; +//} +// +//void home_zoom() { +// step_n_zoom = max_zoom_steps + 200; +// step_zoom_phased(-100); +// for (int i = 0; i < max_zoom_steps; i++) { +// step_zoom_phased(-1); +// if (update_zoom_limit()) { +// break; +// } +// } +// step_n_zoom = 0; +//} +// +//void home_iris() { +// step_n_iris = max_iris_steps + 200; +// step_iris_phased(-100); +// step_n_iris = 0; +// +//} + + + // USART0_sendString("focus->"); + // home_focus(); + // USART0_sendString("\niris->"); + // home_iris(); + // USART0_sendString("\nhome->"); + // home_zoom(); + // USART0_sendString("\n"); + + + + // uart_print_binary(val, " \n"); + // adcVal = ADC0_read_a(); + // uart_print_uint8(adcVal, " "); + // adcVal = ADC0_read_b(); + // uart_print_uint8(adcVal, " "); + + +//void ADC0_init(void) { +// +// PORTD.PIN0CTRL &= ~PORT_ISC_gm; +// PORTD.PIN0CTRL |= PORT_ISC_INPUT_DISABLE_gc; +// PORTD.PIN0CTRL &= ~PORT_PULLUPEN_bm; +// +// PORTD.PIN1CTRL &= ~PORT_ISC_gm; +// PORTD.PIN1CTRL |= PORT_ISC_INPUT_DISABLE_gc; +// PORTD.PIN1CTRL &= ~PORT_PULLUPEN_bm; +// +// ADC0.CTRLC = ADC_PRESC_DIV4_gc +// | ADC_REFSEL_VDDREF_gc; +// ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */ +// | ADC_RESSEL_10BIT_gc; /* 10-bit mode */ +// /* Select ADC channel */ +// +//} +// +//uint16_t ADC0_read_a(void) { +// /* Start ADC conversion */ +// /* Start ADC conversion */ +// ADC0.MUXPOS = ADC_MUXPOS_AIN0_gc; +// ADC0.COMMAND = ADC_STCONV_bm; +// /* Wait until ADC conversion done */ +// while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) { +// ; +// } +// /* Clear the interrupt flag by writing 1: */ +// ADC0.INTFLAGS = ADC_RESRDY_bm; +// return ADC0.RES; +//} +// +//uint16_t ADC0_read_b(void) { +// /* Start ADC conversion */ +// /* Start ADC conversion */ +// ADC0.MUXPOS = ADC_MUXPOS_AIN1_gc; +// ADC0.COMMAND = ADC_STCONV_bm; +// /* Wait until ADC conversion done */ +// while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) { +// ; +// } +// /* Clear the interrupt flag by writing 1: */ +// ADC0.INTFLAGS = ADC_RESRDY_bm; +// return ADC0.RES; +//} + + +//ISR(PORTD_PORT_vect) { +// +// if (PORTD.INTFLAGS & PIN1_bm) { +// update_focus_limit(); +// PORTD.INTFLAGS &= PIN1_bm; +// } else if (PORTD.INTFLAGS & PIN0_bm) { +// update_zoom_limit(); +// PORTD.INTFLAGS &= PIN0_bm; +// +// }; +//} + + +// +// // Zoom +// PORTA.DIRSET = _BV(m1_p1); +// PORTA.DIRSET = _BV(m1_p4); +// PORTA.DIRSET = _BV(m1_p2); +// PORTA.DIRSET = _BV(m1_p3); +// +// // Focus +// PORTB.DIRSET = _BV(m2_p1); +// PORTB.DIRSET = _BV(m2_p2); +// PORTC.DIRSET = _BV(m2_p3); +// PORTC.DIRSET = _BV(m2_p4); +// +// // Iris motor +// PORTC.DIRSET = _BV(m3_p1); +// PORTC.DIRSET = _BV(m3_p2); +// PORTC.DIRSET = _BV(m3_p3); +// PORTC.DIRSET = _BV(m3_p4); + +// PORTD.PIN0CTRL |= PORT_ISC_BOTHEDGES_gc; +// PORTD.PIN1CTRL |= PORT_ISC_BOTHEDGES_gc; diff --git a/main.c b/main.c index 69e6a41..24fab3f 100644 --- a/main.c +++ b/main.c @@ -1,10 +1,3 @@ -/* - * File: main.c - * Author: thebears - * - * Created on September 13, 2021, 3:12 PM - */ - #define F_CPU 3333333 #define USART0_BAUD_RATE(BAUD_RATE) ((float)(3333333 * 64 / (16 * (float)BAUD_RATE)) + 0.5) #include @@ -14,419 +7,278 @@ #include #include #include "helpers_uart.h" -//#include "helpers_i2c.h" -#include + #include #include "twi0_master_example.h" -uint16_t adcVal; -uint8_t val; -void ADC0_init(void); -uint16_t ADC0_read_a(void); -uint16_t ADC0_read_b(void); -bool limit_zoom = false; -bool limit_focus = false; -uint16_t step_n_zoom = 0; -uint16_t step_n_focus = 0; -uint16_t step_n_iris = 0; +#define delay_time 50 +// Zoom, Focus, Iris +struct PORT_struct *port_1[] = {&PORTA, &PORTB, &PORTC}; +struct PORT_struct *port_2[] = {&PORTA, &PORTB, &PORTC}; +struct PORT_struct *port_3[] = {&PORTA, &PORTC, &PORTC}; +struct PORT_struct *port_4[] = {&PORTA, &PORTC, &PORTC}; -#define max_zoom_steps 2994 -#define max_focus_steps 5180 -#define max_iris_steps 77 +uint8_t pin_1[] = {2, 5, 4}; +uint8_t pin_2[] = {3, 4, 5}; +uint8_t pin_3[] = {4, 1, 6}; +uint8_t pin_4[] = {5, 0, 7}; + +uint8_t delay[] = {15, 15, 50}; // Multiples of "delay_time" +uint16_t max_steps[] = {2994, 5180, 77}; +int16_t current_step[] = {0, 0, 0}; + +uint8_t enable_port[] = {2, 3, 4}; + +bool motor_max_pos; +bool motor_min_pos; uint8_t phase; -int8_t last_dir_zoom = 0; -int8_t last_dir_focus = 0; +uint8_t motor_num; +uint8_t port_val; -bool focus_iris_max; -bool focus_iris_min; -bool focus_zoom_max; -bool focus_zoom_min; -bool focus_past_max; -bool focus_past_min; -// Zoom -#define m1_p1 2 -#define m1_p2 3 -#define m1_p3 4 -#define m1_p4 5 -#define deltime1 750 +void init_port_expander() +{ + I2C0_example_write1ByteRegister(32, 0x00, 0x00); + I2C0_example_write1ByteRegister(32, 0x00, 0x00); +} -// Focus -#define m2_p1 5 -#define m2_p2 4 -#define m2_p3 1 -#define m2_p4 0 -#define deltime2 750 +void set_expanded_port_on(uint8_t num) +{ + port_val = I2C0_example_read1ByteRegister(32, 0x09); + port_val |= _BV(num); + I2C0_example_write1ByteRegister(32, 0x09, port_val); +} -// P-Iris -#define m3_p1 4 -#define m3_p2 5 -#define m3_p3 6 -#define m3_p4 7 -#define deltime3 2500 - -#define delay_time 100 +void set_expanded_port_off(uint8_t num) +{ + port_val = I2C0_example_read1ByteRegister(32, 0x09); + port_val &= ~_BV(num); + I2C0_example_write1ByteRegister(32, 0x09, port_val); +} -void step_phased(struct PORT_struct * p1, struct PORT_struct * p2, struct PORT_struct * p3, struct PORT_struct * p4, uint8_t m1, uint8_t m2, uint8_t m3, uint8_t m4, uint8_t phase) { +void battery_charging_on() +{ + set_expanded_port_on(0); +} + +void battery_charging_off() +{ + set_expanded_port_off(0); +} + +void battery_power_supply_on() +{ + set_expanded_port_on(1); +} + +void battery_power_supply_off() +{ + set_expanded_port_off(1); +} + +void power_3v3_on() +{ + // Turn on 3.3V relay + PORTA.DIRSET = _BV(6); + PORTA.OUTSET = _BV(6); +} + +void power_3v3_off() +{ + // Turn off 3.3V relay + PORTA.DIRSET = _BV(6); + PORTA.OUTCLR = _BV(6); +} - if (phase == 0) { - p1->OUTSET = _BV(m1); - p2->OUTCLR = _BV(m2); - p3->OUTSET = _BV(m3); - p4->OUTCLR = _BV(m4); - } else if (phase == 1) { - p1->OUTCLR = _BV(m1); - p2->OUTSET = _BV(m2); - p3->OUTSET = _BV(m3); - p4->OUTCLR = _BV(m4); - } else if (phase == 2) { - p1->OUTCLR = _BV(m1); - p2->OUTSET = _BV(m2); - p3->OUTCLR = _BV(m3); - p4->OUTSET = _BV(m4); - } else if (phase == 3) { - p1->OUTSET = _BV(m1); - p2->OUTCLR = _BV(m2); - p3->OUTCLR = _BV(m3); - p4->OUTSET = _BV(m4); - } +void delay_n_units(uint8_t n) +{ + for (int i = 0; i < n; i++) { + _delay_us(delay_time); + } + +}; + +void step_phased(struct PORT_struct * p1, struct PORT_struct * p2, struct PORT_struct * p3, struct PORT_struct * p4, uint8_t m1, uint8_t m2, uint8_t m3, uint8_t m4, uint8_t phase) +{ + + + if (phase == 0) { + p1->OUTSET = _BV(m1); + p2->OUTCLR = _BV(m2); + p3->OUTSET = _BV(m3); + p4->OUTCLR = _BV(m4); + } else if (phase == 1) { + p1->OUTCLR = _BV(m1); + p2->OUTSET = _BV(m2); + p3->OUTSET = _BV(m3); + p4->OUTCLR = _BV(m4); + } else if (phase == 2) { + p1->OUTCLR = _BV(m1); + p2->OUTSET = _BV(m2); + p3->OUTCLR = _BV(m3); + p4->OUTSET = _BV(m4); + } else if (phase == 3) { + p1->OUTSET = _BV(m1); + p2->OUTCLR = _BV(m2); + p3->OUTCLR = _BV(m3); + p4->OUTSET = _BV(m4); + } } -void step_iris_phased(int steps) { +void step_motor(uint8_t i, int s) +{ + set_expanded_port_on(i); + for (int n = 0; i < abs(s); n++) { + phase = abs(current_step[i] % 4); + motor_max_pos = (current_step[i] >= max_steps[i]) && (s > 0); + motor_min_pos = (current_step[i] <= 0) && (s < 0); - for (int i = 0; i < abs(steps); i++) { - phase = abs(step_n_iris % 4); - focus_iris_max = (step_n_iris >= max_iris_steps) && (steps > 0); - focus_iris_min = (step_n_iris <= 0) && (steps < 0); + if (motor_max_pos || motor_min_pos) { + return; + } - if (focus_iris_max || focus_iris_min) { - return; - } + step_phased(port_1[i], port_2[i], port_3[i], port_4[i], pin_1[i], pin_2[i], pin_3[i], pin_4[i], phase); + delay_n_units(delay[i]); - step_phased(&PORTC, &PORTC, &PORTC, &PORTC, m3_p1, m3_p2, m3_p3, m3_p4, phase); - _delay_us(deltime3); - if (steps > 0) { - step_n_iris++; - } else if (steps < 0) { - step_n_iris--; - } - } -} + if (s > 0) { + current_step[i]++; + } else if (s < 0) { + current_step[i]--; + } + } -void step_zoom_phased(int steps) { - - - for (int i = 0; i < abs(steps); i++) { - phase = abs(step_n_zoom % 4); - focus_zoom_max = (step_n_zoom >= max_zoom_steps) && (steps > 0); - focus_zoom_min = (step_n_zoom <= 0) && (steps < 0); - if (focus_zoom_max || focus_zoom_min) { - return; - } - - step_phased(&PORTA, &PORTA, &PORTA, &PORTA, m1_p1, m1_p2, m1_p3, m1_p4, phase); - _delay_us(deltime1); - if (steps > 0) { - step_n_zoom++; - } else if (steps < 0) { - step_n_zoom--; - } - - - } } -void step_focus_phased(int steps) { - for (int i = 0; i < abs(steps); i++) { - focus_past_max = (step_n_focus >= max_focus_steps) && (steps > 0); - focus_past_min = (step_n_focus <= 0) && (steps < 0); - if (focus_past_max || focus_past_min) { - return; - } +void step_iris_phased(int steps) +{ + set_expanded_port_on(2); + step_motor(2, steps); + set_expanded_port_off(2); +} - phase = abs(step_n_focus % 4); - step_phased(&PORTB, &PORTB, &PORTC, &PORTC, m2_p1, m2_p2, m2_p3, m2_p4, phase); - _delay_us(deltime2); - if (steps > 0) { - step_n_focus++; - } else if (steps < 0) { - step_n_focus--; - } - } +void step_zoom_phased(int steps) +{ + set_expanded_port_on(1); + step_motor(1, steps); + set_expanded_port_off(1); +} + +void step_focus_phased(int steps) +{ + set_expanded_port_on(0); + step_motor(0, steps); + set_expanded_port_off(0); +} + +bool at_zoom_limit() +{ + if (PORTD.IN & PIN0_bm) { + return false; + } else { + return true; + } +} + +bool at_focus_limit() +{ + + if (PORTD.IN & PIN1_bm) { + return false; + } else { + return true; + } } -bool update_zoom_limit() { - if (PORTD.IN & PIN0_bm) { - limit_zoom = false; - } else { - limit_zoom = true; - } - return limit_zoom; +void home_focus() +{ + motor_num = 0; + current_step[motor_num] = max_steps[motor_num] + 200; + step_motor(motor_num, -100); + for (int i = 0; i < max_steps[motor_num]; i++) { + step_motor(motor_num, -1); + if (at_focus_limit()) { + break; + } + } + current_step[motor_num] = 0; } -bool update_focus_limit() { - - if (PORTD.IN & PIN1_bm) { - limit_focus = false; - } else { - limit_focus = true; - } - return limit_focus; +void home_zoom() +{ + motor_num = 1; + current_step[motor_num] = max_steps[motor_num] + 200; + step_motor(motor_num, -100); + for (int i = 0; i < max_steps[motor_num]; i++) { + step_motor(motor_num, -1); + if (at_zoom_limit()) { + break; + } + } + current_step[motor_num] = 0; } -void ir_filter_on() { - PORTB.OUTCLR = _BV(2); - PORTB.OUTSET = _BV(3); - _delay_ms(100); - PORTB.OUTCLR = _BV(3); +void home_iris() +{ + motor_num = 3; + current_step[motor_num] = max_steps[motor_num] + 200; + step_motor(motor_num, -100); + current_step[motor_num] = 0; } -void ir_filter_off() { - PORTB.OUTCLR = _BV(3); - PORTB.OUTSET = _BV(2); - _delay_ms(100); - PORTB.OUTCLR = _BV(2); +void ir_filter_on() +{ + PORTB.OUTCLR = _BV(2); + PORTB.OUTSET = _BV(3); + _delay_ms(100); + PORTB.OUTCLR = _BV(3); } -void home_focus() { - step_n_focus = max_focus_steps + 200; - step_focus_phased(-100); - for (int i = 0; i < max_focus_steps; i++) { - step_focus_phased(-1); - if (update_focus_limit()) { - break; - } - } - step_n_focus = 0; +void ir_filter_off() +{ + PORTB.OUTCLR = _BV(3); + PORTB.OUTSET = _BV(2); + _delay_ms(100); + PORTB.OUTCLR = _BV(2); } -void home_zoom() { - step_n_zoom = max_zoom_steps + 200; - step_zoom_phased(-100); - for (int i = 0; i < max_zoom_steps; i++) { - step_zoom_phased(-1); - if (update_zoom_limit()) { - break; - } - } - step_n_zoom = 0; +void init_pins() +{ + // Pins for reading endstops on lens assembly + PORTD.DIRCLR = PIN0_bm; + PORTD.DIRCLR = PIN1_bm; + + // IR Filter + PORTB.DIRSET = _BV(2); + PORTB.DIRSET = _BV(3); + + //i2c muxing + PORTMUX.TWISPIROUTEA = 0x23; } -void home_iris() { - step_n_iris = max_iris_steps + 200; - step_iris_phased(-100); - step_n_iris = 0; +int main(void) +{ + I2C0_Initialize(); + init_port_expander(); + USART0_init(); + + while (1) { + step_zoom_phased(6000); + step_iris_phased(100); + step_focus_phased(2000); + + step_zoom_phased(-6000); + step_iris_phased(-100); + step_focus_phased(-2000); + } + return 0; } - -ISR(PORTD_PORT_vect) { - - if (PORTD.INTFLAGS & PIN1_bm) { - update_focus_limit(); - PORTD.INTFLAGS &= PIN1_bm; - } else if (PORTD.INTFLAGS & PIN0_bm) { - update_zoom_limit(); - PORTD.INTFLAGS &= PIN0_bm; - - }; -} - -int main(void) { - - - PORTA.OUTSET = _BV(6); - - - PORTD.DIRCLR = PIN0_bm; - PORTD.DIRCLR = PIN1_bm; - - PORTD.PIN0CTRL |= PORT_ISC_BOTHEDGES_gc; - PORTD.PIN1CTRL |= PORT_ISC_BOTHEDGES_gc; - - // Turn on 3.3V relay - PORTA.DIRSET = _BV(6); - - - // Zoom - PORTA.DIRSET = _BV(m1_p1); - PORTA.DIRSET = _BV(m1_p4); - PORTA.DIRSET = _BV(m1_p2); - PORTA.DIRSET = _BV(m1_p3); - - // Focus - PORTB.DIRSET = _BV(m2_p1); - PORTB.DIRSET = _BV(m2_p2); - PORTC.DIRSET = _BV(m2_p3); - PORTC.DIRSET = _BV(m2_p4); - - // Iris motor - PORTC.DIRSET = _BV(m3_p1); - PORTC.DIRSET = _BV(m3_p2); - PORTC.DIRSET = _BV(m3_p3); - PORTC.DIRSET = _BV(m3_p4); - - // IR Filter - PORTB.DIRSET = _BV(2); - PORTB.DIRSET = _BV(3); - - - - - - - - // sei(); - PORTMUX.TWISPIROUTEA = 0x23; - - _delay_ms(250); - I2C0_Initialize(); - I2C0_example_write1ByteRegister(32, 0x00, 0x00); - I2C0_example_write1ByteRegister(32, 0x09, 0xFF); - USART0_init(); - USART0_sendString("Started\n"); - - _delay_ms(250); - I2C0_example_write1ByteRegister(32, 0x09, 0x00); - _delay_ms(250); - I2C0_example_write1ByteRegister(32, 0x09, 0xFF); - - USART0_sendString("focus->"); - home_focus(); - USART0_sendString("\niris->"); - home_iris(); - USART0_sendString("\nhome->"); - home_zoom(); -USART0_sendString("\n"); - - while (1) { - step_zoom_phased(6000); - step_iris_phased(100); - step_focus_phased(2000); - - - step_zoom_phased(-6000); -// - step_iris_phased(-100); - step_focus_phased(-2000); - - - - _delay_ms(250); - - // ir_filter_off(); - // step_iris_phased(76); - // step_iris_phased(-76); - // _delay_ms(25); - // ir_filter_on(); - // step_iris(19); - //_delay_ms(250); - - // _delay_ms(500); - - // _delay_ms(500); - // - // step_focus(1000); - // step_focus(-1000); - // limit_focus = false; - // step_focus(-1000); - // limit_focus = false; - // step_zoom(1000); - // limit_zoom = false; - // step_zoom(-1000); - // limit_zoom = false; - - // step_focus(1000); - // if (limit_focus) - // { - // limit_focus = false; - // step_focus(-1000); - // } - - // step(1000); - // step2(1000); - - // _delay_ms(100); - USART0_sendString("-"); - - // uart_print_uint8(PORTD.IN & PIN0_bm,"p0 "); - // uart_print_uint8(PORTD.IN & PIN1_bm,"p1 \n ") - // step2(1000); - // PORTA.OUTSET = _BV(m1_p1); - // PORTA.OUTSET = _BV(m1_p2); - // PORTA.OUTSET = _BV(m1_p3); - // PORTA.OUTSET = _BV(m1_p4); - // - // PORTB.OUTSET = _BV(m2_p1); - // PORTB.OUTSET = _BV(m2_p2); - // PORTC.OUTSET = _BV(m2_p3); - // PORTC.OUTSET = _BV(m2_p4); - - // uart_print_binary(val, " \n"); - // adcVal = ADC0_read_a(); - // uart_print_uint8(adcVal, " "); - // adcVal = ADC0_read_b(); - // uart_print_uint8(adcVal, " "); - - // step(); - // step2(); - // USART0_sendString("---\n"); - } - - return 0; -} - -void ADC0_init(void) { - - PORTD.PIN0CTRL &= ~PORT_ISC_gm; - PORTD.PIN0CTRL |= PORT_ISC_INPUT_DISABLE_gc; - PORTD.PIN0CTRL &= ~PORT_PULLUPEN_bm; - - PORTD.PIN1CTRL &= ~PORT_ISC_gm; - PORTD.PIN1CTRL |= PORT_ISC_INPUT_DISABLE_gc; - PORTD.PIN1CTRL &= ~PORT_PULLUPEN_bm; - - ADC0.CTRLC = ADC_PRESC_DIV4_gc - | ADC_REFSEL_VDDREF_gc; - ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */ - | ADC_RESSEL_10BIT_gc; /* 10-bit mode */ - /* Select ADC channel */ - -} - -uint16_t ADC0_read_a(void) { - /* Start ADC conversion */ - /* Start ADC conversion */ - ADC0.MUXPOS = ADC_MUXPOS_AIN0_gc; - ADC0.COMMAND = ADC_STCONV_bm; - /* Wait until ADC conversion done */ - while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) { - ; - } - /* Clear the interrupt flag by writing 1: */ - ADC0.INTFLAGS = ADC_RESRDY_bm; - return ADC0.RES; -} - -uint16_t ADC0_read_b(void) { - /* Start ADC conversion */ - /* Start ADC conversion */ - ADC0.MUXPOS = ADC_MUXPOS_AIN1_gc; - ADC0.COMMAND = ADC_STCONV_bm; - /* Wait until ADC conversion done */ - while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) { - ; - } - /* Clear the interrupt flag by writing 1: */ - ADC0.INTFLAGS = ADC_RESRDY_bm; - return ADC0.RES; -} - diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index bdc6044..6c79971 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -27,6 +27,7 @@ Makefile main.c + graveyard.c ../camera_ptz.X/mcc_generated_files/src @@ -41,7 +42,7 @@ ATmega4809 - AtmelIceTool + Simulator XC8 2.32 2