Author Topic: QCW ramp generator  (Read 348 times)

Offline hammertone

  • High Voltage Enthusiast
  • *
  • Posts: 6
  • Karma: +1/-0
    • View Profile
QCW ramp generator
« on: November 26, 2019, 12:32:27 PM »
All,

From time to time, I have been approached with a request to share my QCW ramp generator code.
Everybody should be enabled to build a QCW coil, even though they cannot write code, so here it is:  * QCW_ramp_generator.zip

I know that my shot at the code is probably clumsy at best (I imagine some math and code wizzard getting it done in just one line) , but it is functional, so who cares.

Included is a simple schematic, which I include, because I want to emphasize the need for, and beauty of, hardware debounching of the inputs.

So, please enjoy, and go build that QCW

Cheers, Finn Hammer

Offline shrad

  • High Voltage Enthusiast
  • *
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: QCW ramp generator
« Reply #1 on: November 27, 2019, 08:46:22 PM »
Hi there

I think you can use binary shift operators in a loop for this, which would be nice

basic use is that it will binary shift a value by a power of 2 : 8 >> 1 = 16, 32 << 2 = 8, etc... so if you do a loop until a treshold value is reached, this is very practical

Offline hammertone

  • High Voltage Enthusiast
  • *
  • Posts: 6
  • Karma: +1/-0
    • View Profile
Re: QCW ramp generator
« Reply #2 on: November 28, 2019, 10:44:29 AM »
Shrad,

Thanks for your suggestion.

As you can probably read in my code, I am at a very basic level. Only recently did I get comfortable with interrupts, direct port manipulation and messing with timer prescale.
The bitwise stuff is over my head, at the moment, unfortunately.

Cheers, Finn Hammer

Offline shrad

  • High Voltage Enthusiast
  • *
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: QCW ramp generator
« Reply #3 on: November 29, 2019, 12:07:18 PM »
Thats really simple

imagine an array of 8 bits with a min value of 00000001 and a max value of 10000000 and a logic level of 5V

00000001 is initial value       = V*(1/256) = 0.019V
00000001 >> 1 = 00000010 = V*(1/128) = 0.03V
00000010 >> 1 = 00000100 = V*(1/64) = 0.07V
00000100 >> 1 = 00001000 = V*(1/32) = 0.15V
00001000 >> 1 = 00010000 = V*(1/16) = 0.31V
00010000 >> 1 = 00100000 = V*(1/8) = 0.625V
00100000 >> 1 = 01000000 = V*(1/4) = 1.25V
01000000 >> 1 = 10000000 = V*(1/2) = 2.5V

the rest is thinking of an algorithm which will, in your loop, add shifts to get the steps you want... I'm pretty sure you could find a sketch somewhere that generates a ramp using this technique

you can also use the binary value from 2 to 256 to do some masks (with OR or XOR) on a value to generate another, etc...
from my days of learning microcontroller assembly we played with excel and did some graphs of the values to try different patterns of led flashing, like K2000 and others

Offline Netzpfuscher

  • High Voltage Experimenter
  • **
  • Posts: 89
  • Karma: +4/-0
    • View Profile
Re: QCW ramp generator
« Reply #4 on: November 29, 2019, 12:34:45 PM »
In a time where a micro controller is so powerful you don't need such "tricks". The ramp of your suggestion lacks a good resolution 8 steps ^^ With a calculation you can generate ramps with higher resolution. If a micro is to slow for a realtime generation of the ramp, I would calculate a lookup table in RAM and play it back in the loop. If the timebase is changed you simply read the LUT slower or faster. If you want, you can save arbitrary waveforms. If you need to save RAM I would make a smaller LUT and interpolate linearly between the points. 

In general, write good readable code and leave the optimization to the compiler. A actual compiler is very smart ^^. If you realy need processing power go to the next bigger micro.


In the UD3 the 64Mhz Cortex-M3 does everything, Ethernet, Synthesizer, Serial, Telemetry and has 80% of CPU unused  :o

Offline shrad

  • High Voltage Enthusiast
  • *
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: QCW ramp generator
« Reply #5 on: November 29, 2019, 12:57:16 PM »
you are absolutely right, but knowing this helps with some notions

however, I would reserve lookup tables to things that require floating point math or real arbitrary like you said

a ramp is even easier with a pwm module which will do everything for you without interfering with CPU after initial setup

nowadays programming is done without taking care of doing things properly just because there is plenty of power and resources are not a problem anymore, so modularity and maintainability are not always the best

the best thing to do is to make functions that are modular, that you can test separately, and define things with clarity in mind

and refactor your code whenever you have a doubt

Offline hammertone

  • High Voltage Enthusiast
  • *
  • Posts: 6
  • Karma: +1/-0
    • View Profile
Re: QCW ramp generator
« Reply #6 on: November 30, 2019, 12:45:22 PM »
Netzpfuscher,

Your viewpoint about compilers and the power of modern micro controllers align with mine, but perhaps It would be a good idea to measure what resolution my code gets me on a 16Mhz  ATMega 328P

AT first I set the ramp to 12.8mS:


After that, I zoom in on a single PWM cycle, which shows good correlation between what is expected and what is being done.
Pulse frequency is 31.25 kHz and pulsewidth is 32mS.
This also reveals that there will be 400 PWM cycles on that ramp : which is fine within the 8 bits expected.




First of course, I zoom into the positive pulseform and set the cursors at the flanks



Now comes the benefit of this fantastic digital scope. ( which was also increadible cheap,  at 400 € ! )

Conveniently, it captures the full waveform, even though I am zoomed in to 5µS/S so with the horizontal position knob, I can roll the signal, and count how many pulses in succession that shares the same pulsewidth:



The number is 5, so the resolution is a paltry 80 steps on this 12.8mS long ramp, resulting in a resolution of between 6 and 7 bits.

Looking at the ramp in well smoothed form:


You can actually count the steps, and considering that:

1) The signal has to be transmitted over inexpensive fiber optic
2) It forms the reference of a Hysteretic buck converter that switches around 10-15 kHz (at the best)

I would say that the code is sufficient.

(But I really would like to see each cycle increment, instead of only each 5th. so I will try to load the code into faster processors).

(( But the really smart thing to do would probably be to take a c++ programming course, and free myself from the constraints of the analogWrite macro ))

Cheers, Finn Hammer
« Last Edit: November 30, 2019, 01:09:04 PM by hammertone »

Offline shrad

  • High Voltage Enthusiast
  • *
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: QCW ramp generator
« Reply #7 on: November 30, 2019, 02:26:53 PM »
the read and write functions of arduino are well known to be unefficient, a lookup table with a direct binary copy with DMA would be far more efficient, if it is available on your configuration

Offline hammertone

  • High Voltage Enthusiast
  • *
  • Posts: 6
  • Karma: +1/-0
    • View Profile
Re: QCW ramp generator
« Reply #8 on: November 30, 2019, 04:28:34 PM »
Shrad,

The analogue functions , at least, are slow.
The digitalWriteFast and digitalReadFast macros are almost as fast as direct port manipulation, however:

I do not understand how a lookup table can help me to generate a linear ramp, where both length and amplitude are variables read from potentiometers, so I will try another approach, which I found just now:

I will try to calculate dutycycle in an ISP that gets called from an interrupt set by every cycle, perhaps that will give me maximum resolution, eg, every successive pwm pulse will increment, instead of every 5th as now.
There are 476 clock cycles between each pwm cycle, so there should be plenty of time to calculate the ratios.

Cheers, Finn Hammer

Offline shrad

  • High Voltage Enthusiast
  • *
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: QCW ramp generator
« Reply #9 on: November 30, 2019, 06:12:28 PM »
a technique I was using is the timer interrupt which ticks when a counter reaches zero (or something like that, I did this 10 years ago)... if you copy the pot value to the counter each time interrupt ticks, you will have an efficient variable delay

during the interrupt routine you also have the time to increment your lookup and configure your PWM value with it which will give you a step

the interrupt delay defines the slope of your ramp and can be any interrupt source you can configure, if the counter doesnt suit your needs

if you want the maximum resolution, it will depend on the PWM module and the interrupt time, but I guess you will be able to reach shorter times if you don't analog read a pot but rather increment or decrement a value by steps with a button push (which can also generate an interrupt to reset the ramp)

for amplitude, I would rather use an opamp at the output

High Voltage Forum

Re: QCW ramp generator
« Reply #9 on: November 30, 2019, 06:12:28 PM »

 


* Recent Topics and Posts

post Re: SGTC MK1 - An Accomplishment in Progress
[Spark gap Tesla coils]
davekni
Today at 12:53:57 AM
post Re: CW multiplier resistor string suggestions
[Voltage Multipliers]
davekni
December 08, 2019, 09:57:51 PM
post Re: CW multiplier resistor string suggestions
[Voltage Multipliers]
MRMILSTAR
December 08, 2019, 05:28:09 PM
post Aethra CCD Webcam Teardown - From Back When Streaming Was Expensive!
[Electronic circuits]
Mads Barnkob
December 08, 2019, 01:33:30 PM
post Platter resistance & inductance
[Induction launchers, coil guns and rails guns]
klugesmith
December 08, 2019, 11:41:00 AM
post Re: CW multiplier resistor string suggestions
[Voltage Multipliers]
davekni
December 08, 2019, 06:50:11 AM
post Re: CW multiplier resistor string suggestions
[Voltage Multipliers]
plasma
December 08, 2019, 12:00:00 AM
post CW multiplier resistor string suggestions
[Voltage Multipliers]
MRMILSTAR
December 07, 2019, 11:32:49 PM
post Re: Sense coil fabrication?
[Induction launchers, coil guns and rails guns]
klugesmith
December 07, 2019, 09:54:31 PM
post Re: SGTC MK1 - An Accomplishment in Progress
[Spark gap Tesla coils]
jturnerkc
December 07, 2019, 09:48:21 PM
post Re: Sense coil fabrication?
[Induction launchers, coil guns and rails guns]
klugesmith
December 07, 2019, 08:59:57 PM
post Re: Cost reduction in consumer electrics
[Electronic circuits]
MRMILSTAR
December 06, 2019, 08:35:29 PM
post Re: Full bridge showing half the voltage
[Beginners]
plasma
December 06, 2019, 05:19:26 AM
post Re: Cost reduction in consumer electrics
[Electronic circuits]
davekni
December 06, 2019, 03:48:34 AM
post Re: Cost reduction in consumer electrics
[Electronic circuits]
the_anomaly
December 06, 2019, 03:35:39 AM
post Re: Welcome new members, come say hello and tell a little about yourself :)
[General chatting]
AstRii
December 06, 2019, 01:27:03 AM
post Re: Full bridge showing half the voltage
[Beginners]
plasma
December 05, 2019, 11:38:59 PM
post Re: Cost reduction in consumer electrics
[Electronic circuits]
Mads Barnkob
December 05, 2019, 07:33:01 PM
post Re: Cost reduction in consumer electrics
[Electronic circuits]
sjsimmo
December 05, 2019, 11:09:20 AM
post Cost reduction in consumer electrics
[Electronic circuits]
klugesmith
December 05, 2019, 07:25:20 AM
post Re: HV resistor in oil
[Voltage Multipliers]
MRMILSTAR
December 05, 2019, 05:52:11 AM
post Re: HV resistor in oil
[Voltage Multipliers]
davekni
December 05, 2019, 05:21:07 AM
post Re: HV resistor in oil
[Voltage Multipliers]
MRMILSTAR
December 04, 2019, 06:05:11 PM
post Re: Full bridge showing half the voltage
[Beginners]
shrad
December 04, 2019, 02:57:02 PM
post Re: Sense coil fabrication?
[Induction launchers, coil guns and rails guns]
Uspring
December 04, 2019, 12:40:51 PM
post Re: Full bridge showing half the voltage
[Beginners]
plasma
December 04, 2019, 11:20:25 AM
post Re: Sense coil fabrication?
[Induction launchers, coil guns and rails guns]
klugesmith
December 04, 2019, 08:28:15 AM
post Re: Full bridge showing half the voltage
[Beginners]
klugesmith
December 04, 2019, 07:41:21 AM
post Re: Sense coil fabrication?
[Induction launchers, coil guns and rails guns]
MRMILSTAR
December 04, 2019, 05:15:49 AM
post Re: HV resistor in oil
[Voltage Multipliers]
MRMILSTAR
December 04, 2019, 05:06:39 AM
post Re: HV resistor in oil
[Voltage Multipliers]
davekni
December 04, 2019, 04:31:16 AM
post Re: Full bridge showing half the voltage
[Beginners]
davekni
December 04, 2019, 04:26:38 AM
post Re: Sense coil fabrication?
[Induction launchers, coil guns and rails guns]
klugesmith
December 04, 2019, 04:10:16 AM
post Re: Sense coil fabrication?
[Induction launchers, coil guns and rails guns]
klugesmith
December 04, 2019, 12:28:15 AM
post Re: Full bridge showing half the voltage
[Beginners]
plasma
December 04, 2019, 12:11:32 AM
post Re: HV resistor in oil
[Voltage Multipliers]
johnf
December 03, 2019, 07:58:41 PM
post Re: Driving Nixie-tubes with arduino
[Electronic circuits]
johnf
December 03, 2019, 07:54:08 PM
post Re: Full bridge showing half the voltage
[Beginners]
klugesmith
December 03, 2019, 07:41:00 PM
post Re: Driving Nixie-tubes with arduino
[Electronic circuits]
kamelryttarn
December 03, 2019, 02:14:00 PM
post Re: Driving Nixie-tubes with arduino
[Electronic circuits]
Mads Barnkob
December 03, 2019, 01:24:00 PM
post Re: Driving Nixie-tubes with arduino
[Electronic circuits]
klugesmith
December 03, 2019, 10:45:58 AM
post Driving Nixie-tubes with arduino
[Electronic circuits]
kamelryttarn
December 03, 2019, 09:04:42 AM
post Re: Full bridge showing half the voltage
[Beginners]
plasma
December 03, 2019, 07:29:48 AM
post Re: HV resistor in oil
[Voltage Multipliers]
MRMILSTAR
December 03, 2019, 05:07:28 AM
post Re: HV resistor in oil
[Voltage Multipliers]
davekni
December 03, 2019, 04:34:46 AM
post Re: HV resistor in oil
[Voltage Multipliers]
MRMILSTAR
December 02, 2019, 09:06:07 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic circuits]
T3sl4co1l
December 02, 2019, 10:51:33 AM
post Re: SGTC MK1 - An Accomplishment in Progress
[Spark gap Tesla coils]
jturnerkc
December 02, 2019, 05:49:05 AM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic circuits]
petespaco
December 02, 2019, 04:10:14 AM
post Re: SGTC MK1 - An Accomplishment in Progress
[Spark gap Tesla coils]
davekni
December 02, 2019, 04:09:37 AM

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30