aboutsummaryrefslogtreecommitdiffstats
path: root/notes
diff options
context:
space:
mode:
Diffstat (limited to 'notes')
-rw-r--r--notes/timers.txt77
-rw-r--r--notes/vga.txt32
2 files changed, 109 insertions, 0 deletions
diff --git a/notes/timers.txt b/notes/timers.txt
new file mode 100644
index 0000000..3e6bb9c
--- /dev/null
+++ b/notes/timers.txt
@@ -0,0 +1,77 @@
+
+Each timer (1-4) has 4 capture/compare channels (1-4). These are directly used
+by PWM but have a ton of other possible functionality. The STM32 implementation
+is particularly complicated with, eg, the ability to chain together timers
+
+Timer1 is an "advanced timer" with many more features. I think if we use just
+the "Capture and compare interrupt", and enable MOE during initialization
+everything will be ok. There are seperate Break, Update, and Trigger interrupts
+as well that we will ignore for now.
+
+Timer2,Ch 3+4 are D0 and D1, which conflict with Serial2. USART should work
+fine as long as pins aren't in output mode? and timers should work fine if
+Serial2 isn't in use?
+
+Misc Notes
+------------------------------------------------------------------------------
+implementation with case/switch in the interrupt handlers doesn't work; a lot
+of the time multiple interrupt flags are active at the same time (or become
+active?)
+
+TODO
+------------------------------------------------------------------------------
+- function to read out CCR registers
+- allow comparison output to the pin (a la PWM)
+- additional modes and configuration (up, down, up/down, etc)
+- Wirish (C++) higher level implementation
+- implement the update interrupt as a "5th channel"
+- track down and handle all pin conflicts
+- document
+
+Possible Wirish implementation
+------------------------------------------------------------------------------
+This recent implementation seems pretty clean:
+http://arduino.cc/pipermail/developers_arduino.cc/2010-June/002845.html
+
+ class Timer1Class {
+ public:
+ static void (*isrCompareA)(void);
+ static void (*isrCompareB)(void);
+
+ static const uint8_t PRESCALE1 = 1;
+ static const uint8_t PRESCALE8 = 2;
+ static const uint8_t PRESCALE64 = 3;
+ static const uint8_t PRESCALE256 = 4;
+ static const uint8_t PRESCALE1024 = 5;
+
+ const static uint8_t NORMAL = 0;
+ const static uint8_t CTC = 4;
+
+ void setPrescaleFactor(uint8_t factor);
+ void setMode(uint8_t mode);
+ uint16_t read();
+ void write(uint16_t val);
+ void writeCompareA(uint16_t val);
+ void writeCompareB(uint16_t val);
+ void attachCompareAInterrupt(void (*f)(void));
+ void attachCompareBInterrupt(void (*f)(void));
+ void detachCompareAInterrupt();
+ void detachCompareBInterrupt();
+ };
+
+ extern Timer1Class Timer1;
+
+Here's one of the more standard libaries out there:
+http://www.arduino.cc/playground/Code/Timer1
+
+ void initialize(long microseconds=1000000);
+ void start();
+ void stop();
+ void restart();
+ void setPeriod(long microseconds);
+ void pwm(char pin, int duty, long microseconds=-1);
+ void setPwmDuty(char pin, int duty);
+ void disablePwm(char pin);
+ void attachInterrupt(void (*isr)(), long microseconds=-1);
+ void detachInterrupt();
+
diff --git a/notes/vga.txt b/notes/vga.txt
new file mode 100644
index 0000000..2230f57
--- /dev/null
+++ b/notes/vga.txt
@@ -0,0 +1,32 @@
+
+classic digitalWrite() gives ~500ns pulse time (2MHz)
+
+gpio_write_bit() is about 360ns (2.78MHz)
+
+writing to GPIO?_BASE is about 60ns (16.6MHz -> 18MHz)
+
+pwm write 0x0001 is about 30ns (33MHz)
+pwm write 0x0001 is about 14ns (72MHz) with prescaler as 0 (!)
+
+1/25.125MHz = 39.72ns
+
+crude 640x480 directions:
+ www.epanorama.net/documents/pc/vga_timing.html
+ 480 lines
+ 31.77 us horizontal line length -> 2287.44 clock cycles -> 2287
+ 3.77 us sync period -> 271 clocks -> 271
+ 1.89 us front porch? -> 136 clocks -> 136
+ 25.17 us video -> 1812.24 clocks -> 1812
+
+ so...
+ 2287 reload
+ 271 1: Hsync high
+ 407 2: Video on
+ 2219 3: Video off
+ 2287 4: Hsync low
+
+ vertically, it's
+ 480 lines active video
+ 11 lines front porch
+ 2 lines Vsync (low)
+ 31 lines back porch