..
Hello!
I use the Attiny 45 on a Diamex AVR Programmer (6Pin Output ISP).
Pin1 =reset
Pin2 = NC
Pin3 = NC
Pin4 = GND
Pin5 = MOSI
Pin6 = MISO
Pin7 = SCK
Pin8 = Vcc
I use a simplest sketch to control this Funktion.
IDE Version 1.6.3 with latest Core from Tiny-Master and try also Version 1.6zip from github.
Both with similar results. Some " Blink Sketch" runs, Tone() upload without an Error, but no Funktion (no Output on all Pins)
int ledPin = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
tone(ledPin,1000);
}
Thx for your efforts!!
...now i try the Attiny 84A-PU to use for Tone() Function......nothing!! no Output!!!
int ledPin = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
tone(ledPin,1000);
}
void loop()
{
}
..@coding badly..
thanks for help!
The tone () runs only on void setup!
..but not stable enough for my project. So i need to switch two frequencies with code. I think the ATtiny is to "tiny",. Is it Possible to switch two frequencies around 40/50 khz with the ATtiny with trigger? maybe the tone () function is not the right way!?
I have to use the external 16Mhz cristal to get 50khz with tone().
xxxlshark:
The tone () runs only on void setup!
Wrong.
By putting tone in an otherwise empty loop you have made it impossible for anything interesting to happen. The tone function is called, the hardware is reset to generate the requested frequency, then, before the first wave is created, tone is called again resetting the hardware.
That code running on an Uno will produce the same bad result.
Is it Possible to switch two frequencies around 40/50 khz with the ATtiny with trigger?
If you can do that with an Uno then you can do it with an ATtiny processor.
..thx for your efforts!!
i try the code on the attiny 45 in void(Setup) and he run also great!
..than i try to Switch the frequencies in the Loop by read a pin .
for example pin == high run (40000), pin==low, run 45000,(thats only example, no code...)))))
i get only 30hz?!
otherwise some melody sketch runs on Loop?! (on both 84 and 45)
xxxlshark:
no code...
...means no help from me.
int ledPin = 4;
int readPin = 3;
int pinState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(readPin, INPUT);
pinMode(readPin, HIGH);
}
void loop()
{
pinState = digitalRead(readPin);
if (pinState == LOW)
{
tone(ledPin,46000);
}
else
{
tone(ledPin,42000);
}
}
...............................
that runs only 30 hz?!
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
Your code is essentially identical to the code in the original post. tone is repeatably called so fast that nothing useful happens.
The first step is to write a simple sketch that toggles an LED each time you press the button. First click, the LED is turned on. Second click, the LED is turned off. Third click, the LED is turned on. Etcetera.
.Yes its a realy poor code, but..the trigger to switch the frequencies is quit fast around 1khz and between the two frequencies must have no delay.
I have no idea how can do this...or if the attiny can .
Before i had the idea to take two functions with toggle pins with microseconds delay, but the digitalWrite is not quick enough and the delayMicroseconds not accurate enough for the frequencie value.
The "trigger" in your code (Reply #7) is two to three orders of magnitude faster than 1kHz. Which is why it does not work.
I gave you a suggestion in Reply #8 that will set you on the correct path. Why did you ignore it?
....i realy dont ignor your posts!
the only thing is maybe the language barrier also.
than i'm a newbie in yC und try my best. I come from the hardware electronic und try to something in the yC.
I try to understand your suggestion, but i dont know how can i write code with the Requirements on the quick switching frequencies by trigger.
xxxlshark:
I try to understand your suggestion, but i dont know how can i write code with the Requirements on the quick switching frequencies by trigger.
Developing software is an incremental process. We are on Reply #12 and you are still trying to jump to the end. Try starting at the beginning. Write the sketch I described in Reply #8.
...yea! sorry! thats my nature! I´m impatient.(((
....i read your suggestion again and now i beleave to know the differents..
its not only the reading out level at pin x everytime with every event on tone...
it is the change itself of the level on the pin there triggers the switch of frequencies!!!
no change of level its time to play tone..
Something like this:
int ledPin = 4;
int readPin = 3;
int pinState =0;
int freqH = 4600;
int freqL = 4000;
int oldStatus=0;
int newStatus=0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(readPin, INPUT);
pinMode(readPin,INPUT_PULLUP);
}
void loop()
{
newStatus = digitalRead(readPin);
if ((newStatus != oldStatus)&&(newStatus==HIGH))
{
tone(ledPin,freqH);
}
if ((newStatus != oldStatus)&&(newStatus==LOW))
{
tone(ledPin,freqL);
}
oldStatus=newStatus;
}
it runs! .===))) THX for lesson!!!
It runs only with max around 36khz cause 8Mhz Clock Speed!
- Do you know a way to run faster with 8Mhz with more accurate/stable frequencies?
- If the tone() runs, have the µC Time for other work/process?
xxxlshark:
it runs! .===))) THX for lesson!!!
You are welcome.
- Do you know a way to run faster with 8Mhz with more accurate/stable frequencies?
The t45 processor can be run at 16MHz using the internal oscillator. You will have to create a boards.txt with the correct fuse settings.
The t45 internal oscillator can be tuned to about 1% accuracy using the OSCCAL register.
For more accuracy / stability than that you will have to use an external crystal.
- If the tone() runs, have the µC Time for other work/process?
Yes. The output is generated by an interrupt service routine that occupies several percent of the processor's time. The rest of the processor's time is free for you to use.
If you use this core... GitHub - Coding-Badly/TinyCore1: Tiny Core 1 for Arudino 1.6 ...and an output compare pin for the tone timer, the output is generated entirely by hardware (no processor time used; no jitter).
It runs only with max around 36khz cause 8Mhz Clock Speed!
Output is generated by dividing the processor's clock (8MHz) by an integer. Some frequencies are not going to be available.
For example, you are trying to generate a 42,000 Hz output. If we divide the processor speed by that...
8000000 / 42000 = 190.4761905
...we get 190 and some change. The actual output will be...
8000000 / 190 = 42105.26316 Hz
If you increase the processor speed to 16 MHz, the output is very close to the goal...
16000000 / 42000 = 380.952381
16000000 / 381 = 41994.75066
...Hello and thanks for answer!!
..the calculation about the frequencies is what have done, cause i thought that's only Division of whole numbers are possible so i can only use their solution for frequency value.
...the tiny core you wrote is exactly the core i use!!! Thank you for that!!
I use now the At84A for my projekt and use the pin 7 for Output. ist a OC1A ! I hope thats the right Pin!!
Also i hope thats the config is ok now.
i need a code like an monoflop there hold the value "x" 40µs longer than the "x" is starting by Trigger.
x = digitalRead(pinA);
if (x ==HIGH)
{
digitalWrite(pinB,HIGH);
delayMicroseconds(40);
}
else
{
digitarWrite(pinB,LOW);
{
.....will this work ? I`m sure you have a better idea!..))) cause the other program hold on cause delay !?
...is it also possible to use a code to blink a lamp (for example) and the other program runs without waiting!?