If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.
Special Thanks To:
Aaron Holmes
Aaron Wheeler
Adam Horden
Alan Scrimgeour
Andre
Andrew Haynes
Anonymous000
asabase
Austin Weil
barney
Barry
Bert Hickman
Bill Kukowski
Blitzorn
Brandon Paradelas
Bruce Bowling
BubeeMike
Byong Park
Cesiumsponge
Chris F.
Chris Hooper
Corey Worthington
Derek Woodroffe
Dalus
Dan Strother
Daniel Davis
Daniel Uhrenholt
datasheetarchive
Dave Billington
Dave Marshall
David F.
Dennis Rogers
drelectrix
Dr. John Gudenas
Dr. Spark
E.TexasTesla
eastvoltresearch
Eirik Taylor
Erik Dyakov
Erlend^SE
Finn Hammer
Firebug24k
GalliumMan
Gary Peterson
George Slade
GhostNull
Gordon Mcknight
Graham Armitage
Grant
GreySoul
Henry H
IamSmooth
In memory of Leo Powning
Jacob Cash
James Howells
James Pawson
Jeff Greenfield
Jeff Thomas
Jesse Frost
Jim Mitchell
jlr134
Joe Mastroianni
John Forcina
John Oberg
John Willcutt
Jon Newcomb
klugesmith
Leslie Wright
Lutz Hoffman
Mads Barnkob
Martin King
Mats Karlsson
Matt Gibson
Matthew Guidry
mbd
Michael D'Angelo
Mikkel
mileswaldron
mister_rf
Neil Foster
Nick de Smith
Nick Soroka
nicklenorp
Nik
Norman Stanley
Patrick Coleman
Paul Brodie
Paul Jordan
Paul Montgomery
Ped
Peter Krogen
Peter Terren
PhilGood
Richard Feldman
Robert Bush
Royce Bailey
Scott Fusare
Scott Newman
smiffy
Stella
Steven Busic
Steve Conner
Steve Jones
Steve Ward
Sulaiman
Thomas Coyle
Thomas A. Wallace
Thomas W
Timo
Torch
Ulf Jonsson
vasil
Vaxian
vladi mazzilli
wastehl
Weston
William Kim
William N.
William Stehl
Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
Hello everyone! I wasn't sure whether to put this in the comp sci area, the projects area, or here, but since it is for TC use I figure here is best as it is the most frequented/searched area of the three.
I recently built a programmable SSTC Interrupter using the Digispark () ATTiny85 platform. I heavily modified code by another 4HV member, Gao Guangyan (Loneoceans), with his permission. In keeping with his generosity and the OpenSource spirit, I wanted to release the code for others to use. The bulk of the work is Gao's, I simply ported it to the Digispark, adjusted frequency range to double, increased pulse width range by 500%, and added a CW Mode feature.
All you need is a Digispark (~$8), two 10k pots, and a SPDT On/On switch (you could use a SPST + a pull down resistor too), and a computer with a USB port to get it running. The circuit easily powers from a 9V battery and directly interfaces with a FB-129 fiber optic transmitter, if you so choose to. The nice thing about the Digispark is that no Arduino is needed to program the ATTiny85 MCU. For someone not looking to spend a lot to get a foot in the door of MCU programming who has simple needs, it is the way to go. The Digispark uses a free, modified version of the Arduino IDE, available on their site.
Results: 1.8-418Hz @ 0.05% - 48.8% duty cycle in interrupter mode. The code is for 2-512Hz but the ATTiny85 internal clock on my Digispark is about 20% slow. I read somewhere you can adjust the internal oscillator calibration with code but not wanting to break a working program trying to get it to work I figure better just leave it. The range is plenty for SSTC use.
Arduino IDE CODE:
/*
Sigurthr's Digispark SSTC Interrupter!
By Matt Giordano
Based heavily on ATTiny45/85 code for a simple Solid State Tesla Coil Interrupter
By Gao Guangyan, <www.loneoceans.com/labs/>
Thank you Gao!
offThresh allows the user to turn off the interrupter
by turning the potentiometer for BPS to below a certain threshold.
E.g. with Threshold set at 5/1023 --> 24mV, the signals will be off.
Set Threshold to 0 for always-on operation.
Digispark Physical Pinout:
Pin 5 as Digital Input: CW/Interrupted Mode switch.
Pin 4 as Analog Input: Frequency.
Pin 3 as Analog Input: Pulse-Width.
Pin 1 as Digital Output: LED.
Pin 0 as Digital Output: Fiber Optic Tx.
For the above analog inputs use a 10k Ohm pot with center wiper to associated
pin, one side to 5V and the other side to GND. For Pin 5 use a SPDT On/On
switch with center pin to Pin 5 and one side pin to ground, the other side pin to 5V.
*/
// User Modifiable Variables Here
float maxontime = 5000; // us - no greater than (32768/5) or 6553us!!
int offThresh = 0; // Define (offTresh/1023 * 5)Volts as off-threshold
float duty = 0.5; // Max Duty Cycle desired (here it's 10%)
// User Modifiable Variables End
int vpw;
int vbps;
int vcw;
int critfreq = (1000000*duty)/maxontime; // Hertz
float ontime = 0; // always us
float offtime = 0; // ms or us
float freq; // BPS Hertz
float period; // us
int outPin = 0;
int ledPin = 1;
int bpsPin = 2;
int pwPin = 3;
int cwPin = 5;
void setup() {
pinMode(outPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
vpw = analogRead(pwPin)-offThresh; // read pw voltage
vbps = analogRead(bpsPin); // read bps voltage
vcw = digitalRead(cwPin); // read cw switch state
if (vcw == HIGH) {
digitalWrite(outPin, HIGH);
digitalWrite(ledPin, HIGH);
}
else {
if (vpw < 0){
// Force logic low output when pw voltage is pulled low
digitalWrite(outPin, LOW); // Off
digitalWrite(ledPin, LOW); // Off
delayMicroseconds(100); // Short delay
}
else {
freq = 1 + ((vbps+2)/2);
// sets max BPS to 512.
// change to ((vbps+4)/4) for 254Hz max.
// change to ((vbps+1)/1) for 1024Hz max.
/*
If the period becomes > 2^15 us (T = 32.768ms or f less than 30.51Hz), then
the period variable runs over! Hence, we make sure this doesn't happen by
counting the numbers in milliseconds instead of microseconds.
Else, we can be free to count in microseconds
*/
if (freq < 31){
period = (1.0/freq)*1000; // ms
// Since 31 is a very low frequency, it will not exceed our
// pulse width at 10% duty cycle, so we just calc ontime in us.
ontime = 1 + (vpw/1023.0) * maxontime; // us
if (ontime > maxontime){ontime = maxontime;}
offtime = period - ontime/1000; // period in ms
// Now send the output signals
digitalWrite(outPin, HIGH); // On
digitalWrite(ledPin, HIGH); // On
delayMicroseconds(ontime); // delay in us
digitalWrite(outPin, LOW); // Off
digitalWrite(ledPin, LOW); // Off
delay(offtime); // delay in ms
}
else {
period = (1.0/freq)*1000000; // us
if (freq > critfreq){
ontime = 1 + (vpw/1023.0)*period*duty; // period in us
}
else{ontime = 1 + (vpw/1023.0)*maxontime;} // period in us
// Calculate off-times, capping the on-time to some max
if (ontime > maxontime){ontime = maxontime;}
offtime = period - ontime; // period in us
// Now send the output signals in microseconds
digitalWrite(outPin, HIGH); // On
digitalWrite(ledPin, HIGH); // On
delayMicroseconds(ontime); // delay in us
digitalWrite(outPin, LOW); // Off
digitalWrite(ledPin, LOW); // Off
delayMicroseconds(offtime); // delay in us
}
}
}
}
I use the ATTINY85 all the time too and the internal clock is supposed to be 8MHz +-10% (factory calibrated). However I think they very far more than that too. You can adjust it if you really want to but it is easier just to use a wider range of adjustment if you can in software. The frequency also varies a lot with temperature and voltage. I might be easier just to add a simple Cermaic oscillator to the circuit rather than trying to adjust it. But on the 85 that needs two pins you might not want to spare.
The data sheet has the details on how to adjust the clock. It is done with the OSCCAL register and all so it would require messing with the software and all the risks that has.
Absolutely right. That is part of the reason I decided to just double the frequency range in software and point out to others via notes where it can be increased again if needed. It doesn't seem worth it to risk breaking the program to get an extra 100Hz or so out on the top end.
I had thought about using a xtal to get a better clock speed but I'm already using 5 I/O pins, so no point. One is just for an indicator LED and could be done without but it isn't worth it really, as you pointed out.
Also, I read somewhere that the 85s are locked to 1MHz and require a special bit fusing to get them to 8MHz. I'm new to using uC's so I haven't looked into using OSCCAL and the like.
The uC's clock speed is actually 8MHz right now but there is a divide by 8 clock pre-scaler that reduces that to 1MHz. In Atmel's Studio programming software you can simply disable that fuse bit and then it runs just fine at 8MHz. The bit is called "CLK/8" and the default is enabled. Atmel's uC's seems super stable at higher clock speeds even in exteme environments.
Another easier way to calibrate the clock is just to know the thing is going to be all wrong and have a calibration variable to correct it. In a device I am working on you just calibrate the clock in software along with voltage and current sensors. But you would need a frequency counter or some other standard to calibrate it against in that case. Using the clock's cal register for calibration seems pretty messy from the little I have studied it. It seems easier to me just to fix the clock in software.
BTW - Some very cheap modern watches now have very very high accuracy. Instead of reying on the raw quartz crystal for accuracy, they are calibrated at the factory with software in it's uC brain. So if the 32,768 Hz crystal is really 32,779 Hz, a varible in the little software it has just modifies the counter to correct for any error. Some chips also have temperature calibration. Thus your really cheap watch has very high accuracy at a very tiny added cost.
BBTW - If you can, program the ATTINY85 in what's called the "high voltage" programming mode. Then you can recover the chip if you lock it all up and you can play with more bits. The standard ISP mode is sort of limited if you are experimenting. The only one to really watch is the "clock type". If you program it for a crystal and you have a ceramic ocillator instead, it will have zero clock and that is pretty hard to fix without an external clock source and other complex things. That is more of a concern on the more expensive or hard installed chips you just don't want to throw away.
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.