See he still not say why he want's to do it.
Not a way to win friends here.
See he still not say why he want's to do it.
Not a way to win friends here.
Grumpy_Mike:
See he still not say why he want's to do it.Not a way to win friends here.
i am into generating audio-visual stuff with an Arduino and a breadboard , i wanted to get the arduino to generate all types of signals in different conditions . using the PWM output you can have a decent amount of control over the signal with the preset clock speed , that's why i asked if the clock speed can be altered really fast in real time so i can have more freedom with wave output .
Thank you.
Now I can say that you are wasting your time with changing the processor speed, everything you want to do can be done with the correct programming and a lot more precisely.
What mike is saying is that by reducing the clock speed , you are not gaining another set of PWM signals. The resoslution remains 0 to 255 (256 different pwm count values , including 0). You gain nothing by changing the clock speed (unless what you are really doing is trying to make a voice disguiser)
If you want a LOT of PWM signals with a LOT of fine control, consider CPLDs or FPGAs. There are some very reasonably priced ones in QFP-144 packages where you get a large number of outputs and they are not all that hard to solder, or, IMHO, to program, though the programming is very different than microcontroller programming.
JoeN:
If you want a LOT of PWM signals with a LOT of fine control, consider CPLDs or FPGAs. There are some very reasonably priced ones in QFP-144 packages where you get a large number of outputs and they are not all that hard to solder, or, IMHO, to program, though the programming is very different than microcontroller programming.
actually it's very nice that you mentioned FPGAs since that's what i am looking after these days . though setting an FPGA seems to be a lot more complicated than setting a microcontroller , so setting one on my own PCB would be fairly not possible (the set up of a flash chip and the other components to get it to run) .
though using an already prepared environment with an FPGA like a cyclone or Xilinx board is possible even that's an overkill for this kind of job .
amine2:
Hey , i did search for this , but couldn't find anything on it (y) . and i do not post on the forum whenever i have a question about anything ...
Not only can you programmatically change the Arduino / AVR clock speed, the AVR-GCC toolchain provides a function to do it!
The function is:
void clock_prescale_set(clock_div_t);
...and it's defined in [b]<avr/power.h>[/b]. It handles all the low level manipulations, timing, etc for you.
The "clock_div_t" data type is also defined for you, and the following values are available:
These pre-defined defines resolve simply to powers of 2. For example, "clock_div_128" is "7" (i.e. 27 == 128), so you can also just use, for example: [b]clock_prescale_set((clock_div_t) 7);[/b] to set the clock to crystal/128.
If you try this function and you get an undefined error, you will need to include the header file that describes it:
[b]<avr/power.h>[/b].
By the way, when you burn the CLKDIV8 fuse, the AVR simply reads the bit at reset time and does a [b]clock_prescale_set(clk_div_8);[/b] internally.
Hope this helps....
[rant]
Why does everyone reply with links or snide comments instead of spending 5 minutes and providing the O.P. with some HELP and maybe a bit of code to help explain?
[/rant]
Krupski:
Not only can you programmatically change the Arduino / AVR clock speed, the AVR-GCC toolchain provides a function to do it!The function is:
void clock_prescale_set(clock_div_t);...and it's defined in
[b]<avr/power.h>[/b]. It handles all the low level manipulations, timing, etc for you.The "clock_div_t" data type is also defined for you, and the following values are available:
- clock_div_1 // clock == xtal
- clock_div_2, // clock == xtal/2
- clock_div_4 // clock == xtal/4
- clock_div_8 // etc...
- clock_div_16
- clock_div_32
- clock_div_64
- clock_div_128
These pre-defined defines resolve simply to powers of 2. For example, "clock_div_128" is "7" (i.e. 27 == 128), so you can also just use, for example:
[b]clock_prescale_set((clock_div_t) 7);[/b]to set the clock to crystal/128.If you try this function and you get an undefined error, you will need to include the header file that describes it:
[b]<avr/power.h>[/b].By the way, when you burn the CLKDIV8 fuse, the AVR simply reads the bit at reset time and does a
[b]clock_prescale_set(clk_div_8);[/b]internally.Hope this helps....
[rant]
Why does everyone reply with links or snide comments instead of spending 5 minutes and providing the O.P. with some HELP and maybe a bit of code to help explain?
[/rant]
thank you very much ![]()
Paul__B:
Product life?Do you imagine the microcontroller has a limited number of clock cycles in its lifetime, as some people conceptualise that a human has a certain allocated number of heartbeats?
If you lower the clock you can lower the operating voltage. Lower clock/voltage equals less heat generated and that is easier on the chip. So, if you don't need the faster speed why use it? As I said, sometimes HOBBY is about doing it just because you can.
̶
Speed Grade:
̶ 0 - 4MHz@1.8 - 5.5V, 0 - 10MHz@2.7 - 5.5.V, 0 - 20MHz @ 4.5 - 5.5V
Power Consumption at 1MHz, 1.8V, 25C
̶ Active Mode: 0.2mA
̶ Power-down Mode: 0.1μA
̶ Power-save Mode: 0.75μA (Including 32kHz RTC)
Why does everyone reply with links or snide comments instead of spending 5 minutes and providing the O.P. with some HELP and maybe a bit of code to help explain?
Probably because the OP is not asking for anything specific and won't tell us what it is he needs to know.
We're not mind readers. If he asks "how do you do [such & such], we could do what you are suggesting but since we have to literally interrogate the OP, (which we shouldn't have to do) , what you are suggesting is undefined.
We already told him about the Prescaler.
If you have read this thread completely you know that the OP originally said he didn't want an internal solution because he couldn't read the datasheet (but didn't tell us that)
And then there's the fact that this post is totally UNNECESSARY because all the OP had to do was Google "arduino change clock prescaler" to get THIS: and the FIRST link at the top is THIS
The Arduino usually runs at 16MHz (external clock + no prescaler). However, lowering the clock speed has proven to be critical in power managing low-power system (eg. powered by solar cells) such as the ones I have been developing as part of projects such as Accrochages and Absences.
However, when one changes the clock prescaler, time-based methods millis() and delay() become void, since time needs to be multiplied by the prescaler.
The following library provides get/set methods for the clock prescaler as well as two alternative methods for the millis()/delay() methods:
raschemmel:
Probably because the OP is not asking for anything specific and won't tell us what it is he needs to know.
We're not mind readers. If he asks "how do you do [such & such], we could do what you are suggesting but since we have to literally interrogate the OP, (which we shouldn't have to do) , what you are suggesting is undefined.
We already told him about the Prescaler.
If you have read this thread completely you know that the OP originally said he didn't want an internal solution because he couldn't read the datasheet (but didn't tell us that)And then there's the fact that this post is totally UNNECESSARY because all the OP had to do was Google "arduino change clock prescaler" to get THIS: and the FIRST link at the top is THIS
i hope it's not personal .
i hope it's not personal .
Of course not, but this is what I meant about posting on the forum every time you have a question.
The link I posted from Google is only one of many about changing the arduino prescaler. It's a waste of time when members are too lazy to use Google first. If you had found that link with Google and didn't understand it and wanted clarification, that would have been different, and it would not have taken much time to clarify it. As it is , this thread took up much more time than necessary , all because you don't (or didn't ) use Google. Is that too much to ask ?
Here's another link with some useful info.
If you watch this Youtube video, it explains how to interpret the datasheet section about the prescaler as well as demonstrating the power consumption difference with slower clock frequencies and putting the CPU to sleep, lowering the bare minimum current consumption from 14 mA to 230 uA.
The link I posted from Google is only one of many about changing the arduino prescaler.
in my opinion, the problem here is not about googling or not googling . Google gives you many links, and some of them
will not give a good answer . So, it is better to ask on a forum where people are supposed to give serious answers, which is most of the time the case here
- And even if there are some wrong answers, they are quickly corrected here.
The problem with this thread is that the OP didn't tell the "why" at the beginning - If he had, one of the first answers would have been "yes, you can do it using....... but it won't help you with your problem, instead you could try...... "
alnath:
The problem with this thread is that the OP didn't tell the "why" at the beginning - If he had, one of the first answers would have been "yes, you can do it using....... but it won't help you with your problem, instead you could try...... "
It's called the "XY problem".
It is - or must be - the first answer to many questions.
raschemmel:
And then there's the fact that this post is totally UNNECESSARY because all the OP had to do was Google "arduino change clock prescaler" to get THIS: and the FIRST link at the top is THIS
Have you ever taught any classes? Or better yet, have you ever had a professor who just scribbles garbage on the blackboard, talks for hours using math and terminology that makes your head spin and finally he asks "any questions" and you're so overwhelmed that you can't even think of a question to ask, let alone UNDERSTAND the material.
I have a particular, personal method of teaching. I KNOW the students are near being overwhelmed right from the start - no need to push them over the edge.
I start out with simple explanations and analogies to help the students UNDERSTAND the "basic idea behind the subject".
Then, when I present them with the actual course work, they are not frustrated and confused, their faces light up and you can see in their minds "Oh NOW I get this - it makes perfect sense now".
Now I'll give you an analogy to help explain where I'm coming from (I'm sure you already know, but I want to show you how good analogies work).
Think of a kid with a brand new driver's license. He's flooded with emotions. He's high on the idea of being free and being able to go anywhere he wants to, he's a little nervous driving because of his inexperience and he has no "mental inventory" of the kind of things that can pop out at you on the road and how to instinctively react to them.
Now imagine the kid is driving and he runs into some ice and begins to slowly slide and yaw sideways. Instantly, his stress level (brain CPU usage) shoots up to 100%, he doesn't know what to do, he panics and then does the worst possible thing... he slams on the brakes.
The wheels lock up and the car just slides all the more. Now pure panic sets in.. he's got no clue what to do and he ends up wrapped around a tree.
Now, take the same scenario with an older, experienced driver. The driver is calm (because of his experience) and his "brain CPU usage" idles at probably 5%.
When the skid begins, the experienced driver knows... no brakes, no sudden turns of the wheel, glance all around for a safe place to "crash" into, try the steering wheel, notice it seems to act in reverse, so turn it in reverse and quite possibly the experienced driver coasts down and steers out of the skid and nothing at all happens.
Same thing with students in a classroom. They don't know the material (that's why they're IN the class!), they're stressed and then hearing terminology and seeing seemingly complex equations quickly turn on panic mode.
What then do they LEARN? Nothing. The more clever ones memorize enough to pass the tests, then forget it all. What good is that?
But when I teach, I first explain how the "material" (equations, circuits, whatever) work, their practical daily usage in the world, anything relevant, interesting and UNCOMPLICATED.
Now that they see a bigger picture, they are "calm" enough to understand the math and theory and a lot of times don't need to memorize anything because they UNDERSTAND it and can use their understanding to derive the equations... even decades later... because they didn't just MEMORIZE, they UNDERSTOOD.
Sorry a bit long winded, but maybe now you see why I reply with explanations, followed by sample code and/or analogies.
How can someone search Google for something when they aren't even sure "what it's called" or even what questions to ask?
Personally, it annoys me when someone wastes EVERYONE'S time by saying "Google it" or "See the datasheet". Really? Is that actually any HELP? I don't think so.
alnath:
in my opinion, the problem here is not about googling or not googling . Google gives you many links, and some of them
will not give a good answer . So, it is better to ask on a forum where people are supposed to give serious answers, which is most of the time the case here
This, EXACTLY!
Grumpy_Mike:
Yes you can do that. Although I am not sure why you would want to do so.
I can tell you one reason. I built myself a "Super Esplora" (an ABS plastic chassis with all kinds of Arduino "stuff" attached to it such as a MEGA2560 board, an LCD display, a 1 amp max 1.2 to 15 volt adjustable regulator with a 10 turn pot (for testing A/D inputs and other things that need variable or odd voltages), momentary pushbuttons mounted and wired to a connector that can plug into the Arduino, a rotary encoder, a small digital volt and milliamp meter, etc... etc...).
On the underside, there is a 7805 on a heatsink with a small fan to power ANYTHING I want to connect to the "esplora" without toasting the Arduino regulator.
(OK now I'm getting to the point!)... this particular MEGA R3 board has a digitally controlled module which I can program to generate sine, square, triangle and 0 Hz (DC) with 4 output channels and controlled with an UNO 328P, VFD display and keypad. One of the output channels provides the CLOCK for the MEGA R3 board.
I use this mostly to run the Arduino MEGA board at different clock speeds (overclocked AND underclocked) which I use to check and verify timing within driver libraries, as well as seeing just how fast an AVR can clock before it starts to get flaky and how much further before it crashes (there's no lower limit... I can turn the clock off, then back on and the AVR just picks up where it left off.
For example, if I'm writing a driver for an RTC chip and the datasheet says something like "minimum setup and hold time between enable and data valid is 50 nanoseconds", I can test different Arduino clock speeds along with different delays to find out:
I can also check things like baud rates (for example, with a 16.000 crystal, 115200 baud is actually 117647 baud). How far off can I be before errors show up? Is the acceptable error "delta" the same for different speeds, or does it vary? If it varies, I can acquire a LOT of data points with odd but known clock speeds and then curve fit the data to graphically "see" what's going on under the hood.
Granted, an "infinitely" variable clock generator is of little to no use for most people, but there IS indeed a valid use for one (as well as some "invalid" uses).
Hint: Set the oscillator to something in the AM broadcast band that's unocccupied on the dial and then PWM the oscillator to generate pseudo amplitude modulation... (as well as getting a real-world demo of what "aliasing" means) or do the same in the FM broadcast band and "wiggle" the frequency with audio... bingo you have FM!
The programmable oscillator is 30% a useful tool and 70% a really fun toy! ![]()
raschemmel:
It's stupid to use an external chip to control the ATmega328 clock when it can do it using prescaler commands.
Well then I must be stupid, because I have an Arduino MEGA R2 board running from an external clock which is one output of a 4 channel digitally controlled frequency/waveform generator and the generator is controlled with a 328p processor, a VFD display and a 16 button keypad.
In addition to doing all other kinds of neat things with it, I can also select and generate ANY frequency I desire to clock the MEGA which I use in turn to test connected parallel and SPI projects to see what timings they REALLY need as opposed to what the datasheet says.
And sometimes I need finer grained control than F_CPU/2, F_CPU/4, etc....... I may want "18.432 mHz" or maybe "1.440 mHz" and see what the RFI of an Arduino sounds like on an AM radio.......
I was looking for a chip like that but couldn't finf one. Anything that frees you from the " divisable by 2" restriction is an improvement. I neglected to cite that as an exception. Yes, you have escaped the chains of the Prescaler restrictions. I didn't see any mention of how you did it. ( other than that you had a certain Mega board but no links or anything specific that would help anyone, let alone the OP. I concede your claim invalidates my statement but only if you back it up with proof , like links to where you got the "digitally controlled arbitrary waveform generator. " I looked but was unable to find one though I was sure it exists.) That would be interesting to see. I wouldn't buy a Mega board and I don't know if your solution even qualifies for this post unless you can show how it can be done with the ATmega328, (WITHOUT needing a Mega) Where did you get the VFD ?
raschemmel:
(1) I was looking for a chip like that but couldn't finf one. Anything that frees you from the " divisable by 2" restriction is an improvement. I neglected to cite that as an exception. Yes, you have escaped the chains of the Prescaler restrictions. I didn't see any mention of how you did it.(2) I concede your claim invalidates my statement but only if you back it up with proof , like links to where you got the "digitally controlled arbitrary waveform generator. " I looked but was unable to find one though I was sure it exists.)
(3) That would be interesting to see. I wouldn't buy a Mega board and I don't know if your solution even qualifies for this post unless you can show how it can be done with the ATmega328, (WITHOUT needing a Mega)
(4) Where did you get the VFD ?
(1) You didn't read my post then. I said exactly how I did it. I use a programmable waveform generator CONTROLLED by an UNO 328p to provide a clock source TO my modified MEGA 2560 R3.
(2) I really don't need to "prove" anything. If you don't believe me and/or are incapable of searching Google, not a whole lot I can do about that.
(3) The OP asked:
So can you supply the arduino clock frequency by a chip instead of a fixed oscillator ?
a chip with a variable frequency output ?
I believe my post about the waveform generator is precisely on topic. My point was not to tell him HOW to do it, but rather answer his question. He asked "can you supply....clock...by a chip" and I said "yes, in fact I do it".
On the other hand, YOUR first reply to him was not at all helpful and IMHO a bit rude:
It's amazing what you can learn when you spend YOUR OWN TIME to actually READ a DATASHEET instead of just always posting on the forum for your answers everytime you have a question about anything.
(4) CLICK HERE and pick one.