Trammell Hudson avatar Trammell Hudson committed 16b5980

Slow clock to 2 Mhz, try various things to improve reliability

Comments (0)

Files changed (2)

 #   so your program will run at the correct speed.  You should also set this
 #   variable to same clock speed.  The _delay_ms() macro uses this, and many
 #   examples use this variable to calculate timings.  Do not add a "UL" here.
-F_CPU = 16000000
+F_CPU = 8000000
 
 
 # Output format. (can be srec, ihex, binary)
  * \file 45 baud sync teletype interface
  *
  * Uses a boost converter to make the 50-100V for driving the ciol.
+ * Test string:
+ * now is the time for all good men to come to the aid of their country
+ * the quick brown fox jumps over the lazy dogs
  */
 
 #include <avr/io.h>
 	uint8_t c
 )
 {
+	uint8_t ocr_one = OCR1C;
+	uint8_t ocr_zero = OCR1C;
+
+//#define BIT_CLOCK 22
+#define BIT_CLOCK 22000
+#define one_advance 0
+
+
 	// start bit
 	out(0xD7, 0);
+	OCR1C = ocr_zero;
 
-#define BIT_CLOCK 22
-//#define BIT_CLOCK 16666
-
-	_delay_ms(BIT_CLOCK); // + BIT_CLOCK/2);
+	_delay_us(BIT_CLOCK - 1000);
 
 	for (int i = 0 ; i < 5 ; i++)
 	{
 		c >>= 1;
 
 		if (!x)
+		{
+			OCR1C = ocr_one;
 			out(0xD7, 1);
-		else
+			_delay_us(100);
+		} else {
+			OCR1C = ocr_zero;
 			out(0xD7, 0);
+		}
 
-		_delay_ms(BIT_CLOCK);
+		_delay_us(BIT_CLOCK);
 	}
 
+	// And now send 1.5 stop bits
+	OCR1C = ocr_one;
 	out(0xD7, 1);
-	//_delay_ms(BIT_CLOCK);
-	//_delay_ms(BIT_CLOCK + BIT_CLOCK/2); // 1.42 stop bits
-	_delay_ms(6*BIT_CLOCK); // give it a few bits, slow but reliable
+
+	_delay_us(BIT_CLOCK);
+	_delay_us(BIT_CLOCK/2); // 1.42 stop bits
+
+	_delay_us(BIT_CLOCK); // give it a few bits, slow but reliable
+	_delay_us(BIT_CLOCK); // give it a few bits, slow but reliable
+	_delay_us(BIT_CLOCK); // give it a few bits, slow but reliable
+	_delay_us(BIT_CLOCK); // give it a few bits, slow but reliable
 }
 
 
 	uint8_t ch
 )
 {
+	if ('A' <= ch && ch <= 'Z')
+		ch += ('a' - 'A');
+
 	uint8_t c = ch ? baudot[ch] : 0x00;
 	if (c == 0 && ch != 0)
 		return;
 	if (current_mode != mode && mode != 0x3)
 	{
 		tty_out_raw(mode_select[mode]);
-		_delay_ms(5*BIT_CLOCK); // give it a few bits
+		_delay_us(BIT_CLOCK); // give it a few bits
+		_delay_us(BIT_CLOCK); // give it a few bits
+		_delay_us(BIT_CLOCK); // give it a few bits
+		_delay_us(BIT_CLOCK); // give it a few bits
 		current_mode = mode;
 	}
 
         cbi(TCCR1B, CS11);
         sbi(TCCR1B, CS10);
 
-	OCR1C = 0xDA; // very little off time makes the mosfet unhappy
+	// for the big shiny coil
+	//OCR1C = 0xF0; // very little off time makes the mosfet unhappy
+
+	// for the small black coil
+	OCR1C = 0xD0;
+
 	ddr(0xB7, 1);
 	out(0xB7, 1);
 }
 	usb_serial_write(buf, sizeof(buf));
 }
 
+// ckckckckckckckckckckckckckckckck
+// ryryryryryryryryryryryryryryryry
+
 
 
 
 int main(void)
 {
-	// set for 16 MHz clock
+	// set for 1 MHz clock so that we can do 45 baud
 #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
-	CPU_PRESCALE(0);
+	CPU_PRESCALE(1);
 
 	// Disable the ADC
 	ADMUX = 0;
 	ddr(0xD7, 1);
 	out(0xD7, 1);
 
+#define CONFIG_BOOST
+#ifdef CONFIG_BOOST
 	boost_setup();
+#else
+	// do no enable boost; allow a separate current loop disable
+	// the to diode drive coil.  Pull the MOSFET high to turn it off
+	ddr(0xB7, 1);
+	out(0xB7, 1);
+#endif
 
 	// initialize the USB, and then wait for the host
 	// to set configuration.  If the Teensy is powered
 		if (c == -1)
 			continue;
 
-		if (c == '+')
+		if (c == '{')
 		{
 			boost_adjust(10);
 			continue;
 		} else
-		if (c == '-')
+		if (c == '}')
 		{
 			boost_adjust(-10);
 			continue;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.