From: Robert Garbee Date: Wed, 18 Jul 2012 20:25:27 +0000 (-0600) Subject: Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos X-Git-Tag: 1.1~71 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=e2b472bbb2418fc13be42dbc7c52beb88479c46d;hp=b242f2756a8d9419a9bdba890b9e6b73560bdc19 Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos --- diff --git a/src/avr/ao_pwmin.c b/src/avr/ao_pwmin.c new file mode 100644 index 00000000..73a153b2 --- /dev/null +++ b/src/avr/ao_pwmin.c @@ -0,0 +1,70 @@ +/* + * Copyright © 2012 Robert D. Garbee + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao.h" +#include "ao_pwmin.h" + +/* + * This code implements a PWM input using ICP3. + * + * The initial use is to measure wind speed in the ULA/Ball summer intern + * project payload developed at Challenger Middle School. + */ + +volatile __data uint16_t ao_icp3_count; + +static void +ao_pwmin_display(void) __reentrant +{ + /* display the most recent value */ + printf("icp 3: %5u\n", ao_icp3_count); + +} +ISR(TIMER3_CAPT_vect) +{ + uint8_t lo = ICR3L; + uint8_t hi = ICR3H; + ao_icp3_count = (hi <<8) | lo; +} + +__code struct ao_cmds ao_pwmin_cmds[] = { + { ao_pwmin_display, "p\0PWM input" }, + { 0, NULL }, +}; + +void +ao_pwmin_init(void) +{ + /* do hardware setup here */ + TCCR3A = ((0 << WGM31) | /* normal mode, OCR3A */ + (0 << WGM30)); /* normal mode, OCR3A */ + TCCR3B = ((1 << ICNC3) | /* input capture noise canceler on */ + (0 << ICES3) | /* input capture on falling edge (don't care) */ + (0 << WGM33) | /* normal mode, OCR3A */ + (0 << WGM32) | /* normal mode, OCR3A */ + (4 << CS30)); /* clk/256 from prescaler */ + + + + TIMSK3 = (1 << ICIE3); /* Interrupt on input compare */ + + /* set the spike filter bit in the TCCR3B register */ + + ao_cmd_register(&ao_pwmin_cmds[0]); +} + + diff --git a/src/avr/ao_pwmin.h b/src/avr/ao_pwmin.h new file mode 100644 index 00000000..bbab4ddc --- /dev/null +++ b/src/avr/ao_pwmin.h @@ -0,0 +1,18 @@ +/* + * Copyright © 2012 Robert D. Garbee + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +void ao_pwmin_init(void); diff --git a/src/product/ao_telescience.c b/src/product/ao_telescience.c index 45b6d40e..2d594d7f 100644 --- a/src/product/ao_telescience.c +++ b/src/product/ao_telescience.c @@ -16,6 +16,7 @@ */ #include "ao.h" +#include "ao_pwmin.h" int main(void) @@ -34,6 +35,7 @@ main(void) ao_usb_init(); ao_adc_init(); ao_log_single_init(); + ao_pwmin_init(); ao_start_scheduler(); return 0; } diff --git a/src/telescience-v0.1/Makefile b/src/telescience-v0.1/Makefile index d24128ef..5542913d 100644 --- a/src/telescience-v0.1/Makefile +++ b/src/telescience-v0.1/Makefile @@ -53,6 +53,7 @@ ALTOS_SRC = \ ao_adc_avr.c \ ao_science_slave.c \ ao_spi_slave.c \ + ao_pwmin.c \ $(TELESCIENCE_STORAGE)\ $(TELESCIENCE_LOG)