Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

How do you change the clk speed?

How do you change the clk speed?

2006-11-21 by Richard Cooke

Hi Folks,

I'm working on the ATtiny13 with the AVR Dragon and the latest version
of AVR Studio (4.12 SP4).  I guess I don't understand how to change
the clock frequency correctly.  I read the manual and I thought that
if I used:

CLKPR=0x80;  // enable the Clock Prescaler Change Enable bit
CLKPR=0x02;  // system clock divide by 4

Isn't this the proper way to change the clock?  I'm measuring the
current and I see no change.  I'm running the chip at 5V and according
the the spec sheet I should measure a little over 1ma at 1.2MHz.

Any ideas?

Thanks,

Richard Cooke

RE: [AVR-Chat] How do you change the clk speed?

2006-11-21 by Cat C

I don't know much about your specific case, and you don't say quite enough, 
but if:

0x80;  // enable the Clock Prescaler Change Enable bit
and
0x02;  // system clock divide by 4

Maybe you want:
CLKPR=0x82

Cat

----Original Message Follows----
Show quoted textHide quoted text
From: "Richard Cooke" <rcooke@digitalwavelength.com>
Reply-To: AVR-Chat@yahoogroups.com
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] How do you change the clk speed?
Date: Tue, 21 Nov 2006 05:23:08 -0000

Hi Folks,

I'm working on the ATtiny13 with the AVR Dragon and the latest version
of AVR Studio (4.12 SP4).  I guess I don't understand how to change
the clock frequency correctly.  I read the manual and I thought that
if I used:

CLKPR=0x80;  // enable the Clock Prescaler Change Enable bit
CLKPR=0x02;  // system clock divide by 4

Isn't this the proper way to change the clock?  I'm measuring the
current and I see no change.  I'm running the chip at 5V and according
the the spec sheet I should measure a little over 1ma at 1.2MHz.

Any ideas?

Thanks,

Richard Cooke





Yahoo! Groups Links



_________________________________________________________________
Ready for the world's first international mobile film festival celebrating 
the creative potential of today's youth? Check out Mobile Jam Fest for your 
a chance to WIN $10,000! www.mobilejamfest.com

RE: [AVR-Chat] How do you change the clk speed?

2006-11-21 by Larry Barello

I recently went through this exercise on the mega88.  In short, it works
great, but I would check for any errata on the tiny13 regarding that option.

My problem, it turned out, had nothing to do with the clock change, but in
recording whether I was running at high speed or not.  My logic got out of
synch.  I switch from CLK/2 to CLK/256 which has a dramatic effect on
current draw.

Anyway, you need to make sure the two instructions follow each other.
Inspect the generated assembly code (assuming this is avr-gcc) to verify.
Another thing you can do is toggle an output pin and directly verify the
clock change.  Depending upon your code, you might protect them with an
CLI/SEI pair.

Finally, make sure that hooking up the dragon (in debug mode) that doesn't
mess up your expected current draw.  I did all my measurements with the
one-wire debugger disabled.
Show quoted textHide quoted text
-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
Of Richard Cooke
Sent: Monday, November 20, 2006 9:23 PM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] How do you change the clk speed?

Hi Folks,

I'm working on the ATtiny13 with the AVR Dragon and the latest version
of AVR Studio (4.12 SP4).  I guess I don't understand how to change
the clock frequency correctly.  I read the manual and I thought that
if I used:

CLKPR=0x80;  // enable the Clock Prescaler Change Enable bit
CLKPR=0x02;  // system clock divide by 4

Isn't this the proper way to change the clock?  I'm measuring the
current and I see no change.  I'm running the chip at 5V and according
the the spec sheet I should measure a little over 1ma at 1.2MHz.

Any ideas?

Thanks,

Richard Cooke




 
Yahoo! Groups Links

Re: [AVR-Chat] How do you change the clk speed?

2006-11-21 by Jim Wagner

I don't have a Tiny13 data sheet in front of me, but I
would expect some timing restrictions, like there are for
disabling the watchdog. You MAY need to write to the Change
Enable bit, then within a specific time window, write the
new clock config. The data sheet ought to be pretty
explicit about the procedure.

Jim

On Mon, 20 Nov 2006 22:47:54 -0700
 "Cat C" <catalin_cluj@hotmail.com> wrote:
> I don't know much about your specific case, and you don't
> say quite enough, 
> but if:
> 
> 0x80;  // enable the Clock Prescaler Change Enable bit
> and
> 0x02;  // system clock divide by 4
> 
> Maybe you want:
> CLKPR=0x82
> 
> Cat
> 
> ----Original Message Follows----
> From: "Richard Cooke" <rcooke@digitalwavelength.com>
> Reply-To: AVR-Chat@yahoogroups.com
> To: AVR-Chat@yahoogroups.com
> Subject: [AVR-Chat] How do you change the clk speed?
> Date: Tue, 21 Nov 2006 05:23:08 -0000
> 
> Hi Folks,
> 
> I'm working on the ATtiny13 with the AVR Dragon and the
> latest version
> of AVR Studio (4.12 SP4).  I guess I don't understand how
> to change
> the clock frequency correctly.  I read the manual and I
> thought that
> if I used:
> 
> CLKPR=0x80;  // enable the Clock Prescaler Change Enable
> bit
> CLKPR=0x02;  // system clock divide by 4
> 
> Isn't this the proper way to change the clock?  I'm
> measuring the
> current and I see no change.  I'm running the chip at 5V
> and according
> the the spec sheet I should measure a little over 1ma at
> 1.2MHz.
> 
> Any ideas?
> 
> Thanks,
> 
> Richard Cooke
> 
> 
> 
> 
> 
> Yahoo! Groups Links
> 
> 
> 
>
_________________________________________________________________
> Ready for the world's first international mobile film
> festival celebrating 
> the creative potential of today's youth? Check out Mobile
> Jam Fest for your 
> a chance to WIN $10,000! www.mobilejamfest.com
> 

---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Re: How do you change the clk speed?

2006-11-21 by Richard Cooke

Hi Guys,

Thanks for the suggestions but I'm still not seeing the change in the
clock.  If I set the 9.6MHz fuse my circuit will use 5.1ma.  If I
change the fuse to the 4.8MHz choice my circuit will draw 3.6ma.  No
matter what I use for the CLKPR register values my program isn't
changing the clock.  I'm writing an 0x80 to the register and the next
instruction is the CLKPR = 0x03 so it should be meeting the 4 cycle
restriction as stated in the manual.

Thanks,

Richard Cooke


-- In AVR-Chat@yahoogroups.com, "Larry Barello" <yahoo@...> wrote:
>
> I recently went through this exercise on the mega88.  In short, it works
> great, but I would check for any errata on the tiny13 regarding that
option.
> 
> My problem, it turned out, had nothing to do with the clock change,
but in
> recording whether I was running at high speed or not.  My logic got
out of
> synch.  I switch from CLK/2 to CLK/256 which has a dramatic effect on
> current draw.
> 
> Anyway, you need to make sure the two instructions follow each other.
> Inspect the generated assembly code (assuming this is avr-gcc) to
verify.
> Another thing you can do is toggle an output pin and directly verify the
> clock change.  Depending upon your code, you might protect them with an
> CLI/SEI pair.
> 
> Finally, make sure that hooking up the dragon (in debug mode) that
doesn't
> mess up your expected current draw.  I did all my measurements with the
> one-wire debugger disabled.
> 
> -----Original Message-----
> From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On
Behalf
Show quoted textHide quoted text
> Of Richard Cooke
> Sent: Monday, November 20, 2006 9:23 PM
> To: AVR-Chat@yahoogroups.com
> Subject: [AVR-Chat] How do you change the clk speed?
> 
> Hi Folks,
> 
> I'm working on the ATtiny13 with the AVR Dragon and the latest version
> of AVR Studio (4.12 SP4).  I guess I don't understand how to change
> the clock frequency correctly.  I read the manual and I thought that
> if I used:
> 
> CLKPR=0x80;  // enable the Clock Prescaler Change Enable bit
> CLKPR=0x02;  // system clock divide by 4
> 
> Isn't this the proper way to change the clock?  I'm measuring the
> current and I see no change.  I'm running the chip at 5V and according
> the the spec sheet I should measure a little over 1ma at 1.2MHz.
> 
> Any ideas?
> 
> Thanks,
> 
> Richard Cooke
> 
> 
> 
> 
>  
> Yahoo! Groups Links
>

Re: [AVR-Chat] Re: How do you change the clk speed?

2006-11-21 by John Samperi

At 08:35 AM 22/11/2006, you wrote:
>  I'm writing an 0x80 to the register and the next
>instruction is the CLKPR = 0x03 so it should be meeting the 4 cycle
>restriction as stated in the manual.

Not necessarily....if it is written in C....BOOM..take cover..:)
Have you looked at what the compiler is actually doing? (list file)
May want to write that bit in assembler. Also there was something
on another thread about having to wait another 4 clock cycles
(undocumented feature) before it all happens, may be 4 nops?
I think it was posted on this forum, may have to do a search.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: How do you change the clk speed?

2006-11-21 by Richard Cooke

Hi John,

Here's what the LST file shows:

;      66 void main(void)
                 ;      67 {
                 _main:
                 ;      68 // Declare your local variables here
                 ;      69 char status;
                 ;      70 unsigned int time = 0;
                 ;      71 
                 ;      72 // Crystal Oscillator division factor: 2
                 ;      73 #pragma optsize-
                 ;      74 CLKPR=0x80;
                 ;	status -> R16
                 ;	time -> R17,R18
000054 e010      	LDI  R17,0
000055 e020      	LDI  R18,0
000056 e8e0      	LDI  R30,LOW(128)       // set enable bit
000057 bde6      	OUT  0x26,R30        
                 ;      75 CLKPR=0x02;
000058 e0e2      	LDI  R30,LOW(2)         // divide by 2
000059 bde6      	OUT  0x26,R30


Sorry about the formatting - this is how the compiler writes it.  But
as far as I can tell the two writes are occurring one right after the
other.

Richard

--- In AVR-Chat@yahoogroups.com, John Samperi <samperi@...> wrote:
Show quoted textHide quoted text
>
> At 08:35 AM 22/11/2006, you wrote:
> >  I'm writing an 0x80 to the register and the next
> >instruction is the CLKPR = 0x03 so it should be meeting the 4 cycle
> >restriction as stated in the manual.
> 
> Not necessarily....if it is written in C....BOOM..take cover..:)
> Have you looked at what the compiler is actually doing? (list file)
> May want to write that bit in assembler. Also there was something
> on another thread about having to wait another 4 clock cycles
> (undocumented feature) before it all happens, may be 4 nops?
> I think it was posted on this forum, may have to do a search.
> 
> Regards
> 
> John Samperi
> 
> ********************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495       Fax (02) 9674-8745
> Email: john@...
> Website  http://www.ampertronics.com.au
> *Electronic Design * Custom Products * Contract Assembly
> ********************************************************
>

Re: [AVR-Chat] Re: How do you change the clk speed?

2006-11-22 by John Samperi

At 10:27 AM 22/11/2006, you wrote:
>But
>as far as I can tell the two writes are occurring one right after the
>other.

It all looks ok, what happens after the last write? I have a feeling
(can't find the thread) that you need 4 clock cycles AFTER of doing
nothing before the clock actually changes. Can you put a few (4??) nops
after the last write? I guess anything that does nothing would do.
Can you have a toggling pin driving a led to see if it actually happens
instead of just relying on the current reading?

I remember once trying to use the prescaler on the Tiny2313 with no results
and then giving up :) I may have another go myself.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] Re: How do you change the clk speed?

2006-11-22 by Mark Jordan

On 22 Nov 2006 at 13:15, John Samperi wrote:

> I remember once trying to use the prescaler on the Tiny2313 with no results
> and then giving up :) I may have another go myself.
> 

	I use this:

	ldi	tmp, 1<<CLKPCE		; Enable changes
	out	CLKPR, tmp
	ldi	tmp, 1<<CLKPS0		; Xtal/2
	out	CLKPR, tmp

	Works very well on my TINY2313 running with a 14MHz Xtal.

	Mark Jordan

AVR TWI code needed

2006-11-24 by praveen kumar

hi,
  
can anybody send me TWI C code without using avr library files,
  i.e custumed one like mine attached with this.
   
  what is wrong with this code.
  this code is for AVRGCC
   
   
  praveen
   
  pinn@cle softek,Banglore.
  email:praveen_cpp@yahoo.co.in
   

 				
---------------------------------
 Find out what India is talking about on  - Yahoo! Answers India 
 Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW

[Non-text portions of this message have been removed]

Re: [AVR-Chat] AVR TWI code needed

2006-11-25 by John Samperi

At 05:56 PM 24/11/2006, you wrote:
>like mine attached with this.
>
>   what is wrong with this code.
>   this code is for AVRGCC

Attachments don't come through on this forum, you can
either post your code in the files area or ask the question
on the GCC forum at avrfreaks.net


Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.