New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added clocks and powersupply #4
Merged
Merged
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e088258
Test4 (#2)
JackOA 3fa2ea1
New Clocks added and powersupply
freddiscr 8aa490b
changed variables
JackOA 09bf10d
please review
JackOA 484d218
versions update
JackOA 0cc1ae4
Set sh clock and added Oscilloscope
freddiscr ed0a7d6
Updated sh-clock and oscilloscope with trigger
freddiscr 8448be3
Non-blocking oscilloscope and redefined clocks
freddiscr 91ef6cc
Updated icg_clock and fetch data
freddiscr e4f8b9d
Updated oscillocope
freddiscr d4345a2
Implemented the latest few changed
JackOA 9283bab
Merge branch 'OpnTec:master' into master
freddiscr 27c7e9f
Merge branch 'master' of https://github.com/freddiscr/open-spectromet…
JackOA 5b4e726
Updated variablenames and minor things
freddiscr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
''' | ||
Requests for the Code: | ||
the code should have an power Output on the Voltagesource VDD=5V /VAD=5V | ||
the code should build a Masterclock with a frequency inbetween 0.8 to 4 MHz, typical 2 MHz. The Voltagerange of the Clock | ||
shall be 0-4V | ||
The ICG is a squarewave with a high level of typical 4V over the time of 3694 Elements of the Clock. | ||
The SH is a squarewave with a high level of typical 4V and indicates the integrationtime. | ||
The integrationtime is started with the falling flank of the signal and and lasts till the next falling flank. | ||
The analog input of the sensor shall be read by the the osilloscope. | ||
the analog voltage signal shall be saved over the time and be integrated to get a digital signal. | ||
the algotithims still needs to be definded. | ||
|
||
import argparse | ||
import platform | ||
import os.path | ||
import shutil | ||
import sys | ||
import time | ||
from itertools import zip_longest | ||
from typing import List, Tuple | ||
|
||
|
||
|
||
''' | ||
|
||
import numpy as np | ||
import time | ||
import math | ||
from pslab.instrument.waveform_generator import PWMGenerator | ||
from pslab.instrument.oscilloscope import Oscilloscope | ||
from pslab.serial_handler import SerialHandler | ||
from pslab.instrument.logic_analyzer import LogicAnalyzer | ||
from pslab.instrument.power_supply import PowerSupply | ||
|
||
frequency_master_clock = 2e6 # no need to specify the variable type (float). frequency_master_clock = float(2e6) turns into frequency_master_clock = 2e6. Same for integration_time variable. Im Datentyp float werden reele Zahlen in Exponentialdarstellung geschrieben (also Gleitkommazahlen). float(2e6) turns 2e6 which is already a float into a float. In other words, it does nothing; However f.e. 280,7 would have also been linked to float instead of int | ||
integration_time = 1.85e-3 # time in seconds | ||
oscillator_frequency = 128e6 #frequency of the oscilliator in Mhz | ||
integration_elements = 3694 #according to timing requests | ||
microseconds_in_second = 1e6 | ||
prescaler = int(math.log(oscillator_frequency / frequency_master_clock) / math.log(2)) # When setting a frequency by mapping the reference clock directly to a PWM output, only frequencies which are even factors of 128 MHz (the frequency of the PSLab's main oscillator) are available. The frequency is therefore not set by specifying the frequency itself, but by setting a prescaler. | ||
|
||
|
||
class TCD1304(): | ||
def __init__( | ||
self, #Initializing; self is always first parameter of methods located inside a class and is not limited to the __init__ method but to most methods. A method is a function that belongs to a class | ||
min_masterclock_frequency = 0.8e6, # no need to specify the variable type (float). View comment in L37 | ||
max_masterclock_frequency = 4e6, # no need to specify the variable type (float). View comment in L37 | ||
frequency = frequency_master_clock, #default frequency of masterclock 2 MHz; # no need to specify the variable type (float). View comment in L37 | ||
min_voltagerange_clock: float = 0, #it says that min_voltagerange_clock should (!) be a float. Otherwise it would not turn into a float automatically. Output on float will be 0.0 V and on int 0 V. | ||
max_voltagerange_clock: float = 4, | ||
pwmgen = ... # not sure if pwmgen needs to be assigned to a value ?? | ||
): | ||
|
||
self.min_masterclock_frequency = min_masterclock_frequency #initializing starts from here (? Not sure though) | ||
self.max_masterclock_frequency = max_masterclock_frequency | ||
self.frequency = frequency | ||
self.min_voltagerange_clock = min_voltagerange_clock | ||
self.max_voltagerange_clock = max_voltagerange_clock | ||
self.pwmgen = PWMGenerator() #once assigned in __init__ self.pwmgen can be used in other methods | ||
self.scope = Oscilloscope () | ||
|
||
|
||
def power_source (): # puts a voltage of 4V on PV1 | ||
ps = PowerSupply() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use the |
||
ps.pv1 = 4 | ||
bessman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ps.pv1 | ||
freddiscr marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As pointed out before, this line is unnecessary. |
||
|
||
def master_clock (self): # puts PWM with frequency of 2MHz on SQ1; masterclock is the fastest clock | ||
self.pwmgen.map_reference_clock(["SQ1"], prescaler) | ||
|
||
def sh_clock (self): # on SQ2 sets pulse for the integrationtime. Running the Sensor in shutter mode try with a frequency of 1/4 of master_clock. tint (min) = 10µs | ||
self.pwmgen.generate(["SQ2"], prescaler/4 ) | ||
bessman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def icg_clock (self): # on SQ3 starts and stops the reading of the sensor; this third clock is the slowest clock | ||
bessman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.pwmgen.set_state() | ||
for pulse in range(integration_elements): | ||
self.pwmgen.set_state(sq3=True) | ||
time.sleep(integration_time / 2) | ||
self.pwmgen.set_state(sq3=False) | ||
time.sleep(integration_time / 2) | ||
|
||
''' | ||
normal state of icg is a high level. Start of the reading is on the rising | ||
flank of the voltage. To start the reading voltage shall drop to low and rise | ||
to high again. | ||
''' | ||
def analog_signal_read (self): | ||
self.scope = Oscilloscope() | ||
x, y = scope.capture (1, integration_elements, (integration_time / integration_elements)*microseconds_in_second) # Parameters set are (Ch1, amount of samples(3694), time between samples (~0,5µs)) | ||
bessman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
analog_measurement = np.ndarray () | ||
return analog_measurement # this should put the Measurements and timestamps in an array |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No parentheses needed.