Driving an IV-18 VFD using an Arduino

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Driving an IV-18 VFD using an Arduino

Postby joe426 » Tue Apr 12, 2011 2:53 pm

Regarding LadyAda's Ice Tube clock - http://www.ladyada.net/make/icetube/design.html

I had a few assuptions regarding her design and driving the display using an Arduino:

1. I'm not actually building a "clock" and I just want to control the VFD. So just taking into consideration that I want to use an external oscillator to control a stand-alone arduino chip, I do not need to add anything to the code to to tell the chip to run at 32KHz. It will do so automatically.

2. Since I'm not actually building a clock, BUT I want to use ladyada's boost converter circuit (see link above), I can use a 16MHz external crystal for the Arduino since the Arduino PWM still oscillates at 31.25Khz regardless of the external crystal speed.

Are the above correct? Thanks!
joe426
 
Posts: 21
Joined: Thu Apr 07, 2011 6:43 am

Re: Driving an IV-18 VFD using an Arduino

Postby mtbf0 » Wed Apr 13, 2011 7:10 am

disclaimer: don't have an ice tube and haven't spent much time looking at the code.

joe426 wrote:1. I'm not actually building a "clock" and I just want to control the VFD. So just taking into consideration that I want to use an external oscillator to control a stand-alone arduino chip, I do not need to add anything to the code to to tell the chip to run at 32KHz. It will do so automatically.


the chip is running at 8MHz on its internal oscillator with the clock divider turned off.

joe426 wrote:2. Since I'm not actually building a clock, BUT I want to use ladyada's boost converter circuit (see link above), I can use a 16MHz external crystal for the Arduino since the Arduino PWM still oscillates at 31.25Khz regardless of the external crystal speed.


you're going to have a problem here. the arduino uses timer0 for its timing functions. the ice tube code uses timer0 for the pwm to generate ac for the vfd. at the very least you'll have to do without millis and delay functions. you'll probably want to stop the timer0 overflow interrupt and, since the chip will be running twice as fast, i believe that you will have to double the value of all assignments to OCR0A once you have it properly set up. you may want to move the voltage generation to timer1 or timer2. timer1 might be a good choice since it's being used for the time keeping functions in the ice tube.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Re: Driving an IV-18 VFD using an Arduino

Postby joe426 » Thu Apr 14, 2011 4:44 pm

the chip is running at 8MHz on its internal oscillator with the clock divider turned off.


Does that mean that when you attach an external crystal, it automatically runs at the crystal's speed?

you're going to have a problem here. the arduino uses timer0 for its timing functions. the ice tube code uses timer0 for the pwm to generate ac for the vfd. at the very least you'll have to do without millis and delay functions. you'll probably want to stop the timer0 overflow interrupt and, since the chip will be running twice as fast, i believe that you will have to double the value of all assignments to OCR0A once you have it properly set up. you may want to move the voltage generation to timer1 or timer2. timer1 might be a good choice since it's being used for the time keeping functions in the ice tube.


That sounds like more trouble than it's worth to use the 16Mhz crystal. I think I'll just use the 32kHz crystal Ladyada used. If I use the 32kHz crystal, what (if anything) would I need to change in the code?
joe426
 
Posts: 21
Joined: Thu Apr 07, 2011 6:43 am

Re: Driving an IV-18 VFD using an Arduino

Postby mtbf0 » Thu Apr 14, 2011 5:14 pm

joe426 wrote:Does that mean that when you attach an external crystal, it automatically runs at the crystal's speed?


nope. there are three bytes of special memory on the avr known as fuse bytes that must be programmed with a special bit of hardware such as the usbtinyisp. setting or clearing specific bits in one of these bytes tells the avr what to use for a clock source. on an arduino the fuses are set to specify a high speed external crystal. the avr contains an internal r/c clock source which can also be specified. if the internal clock source is specified, you can leave the external crystal where it is in case you ever want to turn your arduino back into a regular arduino by returning the fuse bytes to their riginal state.

however, changing the clock source will break the bootloader since the timing on the chip's uart is dependent on the clock source. the manly thing to do to resolve this problem is to get your usbtinyisp back out and program a new bootloader compiled for an 8MHz clock. this works fine on older aduinos but i don't know if you would have to reprogram the mega8u2 on an uno or not.

joe426 wrote:That sounds like more trouble than it's worth to use the 16Mhz crystal. I think I'll just use the 32kHz crystal Ladyada used. If I use the 32kHz crystal, what (if anything) would I need to change in the code?


you don't need the 32k crystal. it's only there to provide a time base for the clock. the avr's clock is based on the internal rc oscillator. two different clocks here, you see? the ice tube is a clock. the avr has an instruction clock that determines it's operating speed. you could run the avr at 32KHz, but it would not be able to generate the pwm frequency to generate the power for the vfd.

and if you're using an arduino you've still got a conflict on timer0. the arduino firmware uses it and the code you want to adapt uses it and they use it in incompatible ways. you can sacrifice the arduino timing functions and use the ice cube power code as is or you can adapt the code to use one of the other two timers on the avr.

if you choose to pursue this project, the avr datasheet will turn out to be your best friend.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Re: Driving an IV-18 VFD using an Arduino

Postby joe426 » Sat Apr 16, 2011 3:32 am

Okay. On Ladyada's Ice Tube design page, she lists:

The PWM output speed of the microcontroller is F_CPU / 256 = 8 MHz / 256 = 31.25KHz (period of 32 useconds)


According to this page, the default PWM frequency on the Arduino is 31.25KHz. This means I don't have to change anything in the code since the output PWMs already have the desired frequency?

Alternatively, this page says:

The default PWM frequency for PWM 3, 9, 10, & 11, at least for the Diecimila running at 16 MHz, is 488 Hz.


Now I don't know what to believe...
joe426
 
Posts: 21
Joined: Thu Apr 07, 2011 6:43 am

Re: Driving an IV-18 VFD using an Arduino

Postby mtbf0 » Sat Apr 16, 2011 7:24 am

believe it all. comparing the ice tube to an arduino is like comparing a granny smith to a jonathan. they're both apples, but different, you know?

pwm frequency is dependent on how the avr timer registers are set up. along with the clock speed of the microcontroller there are a couple of other relevant parameters. each timer has a prescaler by which the mcu clock is divided and a top value which determines how many prescaled clock cycles occur in each pwm cycle. timers can also be configured for single or dual slope mode. a dual slope pwm wave form will have a frequency a little higher than half that of a single slope wave form.

for a single slope pwm mode the pwm frwquency is f_cpu / prescaler / top. where f_cpu is the clock frequency at which the mcu is running, (16MHz for most arduini and 8MHz for the ice tube and some arduini).

on the ice tube the prescaler is set to 1, (this is what is meant by clock divider turned off), the top value is 256 and a single slope mode has been selected so,

joe426 wrote:The PWM output speed of the microcontroller is F_CPU / 256 = 8 MHz / 256 = 31.25KHz (period of 32 useconds)


as i said.

mtbf0 wrote:if you choose to pursue this project, the avr datasheet will turn out to be your best friend.


on the arduino a prescaler of 64 is selected for each of the timers. timer0 is configured for single slope operation and timer1 and timer2 are confirgured for dual slope operation. the top value for all timers is 256.

this gives a pwm frequency on timer0, (which controls the pwm on pins 5 and 6), of 16MHz / 64 / 256 = 976.5625Hz, which is what the arduino uses for its timing functions.

timer1 and timer2 use dual slope operation since it is preferred for motors. for dual slope operation the pwm frequency will be f_cpu / prescaler / ((top - 1) * 2), so for pwm on pins 3, 9, 10 and 11 will be 16000000 / 64 / 510 or 490.196078431Hz.

did i mention the data sheet?

amongst the stuff in your arduino installation is a file called wiring.cpp. if you can figure out where arduino is installed on your system, it'll be at arduino-0021/hardware/arduino/cores/arduino/wiring.cpp. that's where i started learning about pwm. then i read the data sheet. then i read it again and again and again, but i'm a little slow.

i suggest you also peruse the source code for the ice tube.

it's early. although i have reread this post there are likely typos in it. gotta go to work, now.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Re: Driving an IV-18 VFD using an Arduino

Postby joe426 » Sun Apr 17, 2011 7:08 am

Okay, thank you so much for your help. I think I understand the timing system now (I did look at the datasheet previously, btw - it's not the easiest document to comprehend though ;).

Would it be possible to just use the tone() function to make this easier? http://www.arduino.cc/en/Reference/Tone (I also found this page helpful)

Also, I've read that it's not a good idea to mess with Timer0 and that I should use timer1 or 2. Why then did Ladyada use timer0 for the tube clock?
joe426
 
Posts: 21
Joined: Thu Apr 07, 2011 6:43 am

Re: Driving an IV-18 VFD using an Arduino

Postby adafruit_support_bill » Sun Apr 17, 2011 7:37 am

Also, I've read that it's not a good idea to mess with Timer0 and that I should use timer1 or 2. Why then did Ladyada use timer0 for the tube clock?


The ice-tube is not a general-purpose device like the Arduino. It is a clock. The engineers that designed the Arduino system chose to use Timer 0 to support many time-related Arduino functions. LadyAda made the engineering decision to use it as a time base for her clock.
User avatar
adafruit_support_bill
 
Posts: 16642
Joined: Sat Feb 07, 2009 9:11 am

Re: Driving an IV-18 VFD using an Arduino

Postby mtbf0 » Sun Apr 17, 2011 3:05 pm

it wouldn't be too much of a stretch to get this working on an arduino. you will have to calculate a new inductor value, though, since the pwm frequency will be twice what it was on the ice tube.

...unless you use 9 bit pwm on timer1. that'll give you the same pwm frequency as the ice tube. that would be mode 6. the pwm output will be on pin 9.

Code: Select all
  TCCR1B = 0;             // stop timer1
  DDRB |= (1 << PB1);          // same as pinMode (9, OUTPUT)
  OCR1A = 60;                      //low brightness
  TCCR1A = (1 << COM1A1) | (1 << WGM11);  // 9 bit fast pwm
  TCCR1B = (1 << WGM12) | (1 << CS10); // restart timer1, prescaler = 1


once you're set up you can control the brightness by assigning values from 60 to 180 to OCR1A. you can monitor millis() to multiplex the display. every time it changes show the next digit. don't use delay(). don't use digitalWrite on pin 9 or 10.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Re: Driving an IV-18 VFD using an Arduino

Postby joe426 » Mon Apr 18, 2011 3:02 am

mtbf0 wrote:...unless you use 9 bit pwm on timer1. that'll give you the same pwm frequency as the ice tube. that would be mode 6. the pwm output will be on pin 9.


Sounds like a good plan to me. I'll use timer 1 and pwm pin 9

once you're set up you can control the brightness by assigning values from 60 to 180 to OCR1A


My understanding (gathered from the datasheet) is that changing OCR1A from 60 to 18 effectively adjusts the duty cycle of the pwm on pin 9 (hence adjusting the brightness where 60 is low brightness and 180 is full brightness)?
joe426
 
Posts: 21
Joined: Thu Apr 07, 2011 6:43 am

Re: Driving an IV-18 VFD using an Arduino

Postby mtbf0 » Mon Apr 18, 2011 4:15 am

joe426 wrote:My understanding (gathered from the datasheet) is that changing OCR1A from 60 to 18 effectively adjusts the duty cycle of the pwm on pin 9 (hence adjusting the brightness where 60 is low brightness and 180 is full brightness)?


that's what we'd like to think. but, yeah, adjusting OCR1A sets the duty cycle and the nine bit pwm ought to get you the same frequency at 16MHz as the ice tube gets at 8MHz. let us know if it actually works.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Re: Driving an IV-18 VFD using an Arduino

Postby joe426 » Mon Apr 18, 2011 5:46 am

Awesome, thank you so much for your help mtbf0 - You're one of the most helpful individuals I've ever come across on a forum.

I'll post a link to my final project here (will be done within one month).
joe426
 
Posts: 21
Joined: Thu Apr 07, 2011 6:43 am

Re: Driving an IV-18 VFD using an Arduino

Postby joe426 » Thu Apr 21, 2011 5:21 pm

mtbf0 wrote:
Code: Select all
  TCCR1B = 0;             // stop timer1
  DDRB |= (1 << PB1);          // same as pinMode (9, OUTPUT)
  OCR1A = 60;                      //low brightness
  TCCR1A = (1 << COM1A1) | (1 << WGM11);  // 9 bit fast pwm
  TCCR1B = (1 << WGM12) | (1 << CS10); // restart timer1, prescaler = 1




Confirmed the code above successful outputs a frequency of ~31.25kHz on pin 9.
joe426
 
Posts: 21
Joined: Thu Apr 07, 2011 6:43 am


Return to Microcontrollers

Who is online

Users browsing this forum: No registered users and 1 guest

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]