diff --git a/.gitignore b/.gitignore index b8e1744..02d44d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .vscode .micropico +.gitignore PiPicoPATLFGGGGG.code-workspace -main_dev.py -ComicCode-Regular.* \ No newline at end of file +dev +ComicCode-Regular.* +logs \ No newline at end of file diff --git a/main.py b/main.py index b577f27..4f57449 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,6 @@ import utime import _thread import math - # gpio pin to read power analysis off of (int) # reads 16bit (0-65535) between 0.0v and 3.3v # (16 bit is phony, real read is 12 bit) @@ -29,70 +28,77 @@ password = 'your-wifi-password-here' # == Clock Pulse Genertor == # # starts a pwm # usage do_pwm(int gpio_pin, float duty_cycle, int hertz frequency, int samples_per_clock_pulse) -def do_pwm(outpin = 20, duty_cycle = 0.5, frequency = 2000): - print('Starting Clock Pulse PWM') - output_pin = machine.Pin(outpin) - pwm_pin = machine.PWM(output_pin) - pwm_pin.freq(frequency) - - pwm_duty = math.floor(duty_cycle*65535) - percent_duty = duty_cycle*100 - pwm_pin.duty_u16(pwm_duty) - print(f"Clock Pulses Running\n\tGPIO Pin: {outpin}\n\tDuty Cycle: {percent_duty}%\n\tFrequency: {frequency}Hz") +def do_pwm(outpin, duty_cycle, frequency): + global pwm_pin + output_pin = machine.Pin(outpin) + + # configure pwm + pwm_pin = machine.PWM(output_pin) + pwm_pin.freq(frequency) # frequency in Hz + pwm_duty = math.floor(duty_cycle*65535) # duty cycle is a uint 16bit -# us of sleep calculate4d by floor(1000000 / (frequency_in_Hz * samples_per_pulse)) + # run da pwm + pwm_pin.duty_u16(pwm_duty) + +# us of sleep calculate4d by ceil(1000000 / (frequency_in_Hz * samples_per_pulse)) +# 1000000 is one million, 1,000,000 or 10^6 def us_samples(frequency, samples_per_pulse): - return math.floor(1000000/(frequency*samples_per_pulse)) + return math.ceil(1000000/(frequency*samples_per_pulse)) # == Read Value off of device == # # uses ADC, 16bit output is phony, is actualloy 12bit. -# us of sleep calculate4d by floor(1000000 / (frequency_in_Hz * samples_per_pulse)) -def do_adc(adcpin=28, duty_cycle = 0.5, frequency = 2000, samples_per_pulse = 100): - print('Starting voltage reading ADC') - semaphore_thread_adc = _thread.allocate_lock() +kill = False # for the thread killing hack +def do_adc(adcpin, frequency, samples_per_pulse): analog_value = machine.ADC(adcpin) us_sample = us_samples(frequency, samples_per_pulse) - while True: - semaphore_thread_adc.acquire() - reading = analog_value.read_u16() - print(reading) - utime.sleep_us(us_sample) - semaphore_thread_adc.release() -# == HTTP Stuff == # + global kill + while True: + reading = analog_value.read_u16() # do the actual reading, actual precision is 12bit + print(reading,',',sep='') + utime.sleep_us(us_sample) + + # just keep checking if kill is set to True by reset_init() + # if it is True, reset kill to False, kill the thread, and break for good measure + if kill is True: + kill = False + _thread.exit() + break + # HTML template for the webpage -header = f""" +header = """
Clock Pulse Pin: {outpin}
- Power Analysis Pin: {adcpin}
+ Power Analysis Pin: {adcpin}
+ Power On Pin:{power_on_pin}
- Frequency: {frequency}Hz (Duty Cycle: {dutyy}%)
+ Frequency: {frequency}Hz (Duty Cycle: {dutyy}%
Samples Per Pulse: {samples_per_pulse}
Delay Between Samples: {us_sample}us
+ Loop length: {loop_time}
LFGGGGGGGG FRONG