Dangerous Prototypes

Other projects => Past projects => Open 7400 Competition => Topic started by: NiHaoMike on October 19, 2012, 05:32:37 am

Title: [Entry] Arbitrary Waveform Generator
Post by: NiHaoMike on October 19, 2012, 05:32:37 am
This is really just for fun - it doesn't make a very good function generator by modern standards. (If I wanted something to actually use, I would start with a FPGA...) Apart from that, however, it can generate a number of waveforms that an old analog function generator cannot. It uses a PC with a serial port to supply the waveform data. (Once programmed, however, it will keep running without the PC until power is disconnected.)
http://http://i46.tinypic.com/2czykva.png

Here's the Python code I used to generate the waveform seen on the scope:
Code: [Select]
import serial
import time
import math
import sys
s = serial.Serial(sys.argv[1],115200,8,'N',1,1,0,0)
time.sleep(0.5)
for x in range (0,32767):
y=chr(int(math.fabs(math.sin(x*math.pi/(pow(2,int(sys.argv[2])))))*127+128))
s.write(y)
for x in range (32768,65535):
y=chr(int(-math.fabs(math.sin(x*math.pi/(pow(2,int(sys.argv[2])))))*127+128))
s.write(y)
time.sleep(0.5)
s.setDTR(False)

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01262051968session_write_close ( )...(null):0
20.01302183560ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01302184336Database_MySQL->query( ).../DatabaseHandler.php:119
40.06362323072Database_MySQL->error( ).../Db-mysql.class.php:273