I’m struggling with the ATtiny85 datasheet and was able to get a waveform but I seem to be
setting it up as PWM and I actually just want a squarewave.
This is what I have so far and I’m sure it’s all wrong but it’s a start.
void setup()
{
DDRB |= (1<<PB0); //Set pin PB0 as output
TCCR0A |=(1<<CTC1); //Start timer 1 in CTC mode Table 12.3.1
TCCR0A|=(1<<COM1A0); //Timer1 in toggle mode Table 12.4
TCNT0 |= (1 << CS00) | (1 << CS02); // Prescaler @ 1024 Table 12.5
TCCR0A |= ((1 << CS13) | (1 << CS11)| (1 << CS10)); // Prescaler @ 1024 Table 12.5
OCR0A=5500; //CTC Compare value
}
void loop()
{
}
This gives me about 1560 Hz (using an old oscope).
I want to use two ATtiny85s, one generating 150khz and the other 150 hz to be used to generate the two
frequencies needed for the Electro-Luminescent Backlight Power Supply circuit in attached schematic.
I breadboarded it and had no trouble using a Pro Mini with the following code (ino file attached)
// backlight.c
// for NerdKits with ATmega168
// mrobbins@mit.edu
#define F_CPU 16000000
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>
const int PB1=9; //OC1A Pin-9
const int PB2=10; //OC1B Pin-10
const int PB3=11; //OC2A Pin-11
// PIN DEFINITIONS:
//
// D9 -- OC1A -- backlight high-speed switchy thing (nFET gate)
// used to generate the high voltage supply
// D11 -- OC2A -- backlight low-speed switchy thing (nFET gate)
// used to pulse the AC to the electroluminescent
void setup()
{
pinMode(PB1,OUTPUT);
pinMode(PB2,OUTPUT);
pinMode(PB3,OUTPUT);
}
void loop()
{
// D9,D10, D11 as output
DDRB |= (1<<PB1) | (1<<PB2) | (1<<PB3);
// Timer1: Toggle CTC, 10-bit, non-inverting, clocked from CLK/1
TCCR1A = (1<<COM1A0);
TCCR1B = (1<<WGM12) | (1<<CS10);
OCR1A = 164; // =>150 kHz
// Timer2: Toggle CTC, clocked from CLK/1024
TCCR2A = (1<<COM2A0) | (1<<WGM21);
TCCR2B = (1<<CS22) | (1<<CS21) | (1<<CS20);
OCR2A = 12; // 175 Hz
}
I got the code from Nerdkits.com page here:
NerdKits - LCD Backlight - Electroluminescent Inverter
I breadboarded it and got 212Vac , about 100V short of the claimed 300V. I think I can increase the voltage
by changing the inductor value but I am not sure what value to use.
Since I read that the Timer 1 of the ATtiny85 is used for millis , micro etc. on this post:
http://forum.arduino.cc/index.php?topic=118586.0
I thought it better just to use two ics, both using Timer 0, which was recommend to avoid messing
with the one used for millis.
I have tried reading the datasheet but without much success. I was able to figure out the register names
but I don’t think I’m setting them correctly.
When tuning the Pro-Mini program I used a potentiometer to set the frequency using an analog input:
Declarations:
int analogPin = A3; // potentiometer connected to analog pin 3
int freq=0;
mapped to the desired OCR1A value range and then using the scope I obtained the corresponding
frequency range generated by that range of OCRIA values and remapped those values to that frequency
range and then used serial.print commands to print the frequency like this:
int freqAdj = analogRead(analogPin); // read the input pin
freqAdj = map(freqAdj, 0, 1023, 144, 184);
int freq = map(freqAdj, 144, 186, 142 ,166);
OCR1A=freqAdj;
Serial.print("freq= ");
Serial.println(freq);
which worked.
I was planning to use the same method to adjust the ATtiny85 frequency.
Can anyone help me ?
EL_Backlight_PS_H_150_kHz_L_175_Hz.ino (1.05 KB)