Attachment 'wobbulator2.6.3.py'

Download

   1 #!/usr/bin/env python3
   2 # RPi Wobbulator v2.63
   3 
   4 # Copyright (C) 2013-2014 Tom Herbison MI0IOU
   5 # Email tom@asliceofraspberrypi.co.uk
   6 # Web <http://www.asliceofraspberrypi.co.uk>
   7 
   8 # Special thanks to Tony Abbey for his efforts developing v2 of the software...
   9 # Edits by Tony Abbey for 10 speed up and continuous looping until STOP button
  10 # ADC now runs at either 60 sps 14 bits or 240 SPS and 12 bits in one-shot mode
  11 # to prevent glitches. Also added initialisation of frequency scan values,
  12 # "Fast" option, optional screen clear every sweep plus code suggested by
  13 # Fred LaPlante for a "scope-like" trace
  14 # Also Fred for horizontal frequency scale, and Tony for vertical scale
  15 # Now programmable display size and scales, stored in parameter file by Fred
  16 # MHz, kHz i/p etc by Dick Bronsdijk
  17 # Display tweaks by various and Tony added vertical text on Y scale
  18 # V 2.6 Addition of Y scale in dB and bias average of 2 readings - Tony
  19 # Version 2.61 scale updates when dBm clicked 
  20 
  21 # Please see "README.txt" for a description of this software
  22 # and for details of the version change log
  23 
  24 # If you wish to make changes to this software and would like your
  25 # changes to be incorporated into a future release please visit,
  26 # <https://github.com/mi0iou/RPi_Wobbulator> and 'fork' the repository
  27 
  28 # This program is free software: you can redistribute it and/or modify
  29 # it under the terms of the GNU General Public License as published by
  30 # the Free Software Foundation, either version 3 of the License, or
  31 # (at your option) any later version.
  32 
  33 # This program is distributed in the hope that it will be useful,
  34 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  35 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36 # GNU General Public License for more details.
  37 
  38 # You should have received a copy of the GNU General Public License
  39 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  40 
  41 # import GUI module
  42 from tkinter import *
  43 
  44 import time, sys
  45 
  46 # ---- get user preferences or set defaults ----
  47 # for param file persistence, import faster cPickle if available
  48 try:
  49     import cPickle as pickle
  50 except:
  51     import pickle
  52     
  53 params = {}
  54 try:
  55     # user parameters
  56     paramFN = 'wobParam.pkl'
  57     paramFile = open(paramFN,"rb")
  58     params = pickle.load(paramFile)
  59     #print (params)
  60     paramFile.close()
  61 except IOError:
  62     # default parameters
  63     params['chrtHt'] = 500
  64     params['chrtWid'] = 500
  65     params['xDivs'] = 10
  66     params['yDivs'] = 10
  67     params['canvFg'] = 'black'
  68     params['canvBg'] = 'cyan'
  69     params['fBegin'] = 1000000
  70     params['fEnd'] = 31000000
  71     params['fIntvl'] = 100000
  72     params['vgain'] = 132
  73     params['vchan'] = 0
  74     params['colour'] = 'blue'
  75     params['bias'] = 0
  76     params['fast'] = 0
  77     params['cls'] = 0
  78     params['grid'] = 1
  79     params['dB'] = 0
  80 # ---- end of user param support ----
  81 
  82 # ---- for app menus and associated displays ----
  83 from tkinter import messagebox
  84 from tkinter import colorchooser
  85 
  86 def notDone():
  87     messagebox.showerror('Not implemented', 'Not yet available')
  88 
  89 def getForegroundColor():
  90     fgColor = colorchooser.askcolor(params['canvFg'], title='Foreground Color')
  91     if fgColor[1] != 'None':
  92         params['canvFg'] = fgColor[1]
  93         app.canvFg = fgColor[1]
  94     #print (params['canvFg'])   
  95 
  96 def getBackgroundColor():
  97     bgColor = colorchooser.askcolor(params['canvBg'], title='Background Color')
  98     if bgColor[1] != 'None':
  99         params['canvBg'] = bgColor[1]
 100         app.canvBg = bgColor[1]
 101     #print (params['canvBg'])
 102 
 103 def getChartWidth():
 104     chrtWid = simpledialog.askinteger('Chart Width', '300 to 1000',initialvalue=params['chrtWid'],minvalue=300,maxvalue=1000)
 105     if chrtWid != 'None':
 106         params['chrtWid'] = chrtWid
 107         app.chrtWid = chrtWid
 108     #print (chrtWid)
 109 
 110 def getChartHeight():
 111     chrtHt = simpledialog.askinteger('Chart Height', '300 to 1000',initialvalue=params['chrtHt'],minvalue=300,maxvalue=1000)
 112     if chrtHt != 'None':
 113         params['chrtHt'] = chrtHt
 114         app.chrtHt = chrtHt
 115     #print (chrtHt)
 116 
 117 def getXdivisions():
 118     xDivs = simpledialog.askinteger('X-divisions', '10-50',initialvalue=params['xDivs'],minvalue=10,maxvalue=50)
 119     if xDivs != 'None':
 120         params['xDivs'] = xDivs
 121         app.xDivs = xDivs
 122     #print (xDivs)
 123 def getYdivisions():
 124     yDivs = simpledialog.askinteger('Y-divisions', '10-50',initialvalue=params['yDivs'],minvalue=10,maxvalue=50)
 125     if yDivs != 'None':
 126         params['yDivs'] = yDivs
 127         app.yDivs = yDivs
 128     #print (yDivs)
 129     
 130 def makemenu(win):
 131     top = Menu(win)
 132     win.config(menu=top)    # set its menu option
 133 
 134     file = Menu(top, tearoff=0)
 135     top.add_cascade(label='File', menu=file, underline=0)
 136     file.add_command(label='Exit', command=root.destroy, underline=1, accelerator='Ctrl+Q')
 137 
 138     opt = Menu(top, tearoff=0)
 139     top.add_cascade(label='Options', menu=opt, underline=0)
 140     opt.add_command(label='Background', command=getBackgroundColor, underline=0)
 141     opt.add_command(label='Foreground', command=getForegroundColor, underline=0)
 142     opt.add_separator()
 143     opt.add_command(label='Chart Width', command=getChartWidth, underline=6)
 144     opt.add_command(label='Chart Height', command=getChartHeight, underline=6)
 145     opt.add_separator()
 146     opt.add_command(label='X-divisions', command=getXdivisions, underline=0)
 147     opt.add_command(label='Y-divisions', command=getYdivisions, underline=0)
 148 
 149     help = Menu(top, tearoff=0)
 150     top.add_cascade(label='Help', menu=help, underline=0)
 151     help.add_command(label='About Wobbulator', command=notDone, underline=1)
 152 # ---- end of menu support ----
 153 
 154 # ---- RaspBerry Pi IO support ----
 155 #import quick2wire i2c module
 156 import quick2wire.i2c as i2c
 157 
 158 # import GPIO module
 159 import RPi.GPIO as GPIO
 160 
 161 # setup GPIO
 162 GPIO.setmode(GPIO.BOARD)
 163 GPIO.setwarnings(False)
 164 
 165 # Define GPIO pins
 166 W_CLK = 15
 167 FQ_UD = 16
 168 DATA = 18
 169 RESET = 22
 170 
 171 # setup IO bits
 172 GPIO.setup(W_CLK, GPIO.OUT)
 173 GPIO.setup(FQ_UD, GPIO.OUT)
 174 GPIO.setup(DATA, GPIO.OUT)
 175 GPIO.setup(RESET, GPIO.OUT)
 176 
 177 # initialize everything to zero
 178 GPIO.output(W_CLK, False)
 179 GPIO.output(FQ_UD, False)
 180 GPIO.output(DATA, False)
 181 GPIO.output(RESET, False)
 182 
 183 #define address for ADC chip, Arduino mini
 184 adc_address = 0x05
 185 
 186 # setup i2c bus
 187 bus = i2c.I2CMaster()
 188 
 189 # Function to send a pulse to GPIO pin
 190 def pulseHigh(pin):
 191     GPIO.output(pin, True)
 192     GPIO.output(pin, False)
 193     return
 194 # ---- end of RaspBerry Pi IO support ----
 195 
 196 # ---- application specific stuff starts here ----
 197 # Function to send a byte to AD9850 module
 198 def tfr_byte(data):
 199     for i in range (0,8):
 200         GPIO.output(DATA, data & 0x01)
 201         pulseHigh(W_CLK)
 202         data=data>>1
 203     return
 204 
 205 # Function to send frequency (assumes 125MHz xtal) to AD9850 module
 206 def sendFrequency(frequency):
 207     freq=int(frequency*4294967296/125000000)
 208     for b in range (0,4):
 209         tfr_byte(freq & 0xFF)
 210         freq=freq>>8
 211     tfr_byte(0x00)
 212     pulseHigh(FQ_UD)
 213     return
 214 
 215 # Function to set address for ADC
 216 def changechannel(address, adcConfig):
 217     bus.transaction(i2c.writing_bytes(address, adcConfig))
 218     return
 219 
 220 # Function to get reading from ADC (12 bit mode)
 221 #def getadcreading(address, adcConfig): # << changed afa
 222 #    bus.transaction(i2c.writing_bytes(address, adcConfig)) # << added afa 
 223 #    m, l ,s = bus.transaction(i2c.reading(address,3))[0]
 224 #    while (s & 128):
 225 #        m, l, s  = bus.transaction(i2c.reading(address,3))[0]
 226 #    # shift bits to product result
 227 #    t = (m << 8) | l
 228     # check if positive or negative number and invert if needed
 229 #    if (m > 128):
 230 #        t = ~(0x02000 - t)
 231 #    if root.fast:
 232 #        return (t * 0.001) # 1mV per DN in 12 bit mode
 233 #    else:
 234 #        return (t * 0.00025) # 0.25mV per DN in 14 bit mode
 235 
 236 # Function to get reading from Arduino ADC
 237 def getadcreading(address):
 238     # channel 1 = box
 239     # channel 3 = local signal
 240     bus.transaction(i2c.writing_bytes(0x05, 0x03))
 241     time.sleep(.001)
 242     avhigh, avlow = bus.transaction(i2c.reading(address,2))[0]
 243     #while (s & 128):
 244     #   h, m, l, s  = bus.transaction(i2c.reading(address,4))[0]
 245     # shift bits to product result
 246     t = (avhigh << 8) | avlow
 247     # Uref = 3.32 V / 1023 (10 Bit) = 308 -> scale in Volt
 248     return (t / 308)
 249 
 250 # Function to convert frequency f to Hz and return as int value
 251 #          e.g.: 10 MHz, 14.1m, 1k, 3.67 Mhz, 1.2 khz
 252 def fconv(f):	
 253 	f = f.upper()	
 254 	if f.find("K") > 0:	
 255   		return (int(float(f[:f.find("K")]) * 1000))	
 256 	elif f.find("M") > 0:	
 257   		return (int(float(f[:f.find("M")]) * 1000000))	
 258 	else:	
 259   		return (int(float(f)))	
 260 
 261 # Class definition for WobbyPi application
 262 class WobbyPi():
 263 
 264     # Build Graphical User Interface
 265     #def __init__(self, master):
 266     def __init__(self, master, params):
 267         frame = Frame(master, bd=10)
 268         frame.pack(fill=BOTH,expand=1)
 269 
 270         self.chrtHt = 0
 271 
 272         # setup working parameters
 273         # system values
 274         self.mrgnLeft = 56 #<-changed ta
 275         self.mrgnRight = 20 
 276         self.mrgnTop = 10 
 277         self.mrgnBotm = 30
 278         # user values
 279         self.canvFg = params['canvFg']
 280         self.canvBg = params['canvBg']
 281         self.chrtHt = int(params['chrtHt'])
 282         self.chrtWid = int(params['chrtWid'])
 283         self.xDivs = params['xDivs']
 284         self.yDivs = params['yDivs']
 285         self.fBegin = params['fBegin']
 286         self.fEnd = params['fEnd']
 287         self.fIntvl = params['fIntvl']
 288 
 289         # setup canvas to display results
 290         global canvas
 291         self.canvHt = self.mrgnTop + self.chrtHt + self.mrgnBotm
 292         self.canvWid = self.mrgnLeft + self.chrtWid + self.mrgnRight
 293         canvas = Canvas(frame, width=self.canvWid, height=self.canvHt, bg=self.canvBg)
 294         canvas.grid(row=0, column=0, columnspan=6, rowspan=10)
 295         ampdivlabel = Label(frame, text='10dB/div')
 296         ampdivlabel.grid(row=0, column=6)
 297 
 298         # choose channel
 299         channelframe = LabelFrame(frame, text='Ch', labelanchor='n')
 300         self.channel = IntVar()
 301         g1 = Radiobutton(channelframe, text='1', variable=self.channel, value=0)
 302         g1.grid(row=0)
 303         if int(params['vchan']) == 0:
 304             g1.select()
 305         g2 = Radiobutton(channelframe, text='2', variable=self.channel, value=1)
 306         g2.grid(row=1)
 307         if int(params['vchan']) == 1:
 308             g2.select()
 309         g3 = Radiobutton(channelframe, text='3', variable=self.channel, value=2)
 310         g3.grid(row=2)
 311         if int(params['vchan']) == 2:
 312             g3.select()
 313         g4 = Radiobutton(channelframe, text='4', variable=self.channel, value=3)
 314         g4.grid(row=3)
 315         if int(params['vchan']) == 3:
 316             g4.select()
 317         channelframe.grid(row=1, column=6)
 318 
 319         # choose input gain - values changed from 3.75 SPS 18 bit to 60 SPS 14 bit, one shot mode
 320         gainframe = LabelFrame(frame, text='Gain', labelanchor='n')
 321         self.gainval = IntVar()
 322         g1 = Radiobutton(gainframe, text='1', variable=self.gainval, value=132, command = self.dispScales)
 323         g1.grid(row=0)
 324         if int(params['vgain']) == 132:
 325             g1.select()
 326         g2 = Radiobutton(gainframe, text='2', variable=self.gainval, value=133, command = self.dispScales)
 327         g2.grid(row=1)
 328         if int(params['vgain']) == 133:
 329             g2.select()
 330         g3 = Radiobutton(gainframe, text='4', variable=self.gainval, value=134, command = self.dispScales)
 331         g3.grid(row=2)
 332         if int(params['vgain']) == 134:
 333             g3.select()
 334         g4 = Radiobutton(gainframe, text='8', variable=self.gainval, value=135, command = self.dispScales)
 335         g4.grid(row=3)
 336         if int(params['vgain']) == 135:
 337             g4.select()
 338         gainframe.grid(row=2, column=6)
 339 
 340         # choose a colour
 341         colourframe = LabelFrame(frame, text='Colour', labelanchor='n')
 342         self.colour = StringVar()
 343         c1 = Radiobutton(colourframe, fg='blue', text='[B]', variable=self.colour, value='blue')
 344         c1.grid(row=0)
 345         if params['colour'] == 'blue':
 346             c1.select()
 347         c2 = Radiobutton(colourframe, fg='red', text='[R]', variable=self.colour, value='red')
 348         c2.grid(row=1)
 349         if params['colour'] == 'red':
 350             c2.select()
 351         c3 = Radiobutton(colourframe, fg='green', text='[G]', variable=self.colour, value='green')
 352         c3.grid(row=2)
 353         if params['colour'] == 'green':
 354             c3.select()
 355         c4 = Radiobutton(colourframe, fg='magenta', text='[M]', variable=self.colour, value='magenta')
 356         c4.grid(row=3)
 357         if params['colour'] == 'magenta':
 358             c4.select()
 359         c5 = Radiobutton(colourframe, fg='yellow', text='[Y]', variable=self.colour, value='yellow')
 360         c5.grid(row=4)
 361         if params['colour'] == 'yellow':
 362             c5.select()
 363         colourframe.grid(row=3, column=6)
 364 
 365         # remove bias
 366         self.bias = IntVar()
 367         biascheck = Checkbutton(frame, text="Bias", variable=self.bias, onvalue=1, offvalue=0)
 368         biascheck.grid(row=5, column=6)
 369         if int(params['bias']) == 1:
 370             biascheck.select()
 371 
 372         # fast flag
 373         self.fast = IntVar()
 374         fastcheck = Checkbutton(frame, text="Fast", variable=self.fast, onvalue=1, offvalue=0)
 375         fastcheck.grid(row=6, column=6)
 376         if int(params['fast']) == 1: #<< changed FL
 377             fastcheck.select()
 378 
 379         # CLS check button to clear the screen every sweep
 380         self.cls = IntVar()
 381         clearbutton = Checkbutton(frame, text='CLS', variable=self.cls, onvalue=1, offvalue=0)
 382         clearbutton.grid(row=7, column=6)
 383         if int(params['cls']) == 1: #<< changed FL
 384             clearbutton.select()
 385             
 386         # dBm check button to change Y scale to dB #<< New button afa
 387         self.dB = IntVar()
 388         dBbutton = Checkbutton(frame, text='dBm', variable=self.dB, onvalue=1, offvalue=0, command = self.dispScales)
 389         dBbutton.grid(row=8, column=6)
 390         if int(params['dB']) == 1: 
 391             dBbutton.select()
 392         #if self.dB == 1:
 393         #   biascheck.select()
 394 
 395         # Button to start a single sweep        #<< New button db
 396         self.sweepbutton = Button(frame, text='Sweep', height = 1, width = 3, relief=RAISED, command=self.onesweep)
 397         self.sweepbutton.grid(row=9, column=6)
 398 
 399         # RUN button to start the sweep
 400         self.runbutton = Button(frame, text='RUN', height = 1, width = 3, relief=RAISED, command=self.loopsweep)
 401         self.runbutton.grid(row=10, column=6)
 402 
 403         # STOP button to stop continuous sweep
 404         self.stopbutton = Button(frame, text='STOP', height = 1, width = 3, relief=SUNKEN, command=self.stop)
 405         self.stopbutton.grid(row=11, column=6)
 406 
 407         # start frequency for sweep
 408         fstartlabel = Label(frame, text='Start Freq (Hz)')
 409         fstartlabel.grid(row=10, column=0)
 410         self.fstart = StringVar()
 411         fstartentry = Entry(frame, textvariable=self.fstart, width=10)
 412         fstartentry.grid(row=10, column=1)
 413         fstartentry.insert(0,self.fBegin)
 414 
 415         # stop frequency for sweep
 416         fstoplabel = Label(frame, text='Stop Freq (Hz)')
 417         fstoplabel.grid(row=10, column=2)
 418         self.fstop = StringVar()
 419         fstopentry = Entry(frame, textvariable=self.fstop, width=10)
 420         fstopentry.grid(row=10, column=3)
 421         fstopentry.insert(0,self.fEnd)
 422 
 423         # increment for sweep
 424         fsteplabel = Label(frame, text='Step (Hz)')
 425         fsteplabel.grid(row=10, column=4)
 426         self.fstep = StringVar()
 427         fstepentry = Entry(frame, textvariable=self.fstep, width=8)
 428         fstepentry.grid(row=10, column=5)
 429         fstepentry.insert(0,self.fIntvl)
 430 
 431         # user description space #<< new addition FL
 432         descLabel = Label(frame, text='Description')
 433         descLabel.grid(row=11, column=0)
 434         descEntry = Entry(frame, width=57)  #<< changed db
 435         descEntry.grid(row=11, column=1, columnspan=5)
 436         
 437         # display a grid
 438         self.grid = IntVar()
 439         gridcheck = Checkbutton(frame, text="Grid", variable=self.grid, onvalue=1, offvalue=0, command=self.checkgrid)
 440         gridcheck.grid(row=4, column=6)
 441         if int(params['grid']) == 1:
 442             gridcheck.select()
 443         self.checkgrid()
 444         self.dispScales()
 445 
 446 
 447     # clear the screen
 448     def clearscreen(self):
 449         chart = canvas.create_rectangle(self.mrgnLeft, self.mrgnTop,
 450                                         self.mrgnLeft+self.chrtWid, self.mrgnTop+self.chrtHt,
 451                                         fill=self.canvBg, outline=self.canvFg)
 452         self.checkgrid()
 453 
 454     # display grid
 455     def checkgrid(self):
 456         checked = self.grid.get()
 457         if checked == 1:
 458                 colour=self.canvFg
 459         else:
 460                 colour=self.canvBg
 461         for x in range(self.mrgnLeft, self.mrgnLeft+self.chrtWid+1, int(self.chrtWid/self.xDivs)):
 462                 canvas.create_line(x, self.mrgnTop, x, self.mrgnTop+self.chrtHt, fill=colour)
 463         for y in range(self.mrgnTop, self.chrtHt+self.mrgnBotm, int(self.chrtHt/self.yDivs)):
 464                 canvas.create_line(self.mrgnLeft, y, self.chrtWid+self.mrgnLeft, y, fill=colour)
 465 
 466     # display horizontal axis labels
 467     def dispScales(self):
 468         startF = float(fconv(self.fstart.get()))	
 469         stopF = float(fconv(self.fstop.get()))	
 470         if stopF > 1000000:
 471             f0 = round((startF/1000000.0),1)
 472             fN = round(stopF/1000000.0,1)
 473             fDesc = 'MHz'
 474         elif stopF > 1000:
 475             f0 = round(startF/1000.0,1)
 476             fN = round(stopF/1000.0,1)
 477             fDesc = 'kHz'
 478         else:
 479             f0 = round(startF/1.0,1)
 480             fN = round(stopF/1.0,1)
 481             fDesc = 'Hz'
 482 
 483         canvas.create_rectangle(0, self.mrgnTop+self.chrtHt+1,
 484                                 self.canvWid+self.mrgnLeft, self.canvHt,
 485                                 fill=self.canvBg, outline=self.canvBg) #remove old X scale
 486 
 487         fStep = (fN-f0)/self.xDivs
 488         fLbls = ''
 489         f = f0
 490         hWhere = (self.mrgnLeft/2)+18 #<- changed ta
 491         while f < fN:
 492             #hLbl = canvas.create_text(hWhere,self.canvHt-20, text='{0:10s}'.format(' ')) #<- commmented out not needed? - ta
 493             hLbl = canvas.create_text(hWhere,self.canvHt-20, text="{0:10.2f}".format(f))
 494             f = f + fStep
 495             hWhere = hWhere+self.chrtWid/self.xDivs
 496         #hLbl = canvas.create_text(hWhere,self.canvHt-20, text='{0:10s}'.format(' ')) #<- commmented out not needed? - ta
 497         hLbl = canvas.create_text(hWhere,self.canvHt-20, text='{0:10.2f}'.format(fN))
 498         hWhere = ((self.mrgnLeft+self.chrtWid+self.mrgnRight) - len(fDesc)) / 2
 499         hLbl = canvas.create_text(hWhere, self.canvHt-5, text=fDesc)
 500 
 501     # display vertical axis labels << new function
 502     
 503         canvas.create_rectangle(0, 0, self.mrgnLeft-1, self.canvHt-self.mrgnBotm,
 504                                 fill=self.canvBg, outline=self.canvBg) #remove old Y scale <<moved and changed by ta 
 505    
 506         gain = pow(2,(self.gainval.get()-132))
 507         
 508         if self.dB.get() == 1:
 509             #self.yDivs = 25 # << with this commented out you should set the menu Ydivs  to something which suits the dB scale 
 510     # cant make the next line work - get AttributeError: type object 'WobbyPi' has no attribute 'biascheck'
 511             # self.biascheck.select()      # remove bias if in dB mode else display is incorrect       
 512             startV = float(-80)
 513             stopV = float(20)
 514             v0 = startV
 515             vN = startV + 100/gain
 516             vDesc = 'dBm'
 517             vStep = (vN-v0)/self.yDivs
 518             vLbls = ''
 519             v = vN
 520             vWhere = (self.mrgnBotm)/2 - 5
 521             while v > v0:
 522               vLbl = canvas.create_text(self.mrgnLeft-30, vWhere, text='{0:10.1f}'.format(v))
 523               v = v - vStep
 524               vWhere = vWhere+self.chrtHt/self.yDivs
 525             vLbl = canvas.create_text(self.mrgnLeft-30, vWhere, text='{0:10.1f}'.format(v0))
 526 
 527             
 528         else:
 529             startV = float(0)
 530             stopV = float(2.5)
 531             v0 = startV
 532             vN = stopV/gain
 533             vDesc = 'Volts'
 534             vStep = (vN-v0)/self.yDivs
 535             vLbls = ''
 536             v = vN
 537             vWhere = (self.mrgnBotm)/2 - 5
 538             while v > v0:
 539               vLbl = canvas.create_text(self.mrgnLeft-30, vWhere, text='{0:10.3f}'.format(v))
 540               v = v - vStep
 541               vWhere = vWhere+self.chrtHt/self.yDivs
 542             vLbl = canvas.create_text(self.mrgnLeft-30, vWhere, text='{0:10.3f}'.format(v0))
 543             
 544         vWhere = (self.chrtHt) / 2 - 6	#<< changed ta
 545         vLbl = canvas.create_text(8, vWhere, text="\n".join(vDesc))#<- changed to give vertical text - ta
 546 
 547     # start frequency sweep
 548     def sweep(self):
 549         pulseHigh(RESET)
 550         root.fast = int(self.fast.get())
 551         address = int(self.gainval.get())-4*root.fast # change to fast value if fast flag
 552         channel = int(self.channel.get())
 553         chip = adc_address
 554         address = (address + (32 * channel))
 555 #        changechannel(chip, address) #trigger adc <<removed afa
 556         startfreq = fconv(self.fstart.get())	 
 557         stopfreq = fconv(self.fstop.get())	
 558         span = (stopfreq-startfreq)
 559         step = fconv(self.fstep.get())
 560         #  If a value has changed, only then refresh scales. This to avoid slowdown between sweeps    #<< added db
 561         if self.oldstartfreq != startfreq or self.oldstopfreq != stopfreq or self.oldspan != span or self.oldstep != step:
 562             self.dispScales()
 563             self.oldstartfreq = startfreq 
 564             self.oldstopfreq = stopfreq
 565             self.oldspan = span
 566             self.oldstep = step	
 567         colour = str(self.colour.get())
 568         removebias = self.bias.get()
 569         bias = (getadcreading(chip) + getadcreading(chip))/2 #<< changed afa
 570         if int(self.cls.get()):
 571            self.clearscreen()
 572         root.fast = int(self.fast.get())
 573         print('bias [V] ', bias)
 574         tstart = time.time()
 575         for frequency in range((startfreq - step), (stopfreq + step), step):
 576             pulseHigh(RESET)
 577             pulseHigh(W_CLK)
 578             pulseHigh(FQ_UD)
 579             sendFrequency(frequency)
 580             # changechannel(chip, address)  #trigger adc << removed afa
 581             reading = getadcreading(chip) #includes triggering adc << added afa
 582             #x = int(self.chrtWid * ((frequency - startfreq) / span)) + self.mrgnLeft
 583             #y = int(self.chrtHt + self.mrgnTop - ((reading - (bias * removebias)) * self.chrtHt/2.5))
 584             x = int(500 * ((frequency - startfreq) / span)) + self.mrgnLeft
 585             # AD8307 span 0.3 - 2.1 V, *185 = 10 dB/div, +15 = offset
 586             y = int(500 + 25 - (reading * 185))
 587             if frequency > startfreq:
 588                 canvas.create_line(oldx, oldy, x, y, fill=colour)
 589                 canvas.update_idletasks() # new code to look like oscilloscope
 590             oldx = x
 591             oldy = y
 592             #if frequency == stopfreq:      #<< changed db
 593             #    pulseHigh(RESET)
 594             #    root.after(100, self.runsweep)
 595         tend = time.time()
 596         print('Dauer (s) ', tend-tstart)
 597 
 598     # continuous sweep
 599     def runsweep(self):
 600         if not root.stopflag:
 601             if root.oneflag:
 602                 root.stopflag = True
 603             self.sweep()
 604         else:
 605             # change relief of button to show selected button
 606             self.runbutton.config(relief=RAISED)
 607             self.sweepbutton.config(relief=RAISED)
 608             self.stopbutton.config(relief=SUNKEN)
 609 
 610     # initialize parameters for first sweep
 611     def startsweep(self):                                          #<< new function db
 612         self.stopbutton.config(relief=RAISED)
 613         #   Initial data to check when Scales need refresh
 614         self.oldstartfreq = 0 
 615         self.oldstopfreq = 0
 616         self.oldspan = 0
 617         self.oldstep = 0
 618         #	---------------------------------------------
 619         root.stopflag = False
 620         self.runsweep()
 621 
 622     # start single sweep
 623     def onesweep(self):                                       #<< new function db
 624         self.sweepbutton.config(relief=SUNKEN)
 625         root.oneflag = True
 626         self.startsweep()
 627         
 628     # start sweep after clearing stop flag to prevent need for dubble click run button
 629     def loopsweep(self):                                         #<< changed db
 630         self.runbutton.config(relief=SUNKEN)
 631         root.oneflag = False
 632         self.startsweep()
 633 
 634     # set stop flag
 635     def stop(self):
 636         # change relief of button to show selected button     #<< added db
 637         self.stopbutton.config(relief=SUNKEN)
 638         self.dispScales()	
 639         root.stopflag = True
 640 
 641 # Assign TK to root
 642 root = Tk()
 643 
 644 # Set main window title and menubar
 645 root.wm_title('RPi Wobbulator v2.6.3RR, use "scrot -s -d 4" for window shot')
 646 makemenu(root)
 647 
 648 # Create instance of class WobbyPi
 649 app = WobbyPi(root, params)
 650 
 651 # initialise start and stopflags
 652 root.startflag = 0
 653 root.stopflag = 0
 654 root.oneflag = 0
 655 root.fast = 0
 656 
 657 # Start main loop and wait for input from GUI
 658 root.mainloop()
 659 
 660 # When program stops, save user parameters
 661 paramFile = open(paramFN, "wb")
 662 params['chrtHt'] = app.chrtHt
 663 params['chrtWid'] = app.chrtWid
 664 params['canvFg'] = app.canvFg
 665 params['canvBg'] = app.canvBg
 666 params['fBegin'] = str(app.fstart.get())
 667 params['fEnd'] = str(app.fstop.get())
 668 params['fIntvl'] = str(app.fstep.get())
 669 params['vgain'] = str(app.gainval.get())
 670 params['vchan'] = str(app.channel.get())
 671 params['colour'] = app.colour.get()
 672 params['bias'] = str(app.bias.get())
 673 params['fast'] = str(app.fast.get())
 674 params['cls'] = str(app.cls.get())
 675 params['grid'] = str(app.grid.get())
 676 params['dB'] = str(app.dB.get())
 677 #print (params)
 678 params = pickle.dump(params, paramFile)
 679 paramFile.close()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2013-12-15 10:07:00, 3.0 KB) [[attachment:ADCNano3.ino]]
  • [get | view] (2013-12-15 09:17:00, 3.5 KB) [[attachment:ADCtiny85r.ino]]
  • [get | view] (2013-12-15 23:44:00, 89.1 KB) [[attachment:ATmega_I2C_0A03_IMAG0189.jpg]]
  • [get | view] (2013-12-15 10:41:00, 129.5 KB) [[attachment:ATtiny_I2C_0A03_IMAG0188.jpg]]
  • [get | view] (2014-01-21 16:36:00, 122.5 KB) [[attachment:PHSNA_PLX_DAQ_10_7_5V.PNG]]
  • [get | view] (2014-08-08 17:25:00, 38.7 KB) [[attachment:Wobbulator_Front_DSC05423.jpg]]
  • [get | view] (2014-03-18 08:46:00, 99.6 KB) [[attachment:Wobbulator_Prototyp2_DSC05176.jpg]]
  • [get | view] (2013-12-19 15:02:00, 65.1 KB) [[attachment:Wobbulator_Prototyp_DSC05047.jpg]]
  • [get | view] (2014-08-08 17:07:00, 83.8 KB) [[attachment:Wobbulator_oben_DSC05421.jpg]]
  • [get | view] (2013-12-15 10:18:00, 0.8 KB) [[attachment:test_adc.py]]
  • [get | view] (2013-12-15 09:32:00, 0.8 KB) [[attachment:test_adcr.py]]
  • [get | view] (2014-08-09 08:23:00, 55.6 KB) [[attachment:wob_logamp.brd]]
  • [get | view] (2014-08-09 08:23:00, 58.8 KB) [[attachment:wob_logamp.eps]]
  • [get | view] (2014-08-09 08:23:00, 322.8 KB) [[attachment:wob_logamp.sch]]
  • [get | view] (2014-08-09 08:22:00, 33.0 KB) [[attachment:wob_logamp_sch.pdf]]
  • [get | view] (2014-08-09 08:25:00, 119.2 KB) [[attachment:wob_logamp_sch.png]]
  • [get | view] (2014-08-08 17:54:00, 25.2 KB) [[attachment:wobbulator2.6.3.py]]
  • [get | view] (2014-04-05 19:10:00, 271.0 KB) [[attachment:wobbulatorM.sch]]
  • [get | view] (2014-04-05 19:09:00, 28.9 KB) [[attachment:wobbulatorM_sch.pdf]]
  • [get | view] (2014-04-05 19:09:00, 74.7 KB) [[attachment:wobbulatorM_sch.png]]
  • [get | view] (2014-08-08 14:27:00, 31.8 KB) [[attachment:wobbulator_10.7MA_limits.png]]
  • [get | view] (2014-08-08 17:06:00, 83.8 KB) [[attachment:wobbulator_DSC05418.jpg]]
  • [get | view] (2014-04-05 18:28:00, 29.5 KB) [[attachment:wobbulator_limits_0-60dB_5V.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.