Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) ATTiny and Clock Speeds (Read 18794 times)
davidcoward
Junior Member
**
Offline


Posts: 56
Joined: Oct 5th, 2012
ATTiny and Clock Speeds
Nov 25th, 2012 at 11:52am
Print Post  
Hi there

I'm using ATTiny85 for a simple project and have successfully added it to the Visual Micro board list. I can compile and upload projects, but there seems to an issue with the clock speed.

Using a simple "Blinky" in the standard (non VS) Arduino environment, I can make the led blink once per second, change the clock speed, upload the bootloader, rebuild and it will still blink at once per second.

However, in the Visual Micro environment, the clock speed seems to be ignored and the LED blinks "too fast" in all cases. In other words, if I use the Arduino environment to set the clock speed for (say) a 1Mhz device, it will build and run correctly. If I select the same device and speed in VM, build and upload it won't.

Is there some independent setting for choosing/altering the clock speed?

David
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #1 - Nov 25th, 2012 at 12:15pm
Print Post  
Hi, currently vm passes the F_CPU from boards.txt. I'll test it
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #2 - Nov 25th, 2012 at 2:47pm
Print Post  
Some questions...

1) In the Boards.txt what is the value of [BoardName].build.f_cpu

2) Please enable Tools>Options>Visual Micro>Compiler>Verbose and email the output from a compile.

In the meantime you might know that you can enable the "File>Preferences>External Editor" checkbox in the Arduino IDE. This allows you to have the sketch open in both vs and arduino at the same time. Clicking upload in the arduino will read the latest changes to your code and compile/upload. This allows you to edit in VS and upload using Arduino.

Thanks
  
Back to top
IP Logged
 
davidcoward
Junior Member
**
Offline


Posts: 56
Joined: Oct 5th, 2012
Re: ATTiny and Clock Speeds
Reply #3 - Nov 25th, 2012 at 6:50pm
Print Post  
Hi Tim and thanks for looking in to this.

The relevant parts of boards.txt are as follows:

attiny85.name=ATtiny85 (internal 1 MHz clock)
attiny85.bootloader.low_fuses=0x62
attiny85.bootloader.high_fuses=0xdf
attiny85.bootloader.extended_fuses=0xff
attiny85.upload.maximum_size=8192
attiny85.build.mcu=attiny85
attiny85.build.f_cpu=1000000L
attiny85.build.core=arduino:arduino
attiny85.build.variant=tiny8

attiny85-8.name=ATtiny85 (internal 8 MHz clock)
attiny85-8.bootloader.low_fuses=0xe2
attiny85-8.bootloader.high_fuses=0xdf
attiny85-8.bootloader.extended_fuses=0xff
attiny85-8.upload.maximum_size=8192
attiny85-8.build.mcu=attiny85
attiny85-8.build.f_cpu=8000000L
attiny85-8.build.core=arduino:arduino
attiny85-8.build.variant=tiny8

Which looks OK.

The (truncated due to forum post size) verbose output with a 1Mhz device selected is:

Compiling 'TinyTest' for 'ATtiny85 (internal 1 MHz clock)'
Build folder: file://C:\Users\David\AppData\Local\VMicro\Arduino\Builds\TinyTest\attiny85
SketchLibFolders
arduino\arduino-1.0.1\hardware\tools\avr\lib\gcc\avr\4.3.2\include\;
Summary: Header=1 Prototypes=4 Imports=0
C:\Users\David\Documents\Arduino\arduino-1.0.1\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=attiny85 -DF_CPU=1000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -DVISUALMICRO_COMPILER_VER=1 " -I"C:\Users\David\Documents\Arduino\hardware\attiny\variants\tiny8" 


And the 8Mz version:

CCompiling 'TinyTest' for 'ATtiny85 (internal 8 MHz clock)'
Build folder: file://C:\Users\David\AppData\Local\VMicro\Arduino\Builds\TinyTest\attiny85-8
SketchLibFolders
arduino\arduino-1.0.1\hardware\tools\avr\lib\gcc\avr\4.3.2\include\;
Summary: Header=1 Prototypes=4 Imports=0
C:\Users\David\Documents\Arduino\arduino-1.0.1\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=attiny85 -DF_CPU=8000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -DVISUALMICRO_COMPILER_VER=1 -

I didn't know about that option, si I'll enable it and upload from Arduino and see what happnes!

Thanks

David
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #4 - Nov 25th, 2012 at 7:11pm
Print Post  
Strange, vm is setting the F_CPU define correctly. Can you switch on verbose in arduino ide prefs so we can see the difference. Thanks
  
Back to top
IP Logged
 
davidcoward
Junior Member
**
Offline


Posts: 56
Joined: Oct 5th, 2012
Re: ATTiny and Clock Speeds
Reply #5 - Nov 25th, 2012 at 7:29pm
Print Post  
Here's 1Mhz as the example:

C:\Users\David\Documents\Arduino\arduino-1.0.1\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=attiny85 -DF_CPU=1000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IC:\Users\David\Documents\Arduino\arduino-1.0.1\hardware\arduino\cores\arduino -IC:\Users\David\Documents\Arduino\hardware\attiny\variants\tiny8

Looks OK. I don't have the board here at the moment, so in the morning, I'll try a VS upload v Arduino upload for the same simple source and let you know.

The problem manifests itself in a delay() function. The silver lining was that it made me learn about Timer interrupts on the tiny device...

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #6 - Nov 25th, 2012 at 7:52pm
Print Post  
Yes it looks the same to me. Interested to hear the result of the test thanks.
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #7 - Nov 25th, 2012 at 8:07pm
Print Post  
Are you uploading using the normal serial/usb system or are you using a programmer?
  
Back to top
IP Logged
 
davidcoward
Junior Member
**
Offline


Posts: 56
Joined: Oct 5th, 2012
Re: ATTiny and Clock Speeds
Reply #8 - Nov 25th, 2012 at 8:12pm
Print Post  
Both, I suppose. It's ATtiny85 so I'm using "Arduino as ISP"

Seems to work fine.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #9 - Nov 25th, 2012 at 8:18pm
Print Post  
Okay when you have your arduino please switch on verbose upload in the arduino ide prior to upload. I would like to see the output from that. Thanks very much.
  
Back to top
IP Logged
 
davidcoward
Junior Member
**
Offline


Posts: 56
Joined: Oct 5th, 2012
Re: ATTiny and Clock Speeds
Reply #10 - Nov 25th, 2012 at 9:31pm
Print Post  
Will do.

I suppose the fact that  simple delay() function runs too quickly indicates that the chip clock is faster than the compiler thinks it is.

But it occurs to me that it is not easy to work out what the clock has actually been set to. Maybe I could build something into the ISR which does the flashing. If I get it to go once per second when the 8Mhz device is selected, I would expect it to go once per 8s when a 1Mhz device has been selected (assuming the bootloader has been loaded correctly for 1Mhz).

Extending this a bit, I could have one LED driven by delay and the other driven by an ISR. If I build for 1Mhz then 8Mhz, the delay() LED should flash at a constant rate, but the ISR LED will change.

I am moving from (many years of) PIC to Arduino/AVR, so the toolchain and architecture is all a bit new to me, but is my suggested test a reasonable diagnostic? It will depend how delay() works. Does it use interrupts?  Does it interfere with other interrupt processes?

Thanks again

David




  
Back to top
 
IP Logged
 
davidcoward
Junior Member
**
Offline


Posts: 56
Joined: Oct 5th, 2012
Re: ATTiny and Clock Speeds
Reply #11 - Nov 26th, 2012 at 10:29am
Print Post  
OK, I have tackled this in a more structured way. It is the bootloader burning from VM/VS (via Arduino as ISP) that seems to be the issue:

Burning bootloader to board 'ATtiny85 (internal 8 MHz clock)' using 'Arduino as ISP'
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avr_read(): error reading address 0x0000
    read operation not supported for memory "lock"
avrdude: failed to read all of lock memory, rc=-2

And after this operation, the choice of board is unchecked (you have to trust me that it was OK before). I do have a screenshot showing this, but can't work out how to paste it into a message....

So my symptom of yesterday is explained by the facts that the chip was set to 8Mhz (and did not change), the board to 1Mhz, thus things flashed more quickly.

The workaround is straightforward and is simply to use the Arduino environment to load the bootloader.

David








  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #12 - Nov 26th, 2012 at 11:04am
Print Post  
Thanks.

Once you have burned the bootloader via arduino ide, does it still fail to upload your sketch at the right speed using vm?
« Last Edit: Nov 26th, 2012 at 11:07am by Tim@Visual Micro »  
Back to top
IP Logged
 
davidcoward
Junior Member
**
Offline


Posts: 56
Joined: Oct 5th, 2012
Re: ATTiny and Clock Speeds
Reply #13 - Nov 26th, 2012 at 11:37am
Print Post  
Yes.

It seems to forget the board name, or curiously, builds for a different device than that which is checked. I have a screenshot of this situation as well, if I could figure out how to attach it...

It built for an 8Mhz clock when the selected board was 1Mhz.

David
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #14 - Nov 26th, 2012 at 1:23pm
Print Post  
You can email the screen shot thanks
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #15 - Nov 26th, 2012 at 6:08pm
Print Post  
This might be connected to the internal system needing to remove the dash from the real board name. If I recall this change was made not so long ago.

I have some other work to complete, hopefully in a week or so I can find time to re-test the custom boards, with dashes and also the isp program upload.
  
Back to top
IP Logged
 
davidcoward
Junior Member
**
Offline


Posts: 56
Joined: Oct 5th, 2012
Re: ATTiny and Clock Speeds
Reply #16 - Nov 26th, 2012 at 6:32pm
Print Post  
I had the dash issue. I picked up the solution from the forum and downloaded the latest version, which fixed it.

It's not a big deal in the overall scheme of things. Just something to know about and work around for the moment.

Thanks for looking into it!

Top class support as well as a great product! (And you can quote me.)

David

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ATTiny and Clock Speeds
Reply #17 - Nov 27th, 2012 at 12:04pm
Print Post  
Thanks very much, I want this fixed. As soon as the Arduino "Due" work is complete I'll take a look at it. (Week or two)
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint