| Author |
Message |
|
|
Posted: Feb 14, 2012 - 11:22 AM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Hello AVR freaks,
I am a student and decided to design a system using the atmega1284p cause it is awesome, I really don't have any experience with microcontrollers and never programmed one but my issue currently is how to get the software on the uC,
my college has a pinmaster 48 programmer that is compatible with alot of uCs, it has direct pin interface and jtag/ISP.
My worry is the software is old and the 1284p is not on the list but the 664p is which I hear is similar.
Are there any way to use this machine to program the uC?
Thanks
I am starting to think I should I have just got 89s52 but it is not nearly as powerful. |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 11:40 AM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
I do not know hat a '664p' is.
The whole point of modern flash based MCUs is that you can program them in-circuit. i.e. ICSP or ISP.
You really do not want to be pulling chips in and out of a PCB for programming.
You just put a small 6-pin ISP header on your pcb and use a regular Atmel programmer like AVRISP-2 or usbasp.
If your mega1284P is on a dev board with USB or RS232 connections, you install a bootloader and never need an external programmer again. (you do need a programmer to program the bootloader)
If you are too poor to buy an AVRISP-2 or usbasp, you will need the 'Pinmaster 48' to be available to you. Will the college approve ?
Ask the manufacturer for an update to its software to handle the ATmega1284P.
David. |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 11:44 AM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
pinmaster 48
The 1284 does not appear on this list:
http://www.mqp.com/text/devs48.txt
but many older mega AVRs do so I'm guessing this list may simply be out of date. The chances are the firmware of the programmer has an upgrade to cover the more modern ATmega too - worth asking at mqp.com |
_________________
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 01:15 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
|
david.prentice wrote:
I do not know hat a '664p' is.
The whole point of modern flash based MCUs is that you can program them in-circuit. i.e. ICSP or ISP.
You really do not want to be pulling chips in and out of a PCB for programming.
You just put a small 6-pin ISP header on your pcb and use a regular Atmel programmer like AVRISP-2 or usbasp.
If your mega1284P is on a dev board with USB or RS232 connections, you install a bootloader and never need an external programmer again. (you do need a programmer to program the bootloader)
If you are too poor to buy an AVRISP-2 or usbasp, you will need the 'Pinmaster 48' to be available to you. Will the college approve ?
Ask the manufacturer for an update to its software to handle the ATmega1284P.
David.
by 664p I ment the 644p and the pinmaster has ISP connections but the uC is not in the list of the pinmaster software |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 03:48 PM |
|


Joined: Sep 04, 2002
Posts: 21253
Location: Orlando Florida
|
|
| Don't drink cokes for a couple weeks. Every time you get thirsty, put that buck in your pocket. After a week or so, you can buy your very own Atmel AVR ISP mkii for $35 from the Atmel store. Durable goods. You can take it with you to your first engineering job. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 04:23 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
|
|
|
|
Posted: Feb 14, 2012 - 06:49 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Thanks guys so it seems it won't work, I thought since it had ISP it would just program via software but each microcontroller is different ISP? Still confused but
What is my cheapest and most simplest alternative, I did look at the programmer on the atmel website AVRmkII, it costs too much for me, especially since this is a college project and is assigned a small budget, I could buy it myself but still not sure it is worth that much.
Please recommend a cheap ISP programmer or any programmer in fact that will work with 1284p, the simpler the better as I have no clue and really dont want to run into problems. |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 07:08 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
You wrote:
Please recommend a cheap ISP programmer
Previously I wrote:
$1.63 gets this delivered to your door: http://www.ebay.com/itm/USB-to-RS232-SE ... d=ViewItem
Is $1.63 still too expensive for you then? |
_________________
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 07:22 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
|
clawson wrote:
You wrote:
Please recommend a cheap ISP programmer
Previously I wrote:
$1.63 gets this delivered to your door: http://www.ebay.com/itm/USB-to-RS232-SE ... d=ViewItem
Is $1.63 still too expensive for you then?
ofcourse not but what I see is a usb to serial cable, looks nothing like avr mkII, how would it even work?, I am lookimg for something u can use with avr studio most likely |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 07:25 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
ofcourse not but what I see is a usb to serial cable, looks nothing like avr mkII, how would it even work?, I am lookimg for something u can use with avr studio most likely
Apologies - wrong ebay link. Sorry. I meant this one:
http://www.ebay.com/itm/USBASP-USBISP-A ... 564571ffe4
The price has, I'm afraid gone to $4 |
_________________
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 07:56 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
I am sure that there will be an upgrade file for your 'Pinmaster 45'. Just ask the makers.
The main consideration is: "Can you take it home with you?"
Spend a whole $4 and you can use the usbasp whenever you like.
From Studio4, you use a .BAT file to control the usbasp via the Tools menu.
From Studio5.1, I think you should be able to run directly from the Tools menu.
David. |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 08:04 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
|
david.prentice wrote:
I am sure that there will be an upgrade file for your 'Pinmaster 45'. Just ask the makers.
The main consideration is: "Can you take it home with you?"
Spend a whole $4 and you can use the usbasp whenever you like.
From Studio4, you use a .BAT file to control the usbasp via the Tools menu.
From Studio5.1, I think you should be able to run directly from the Tools menu.
David.
My bad, I forgot to mentioned I send the company of the pinmaster an email and they replied saying they no longer support the universal programmer, the latest atmega supported was the 644p. Still nice of them to reply so soon, they do usb analyser and stuff now.
I got AVR studio 5.0 installed right now will the usbasp work with that? |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 08:51 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
I got AVR studio 5.0 installed right now will the usbasp work with that?
You can define a post build step in AS5 to invoke "avrdude.exe -c usbasp..." but this will run avrdude (which is what you use with the USBAsp) outside of AS5 - though it will just seem like it's happening inside. |
_________________
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 09:09 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
|
Quote:
My bad, I forgot to mentioned I send the company of the pinmaster an email and they replied saying they no longer support the universal programmer, the latest atmega supported was the 644p. Still nice of them to reply so soon, they do usb analyser and stuff now.
I am surprised that they do not support it. After all, they are still trading.
At least they had the honesty to tell you. (I guess it would take them 1 minute to add support for the ATmega1284P)
David. |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 09:27 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
|
david.prentice wrote:
Quote:
My bad, I forgot to mentioned I send the company of the pinmaster an email and they replied saying they no longer support the universal programmer, the latest atmega supported was the 644p. Still nice of them to reply so soon, they do usb analyser and stuff now.
I am surprised that they do not support it. After all, they are still trading.
At least they had the honesty to tell you. (I guess it would take them 1 minute to add support for the ATmega1284P)
David.
I know it is very disappointed, my thought right now is why can't I use avr studio or avrdude with the pinmaster, since it has an ISP/JTAG interface.
Also another idea is I could use an arduino, I think it would be wiser to pay high cost for arduino then just mkII programmer.
The usbasp ones are ok but they are all from china and it will take weeks, I read the feedback and found some of them even lie saying they are based in uk but really they are in china. |
|
|
| |
|
|
|
|
|
Posted: Feb 15, 2012 - 10:01 AM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
|
|
|
|
|
Posted: Feb 15, 2012 - 11:24 AM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
why can't I use avr studio or avrdude with the pinmaster,
Atmel talks various protocols (AVR069, AVR109) to it's programmers and debuggers. The chances are "pinmaster" have chosen not to implement one of these protocols - remember this thing is not Atmel specific but "talks" to about 50 manufacturers chips so why would they feel bound to specifically use an Atmel protocol? My guess is that they have a proprietary protocol that covers everything all those chips might require and are therefore tied to their own PC software.
Quote:
Also another idea is I could use an arduino, I think it would be wiser to pay high cost for arduino then just mkII programmer.
This is very true - it's easy to turn an Arduino into an ISP programmer. (where do you get "higher cost"? AVRISPmkII is $34 - you can get Arduinos for less than that).
Quote:
The usbasp ones are ok but they are all from china and it will take weeks,
Experience suggests 6 or 7 days to Europe. Presumably the same to any worldwide destination. |
_________________
|
| |
|
|
|
|
|
Posted: Feb 15, 2012 - 03:16 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
| [quote="clawson"]
Quote:
Quote:
Also another idea is I could use an arduino, I think it would be wiser to pay high cost for arduino then just mkII programmer.
This is very true - it's easy to turn an Arduino into an ISP programmer. (where do you get "higher cost"? AVRISPmkII is $34 - you can get Arduinos for less than that).
Quote:
The usbasp ones are ok but they are all from china and it will take weeks,
Experience suggests 6 or 7 days to Europe. Presumably the same to any worldwide destination.
Yh thats what I ment arduino is cheaper then mkII so why pay for a programmer when you can get a whole system.
Also a week is not too bad for delivery from china will look it to that more.
I had my eye on AVR dragon seems cool, debugger and programmer in one, bad point you have to buy ZIF socket and headers to use it as a programmer. |
|
|
| |
|
|
|
|
|
Posted: Feb 15, 2012 - 03:25 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
you have to buy ZIF socket and headers to use it as a programmer.
Just to note that you don't need a ZIF socket - I've never added on to mine. |
_________________
|
| |
|
|
|
|
|
Posted: Feb 15, 2012 - 03:36 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
You need to buy / make proper 10-way and 6-way JTAG and ISP cables for a Dragon.
I put a sheet of clear polycarbonate top and bottom with cut-outs for USB, JTAG, ISP.
Only masochists mess around with HVPP.
If you mess up a chip, it is cheaper to buy a new chip than to buy and solder headers, sockets, jumper wires.
Of course, some people enjoy messing up chips. It is not necessary.
David. |
|
|
| |
|
|
|
|
|
Posted: Feb 16, 2012 - 11:25 AM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Got too many choises,
AVRISP MKII
AVR DRAGON
AVR STK500
AVRISP/ASP CLONES
AVR STK500 CLONES
ALL THEESE OTHER ONES PARALLEL AND SERIAL Bit banging etc
AVRJTAGICE CLONES
A COUPLE AVRISP MKII CLONES
my only concern is will they work atleast with the official product you know it will work with the 1284p
its driving me nuts |
|
|
| |
|
|
|
|
|
Posted: Feb 16, 2012 - 11:29 AM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
If you have $5 buy a USBAsp
If you have $35 buy an AVRISPmkII
If you have $50 buy a Dragon
If you have $80 buy an STK500
Simple as that. (IMAO). |
_________________
|
| |
|
|
|
|
|
Posted: Feb 16, 2012 - 11:56 AM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
As an impecunious student, it is really two choices:
1. USBasp @ $3.99 is hardly going to break the bank.
2. Dragon + some jumper wires is the cheapest way to debug ALL chips.
The USBasp can be added as a 'Tool' but is not directly integrated into Studio. No real inconvenience.
The Dragon is fully supported by Studio and every third party software ever invented.
Of course if you are rich, the choices are more varied. e.g. A reliable dev board.
If you buy from abroad, it can be cheaper but you wait a few days.
Beware carriage and customs charges.
David. |
|
|
| |
|
|
|
|
|
Posted: Feb 18, 2012 - 08:28 AM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Hi David, Will the usbasb you will lend come with the isp cable and is it six pin or 10 pin interface?
I will probably try to setup part of the system this week.
The isp header for the target board should be male right. |
|
|
| |
|
|
|
|
|
Posted: Feb 18, 2012 - 09:01 AM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
All usbasp boards use a 10-pin male header, and a 10-way ribbon cable.
You download the pin-out and USB driver from www.fischl.de/usbasp
I suggest that you wire a matching male header on your pcb (you can leave pins 4, 6, 8, 3 as n/c). Mark a RED dot for pin#1 with a permanent marker. Then you have a reliable connection with your ribbon cable.
Pin #2 will supply 5V power from the usbasp. So you must not supply power to your board in any other way.
Alternatively, leave #2 as n/c if you already have power on your pcb.
David. |
|
|
| |
|
|
|
|
|
Posted: Feb 27, 2012 - 11:16 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Hi,
Is this the right pinout?
I thought I might as well build a connector from the usbasp to uC.
Still haven't recieved the microcontroller, so little time so much to do  |
|
|
| |
|
|
|
|
|
Posted: Feb 27, 2012 - 11:42 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
Where are you buying your microcontroller from?
Farnell deliver next day.
RS might take 2 days.
I always reckon that an Arduino is a very convenient and useful dev board.
It should be easy to get your University project up and running with an Arduino.
If you spend your time on good documentation of your project, you will get good marks.
A 'clever' design with bad or absent documentation is no good to anyone.
David. |
|
|
| |
|
|
|
|
|
Posted: Feb 28, 2012 - 12:03 AM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Yh, it was ment to have arrived last week but some complication happened and now they need to place order again.
Arduino was a choice but isn't it very simple and you would learn less about the hardware side of it. It is still a backup plan in case everything goes wrong, hopefully it wont. At first I was thinking of 8051, the avr was a big step up without going as far as arduino. |
|
|
| |
|
|
|
|
|
Posted: Feb 28, 2012 - 09:30 AM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
Arduino was a choice but isn't it very simple and you would learn less about the hardware side of it.
Au contraire - it's almost undoubtedly the simplest AVR development board there is - they couldn't have made it easier to use.
And while you are right that if you use library code you don't learn so much about the hardware - but you only do that to get started. When you are confident about overall program structure you can then switch to direct hardware access for each peripheral in turn and learn about that. |
_________________
|
| |
|
|
|
|
|
Posted: Feb 28, 2012 - 10:15 AM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
A project starts with an idea, and then you design the solution.
The coding is the last step and fairly trivial.
Why not use the coding system that is easiest?
e.g.
Code:
Serial.begin(9600);
Serial.println("Hello World");
You can always write the equivalent in C or ASM. More work, but it does the same thing.
They all run on the same Arduino hardware. You need no extra wires for the UART.
The Arduino board already has headers that can connect to extra hardware.
David. |
|
|
| |
|
|
|
|
|
Posted: Feb 28, 2012 - 11:50 AM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
If I was to use arduino instead which model would be similar to a atmega1284p.
The prime reason I chose the 1284p was because it had built in adc, 4k eeprom to store data. I want to be able to log information from several sensors onto the eeprom and then periodicly extract it via serial interface to the pc which then converts it to an appropiate format and the send it off to a website.
I have a very little understanding of arduino, I know two things, it is easy to use and it uses atmega chips. |
|
|
| |
|
|
|
|
|
Posted: Feb 28, 2012 - 12:05 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
The "big" Arduinos are based on the mega1280 and mega2560. They have ADC and they have 4K of EEPROM. The main deficiency compared to the 1284 is they only have 8K of SRAM while the 1284 is the only mega AVR that has 16KB.
From boards.txt in the Arduino software:
mega2560.name=Arduino Mega 2560 or Mega ADK
mega.name=Arduino Mega (ATmega1280) |
_________________
|
| |
|
|
|
|
|
Posted: Feb 28, 2012 - 01:03 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
I seriously advise a regular Arduino with a mega328P.
95% of all accessories are designed for the standard Arduino.
If you want some local storage, add a 24C512 or 23C256 (3.3V) on a shield or breadboard.
It is surprising how much you can 'log' to ordinary SRAM or external eeprom.
The internal eeprom is ok for occasional use but is VERY slow for logging purposes. e.g. 320ms for 64 bytes when a 24C512 takes 4ms. Or a 23C256 takes microseconds.
The Arduino has libraries to handle pretty well any hardware ever invented.
They may not all work with the mega2560 boards.
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 01, 2012 - 10:05 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Hi, I got the uC and usbasp setup, I am just wondering will I brick the uC if I flash without changing fusebits or lockbits on avrdude. |
|
|
| |
|
|
|
|
|
Posted: Mar 01, 2012 - 10:59 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
Do not touch the fuses yet.
Just practice uploading program to flash.
Your chip will run at 1MHz.
You can make it run at 8MHz by adding these two lines to the start of your program.
Code:
// Crystal Oscillator division factor: 1
CLKPR = 0x80;
CLKPR = 0x00;
or with avr-gcc:
Code:
#include <avr/power.h>
...
clock_prescale_set(0);
...
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 02, 2012 - 02:06 AM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
| is there any advantage to using the code instead of disabling the divide by 8 fuse, to let it run at 8mhz? |
|
|
| |
|
|
|
|
|
Posted: Mar 02, 2012 - 10:21 AM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
is there any advantage to using the code instead of disabling the divide by 8 fuse, to let it run at 8mhz?
Yes you don't risk crewing the chip by making a wrong fuse setting!
The downside of the code solution is that if you do it as:
Code:
int main(void) {
// Crystal Oscillator division factor: 1
CLKPR = 0x80;
CLKPR = 0x00;
then there could be several thousand instructions executed before main() that will run at the slow 1MHz rather than the new, fast 8MHz speed.
If using avr-gcc you can mitigate this by putting the lines in a separate function:
Code:
__attribute__((naked,section(".init3"))) void setclk(void) {
// Crystal Oscillator division factor: 1
CLKPR = 0x80;
CLKPR = 0x00;
}
That will then be done before any "long" work in the pre-main code. |
_________________
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 01:41 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Hey, I got the 1284p with internal clk and a arduino both setup to blink led every second.
They are not running at the same speed. I had lots of problems with the _delay function in avr toolchain so I am currently using delay_x.h from here.
What could be the problem? |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 01:53 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
How different ?
Unless you specifically set the CLKPR in software (or remove the CKDIV8 fuse) your chip will run at 1MHz.
The Arduino will run at 16MHz. i.e. 16x faster.
If your Toolchain is recent, you should have a working _delay_ms(). Of course you have to tell Studio 5 that you are running at 8MHz or whatever.
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 02:16 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
Unless you specifically set the CLKPR in software (or remove the CKDIV8 fuse) your chip will run at 1MHz.
The Arduino will run at 16MHz. i.e. 16x faster.
Just to say that this alone should not affect the LED blink rate AS LONG AS you specify F_CPU correctly for each program. The _delay() routines use F_CPU to determine how many loops they should do and therefore need to be told accurately how fast the CPU is running at - this is done when you #define F_CPU. So the error is likely that the value you specify for F_CPU does not match reality. If you get it right then:
Code:
LED_on();
for(i=0; i<10; i++) {
_delay_ms(1000);
}
LED_off();
should light up an LED for exactly 10 seconds as shown on the sweep second hand of your wristwatch. If not F_CPU is not set to the actual CPU speed. |
_________________
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 02:33 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
I'm using avr studio 5.0, At the top of the code I define F_CLK 8000000UL and I disable the div/8 fusebit and it runs too fast.
When I use the delay_x.h instead it works ok, I don't have a accurate way or measuring the time.
When I try setup them up to blink at the same time the avr gets a head fairly quickly. so it is definantly blink faster than the arduino.
It just comes down to how accurate the arduino clk is compared to the avr. |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 02:43 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
I'm using avr studio 5.0,
Quote:
When I use the delay_x.h instead it works ok
All the warning signs are here. Atmel made a mistake in 5.0 and set the default build optimisation to be -O0, this almost never works. They corrected this in 5.1 (and now 6.0) so that the default build ("Debug") now uses -O1. Suggest you try the same. |
_________________
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 02:43 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
The delay macros use F_CPU.
They will not care what value to give to F_CLK. It is irrelevant.
Even Studio5 gives a Build report.
Examine any Warnings or Error messages.
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 02:50 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Thanks I thought it was F_CLK for the avr delay.h and F_CPU for the delay_x.h, but I had both defined so my resut above it true.
did the test with the for loop and it turned out the avr is 9.7s and arduino is 10s.
Anyway to fix this ? |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 02:53 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
Anyway to fix this ?
As I say, what optimization setting are you using? The delay.h delays will not work properly at -O0 (which is what 5.0 mistakenly defaults to) |
_________________
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 03:18 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
| I am not sure maybe debug? |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 03:27 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
I'm talking about this...
(what is yours set to?) |
_________________
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 03:52 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
Cliff,
Surely you should choose -O1 for the Debug build.
And -Os or -O3 for the Release build.
It is important to test the final version after you have finished debugging. You might select -Os for these final tests of the Debug version. (and learn how to follow a mixed ASM and C view)
David. |
Last edited by david.prentice on Mar 03, 2012 - 03:53 PM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 03:52 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
| Thanks clawson, it was said to -O0, I changed it to -O1 and the standard util/delay.h is now working but it is still not exactly 10seconds, just like the delay_x.h, could it be the uC internal clock is not running at exactly at 8MHz? |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 03:57 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
You will not discover any calibration errors with your wristwatch. They should be fairly minimal anyway.
I suppose that -3% is within a margin of calibration accuracy. You must be pretty good with your reactions to detect 0.3 seconds in a 10 second period. 3 seconds in a 100 sec period, yes.
Does it really matter anyway?
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 04:01 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
Surely you should choose -O1 for the Debug build.
Not me - I always use -Os everywhere. I simply don't see the point in fannying about with some code that does not reflect what you plan to finally deploy?!? Spend hours getting some timing sequence right in a -O1 build then switch to -Os and start all over again? No thanks. The only downside of debugging -Os (the optimizer is acting at it's most aggressive) simply means that toys like watch windows don't work. Again - big deal? |
_________________
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 06:01 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
| Thanks for the help guys, stupid software bugs. Now i understand and the 0.3s difference is no big deal right. |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2012 - 10:53 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
I presume that you mean PCINT3_vect.
You still need to do an sei()
And of course examine the state of your PCMSK3 pins.
You get an interrupt regardless of which edge has caused a change on any of the enabled pins.
You would be better off starting with an INT0 interrupt.
And explaining exactly what your intentions are, and adding this in your commented code.
Then you can copy-paste real-life code. Otherwise we have to read 'PCINT32_vect' typos.
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 12, 2012 - 10:12 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Hey again,
I just stumbled across a wall with the pin interrupts.
Each port is assigned a pin interrupt register, PCINT(3:0)
What If I want several pin interrupts on the same port,
yes it is possible to initialise them.
But the problem, when they are activated they will start the same ISR.
because the vector is checking all the pins of the port
ISR(PCINT3_vect) THEY ARE NOT SEPERATED.
Is there a solution around this?
Any help is much appreciated  |
|
|
| |
|
|
|
|
|
Posted: Mar 12, 2012 - 10:33 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
Yes.
Code:
...
PCMSK3 = 0b00001011; // enable IRQ on 3 pins
...
ISR(PCINT3_vect)
{
static uint8_t prev;
uint8_t current = PIND & PCMSK3;
uint8_t changed = current ^ prev;
prev = current;
if (changed & 0b00001000) do_pin3();
if (changed & 0b00000010) do_pin1();
if (changed & 0b00000001) do_pin0();
}
The bits will be set in 'changed' on both edges.
If you want the rising / falling edge:
Code:
if (changed & 0b00000010 & current) do_up_pin1();
if (changed & 0b00000010 & ~current) do_down_pin1();
Untested. You can probably be a little neater.
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 12, 2012 - 11:33 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Nice, too bad I don't get it
From my understanding
Current gives the pin that is pressed out of the selected for IRQ.
Changed gives a 1 if different and 0 if same [fixed]
Code:
00001011(pcmask) & 00000010(PinD) = 00000010 (Current)
00000010 ^ 00001000 = 00001010 (changed)
00000010 (now prev)
if(00001010 & 0b00001000) do_pin3();
00001010 & 00001000 = 00001000
I AM CONFUSED AT THIS POINT |
Last edited by JollyMolly on Mar 13, 2012 - 12:05 AM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Mar 12, 2012 - 11:41 PM |
|

Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca
|
|
|
Quote:
Current gives the pin that is pressed out of the selected for IRQ.
Yes .
Quote:
Changed gives a 0 if different and 1 if same...
Nope, the ^ is the XOR operator, so it does the opposite of what you wrote .
Quote:
...but what is the initial value of prev?
From the definition of a static var -> It's zero . You need to review a C book and check out the "Bit Manipulation 101" tutorial .
Don't forget, you can/should try such code sections that you don't get in the simulator ( a non-ISR version of course ) . You can put what David P. gave you near the top of your code in main(), so it gets down soon enough in the start of the simulation . Init. vars and play with it until you get it ( with an open C book, pencil and paper ) . |
_________________ 1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
|
| |
|
|
|
|
|
Posted: Mar 13, 2012 - 08:35 AM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
I second indiana's advice. Open your Boolean textbook on the XOR page. Trace different values with pencil and paper.
XOR is a difficult concept for people. However it just behaves simple Boolean rules, and is really useful. Work through the values bit by bit with the XOR truth table.
Note that my example was untested. If you find something wrong, shout.
'prev' starts off as 0. So you will get 'changed' bits immediately. If you use regular active-low pushbuttons, you set prev to 0b00001011. i.e. the un-pushed value of the buttons.
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 13, 2012 - 11:59 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
I will use the external interrupt int2:0 instead, don't have much time to mess with these things, just spent hours trying to figure out why 0<<SOMEBITINREGISTER, affected my code.
I read somewhere you can use it to make it obvious for others reading your code that a particular bit in register is set to zero.
DOING SO MESSED UP MY CODE, NOW I KNOW BETTER.
EXTRA:
Can I use the SCK, MISO, MOSI pins when the programmer is not programming and only connected for power supply? |
|
|
| |
|
|
|
|
|
Posted: Mar 14, 2012 - 10:40 AM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
just spent hours trying to figure out why 0<<SOMEBITINREGISTER, affected my code.
I read somewhere you can use it to make it obvious for others reading your code that a particular bit in register is set to zero.
Surely it depends what you were doing with it. 0<<anything is 0. It is completely benign to OR or XOR with 0 as nothing changes. It is totally fatal to AND with 0 (unless you really mean to clear the target to 0 in which case you might as well just use "= 0;").
So how were you using (0 << something) ? |
_________________
|
| |
|
|
|
|
|
Posted: Mar 14, 2012 - 10:57 AM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
Quite honestly, most projects only need a few pin-change inputs. So you can use INT0, INT1, INT2 pins. The INTn pins have the advantage of selecting edge or level separately.
OTOH, the INTn pins are not always convenient. The PCINTn_vect interrupts of the modern AVRs can work on any pin.
The first stage of any design is to write down your requirements. Preferably on disk so that you can print on paper.
If you have a clear description of what you want to do, the implementation is easier. Especially because you can ask others to inspect or advise. And when you come back to your project in a year's time, you can understand what you were doing.
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 14, 2012 - 12:20 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
| Yh i understand as it was OR it shouldnt change the value. But.it.certainly has an affect on the prog |
|
|
| |
|
|
|
|
|
Posted: Mar 14, 2012 - 12:24 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
Yh i understand as it was OR it shouldnt change the value. But.it.certainly has an affect on the prog
No it does not - in fact the optimiser in the compiler will likely recognise that it does nothing and not generate code. If the behaviour changes you are misunderstanding something else. |
_________________
|
| |
|
|
|
|
|
Posted: Mar 14, 2012 - 12:56 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
I don't know how I can explain it better,
When initialising the ADC you have to set the control registers
like ADMUX
I had it set as ADMUX |= 1<<REFS0
and the code works fine, displays conversion results as predicted
however
When Later I though to maker it more clear to readers
I set ADMUX |= 0<<REFS1 | 1<<REFS0;
The prog still works but there is a delay on the conversion results, it will display a Zero Value and then update after just over a second.
All that just because I put 0<<REFS1,
I checked all my code every last bit of it and found that removing the 0<<REFS1, fixed my problem.
Bear in mind REFS1 is assigned to Zero by default,
and the initialisation was not in a loop.
Strange, I think it is a compiler Issue. |
|
|
| |
|
|
|
|
|
Posted: Mar 14, 2012 - 01:46 PM |
|


Joined: Feb 19, 2001
Posts: 25891
Location: Wisconsin USA
|
|
|
Quote:
I set ADMUX |= 0<<REFS1 | 1<<REFS0;
I cannot see the fascination that people seem to have with |= and AVR I/O registers. In particular with ADMUX we see threads over and over with garbage ADMUX.
Is it >>that<< hard to just rebuild it each time? Pseudo code when getting ready for a conversion:
"ADMUX = (reference selection) | (channel selection); "
Now indeed there may be ADLAR or other special-purpose in there. The point is with an AVR app it is rare (at least for my apps) to have more than one reference V for an app.
Code:
// VREF
// ====
// Note that in ADMUX, bit 7 is REFS1; bit 6 is REFS0; bit 4 is REFS2.
// REFS2:0 ADMUX Mask Description
// ------- ---------- -----------
// 0 0x00 Use Vcc as Aref
// 1 0x40 External AREF on PB0
// 2 0x80 Internal 1.1V bandgap
// 3 n/a
// 6 0x90 Internal 2.56V w/ capacitor on PB0
// 7 0xd0 Internal 2.56V; no connection to PB0
#define ADC_VREF_VCC 0x00
#define ADC_VREF_AREF 0x40
#define ADC_VREF_BG 0x80
#define ADC_VREF_INTCAP 0x90
#define ADC_VREF_INT 0xd0
#define ADC_VREF_TYPE ADC_VREF_VCC
...
// **************************************************************************
// *
// * R E A D _ A D C
// *
// **************************************************************************
//
// Read the AD conversion result
unsigned int read_adc (unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
No |= or &=~ in sight. Short/fast code sequence and no RMW possible issues. Plain to read.
Quote:
All that just because I put 0<<REFS1,
I checked all my code every last bit of it and found that removing the 0<<REFS1, fixed my problem.
...
Strange, I think it is a compiler Issue.
Let's see the generated code fragments. Then we don't have to "think". |
|
|
| |
|
|
|
|
|
Posted: Mar 14, 2012 - 02:30 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
I set ADMUX |= 0<<REFS1 | 1<<REFS0;
What is the order of precendence of those operators? (personally I don'tknow and would have to look it up - using parentheses avoids a lot of manual reading!)
OK, I couldn't help myself so I had to check:
Code:
ADMUX |= 1<<REFS0;
3c: 3e 9a sbi 0x07, 6 ; 7
ADMUX |= 0<<REFS1 | 1<<REFS0;
3e: 3e 9a sbi 0x07, 6 ; 7
Those lines are logically identical so cannot possibly have changed the program behaviour.
Oh and just to check this is the dog's breakfast you get fro -O0:
Code:
ADMUX |= 1<<REFS0;
74: a7 e2 ldi r26, 0x27 ; 39
76: b0 e0 ldi r27, 0x00 ; 0
78: e7 e2 ldi r30, 0x27 ; 39
7a: f0 e0 ldi r31, 0x00 ; 0
7c: 80 81 ld r24, Z
7e: 80 64 ori r24, 0x40 ; 64
80: 8c 93 st X, r24
ADMUX |= 0<<REFS1 | 1<<REFS0;
82: a7 e2 ldi r26, 0x27 ; 39
84: b0 e0 ldi r27, 0x00 ; 0
86: e7 e2 ldi r30, 0x27 ; 39
88: f0 e0 ldi r31, 0x00 ; 0
8a: 80 81 ld r24, Z
8c: 80 64 ori r24, 0x40 ; 64
8e: 8c 93 st X, r24
But still identical. |
_________________
|
| |
|
|
|
|
|
Posted: Mar 14, 2012 - 08:12 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Sorry they had parentheses around them like (0<<REFS1)|(1<<REFS0)
If you saying they are identical then are really don't know.
Try 01 optimization, with avr studio 5.1 |
|
|
| |
|
|
|
|
|
Posted: Mar 18, 2012 - 04:15 AM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
Hello,
I need help with serial interface USART0, can anyone show me how to initiliase with 1284p using internal 8mhz oscilator? |
|
|
| |
|
|
|
|
|
Posted: Mar 18, 2012 - 01:05 PM |
|


Joined: Jul 18, 2005
Posts: 62234
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
There are articles about this in the tutorial forum. It can be as simply as setting UBRR and the TXEN/RXEn bits and then for transmit waiting for UDRE and flling UDR and for reception waiting for RXC and reading UDR.
Using the internal oscillator is not a great idea - I'd pay $0.25 for a crystal if I were you to rule out one of the likely problems you'll face. |
_________________
|
| |
|
|
|
|
|
Posted: Mar 18, 2012 - 01:33 PM |
|

Joined: Feb 14, 2012
Posts: 60
|
|
I tried to simulate the serial port using VSPE and Proteus but it does not work.
I just want to test it using a simple program that transmits a string of characters to the pc.
Can't find a code for the 1284p. I even tried the code from the usart tutorial and it didn't work. |
|
|
| |
|
|
|
|
|
Posted: Mar 18, 2012 - 01:56 PM |
|

Joined: Feb 12, 2005
Posts: 16275
Location: Wormshill, England
|
|
We are very kind and helpful to those students that show some effort.
The USART of a mega1284P is the same as the mega88/168/328 used in the Arduino or the 164/324/644/1284 family or most modern AVRs. You can see many examples.
It is slightly different to the old mega8/16/32 chips. Compare the differences by looking at URSEL in the mega32 data sheet.
But you can use <util/setbaud.h>.
Look it up in the Studio Help->avr-libc.a docs
Show what effort you have made.
Describe your symptoms / problems.
Ask specific questions.
There is no problem in students posting their code and asking for help. If it means that you understand how and why anything works, not only does your project succeed but you can do the next one yourself
David. |
|
|
| |
|
|
|
|
|
Posted: Mar 18, 2012 - 05:12 PM |
|


Joined: Sep 04, 2002
Posts: 21253
Location: Orlando Florida
|
|
| If you ask several AVR programmers what steps will get the serial port talking, I bet most would say: 1)write a function to init the uart. Name it void inituart(void); 2)Write a function to send a char parameter to the uart. Name it void putchar(char c); 3) Write a function to return a char from the uart. Name it char getchar(void); 4)Write a main program that calls inituart() then calls putchar('U'); in a loop. Plug the AVR RS232 transmit pin into your PC RS232 receive pin, and see if you can read the UUUUUUUU from the AVR. If you can't then the 8MHz RC oscillator in the AVR is not within the required 2% accuracy for serial comms. It is usually within 10%, but if it is greter than 2%, I'd expect to see garbage on the serial port. Perform these steps and report your results. Hurry. This is urgent. You have a dozen engineers with 30 years of experience on 5 continents on planet earth waiting for your next message. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Mar 18, 2012 - 05:28 PM |
|

Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca
|
|
| OP's saying the simulation's not working, it seems to me since the sentence before it not working was about Proteus . Try it on the hardware, the tutorial UART code WORKS ( after adjusting UART registers for a different MCU than in the tut. ) . |
_________________ 1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
|
| |
|
|
|
|
|
Posted: Mar 18, 2012 - 06:31 PM |
|


Joined: Sep 04, 2002
Posts: 21253
Location: Orlando Florida
|
|
| Yo Jolly... your problem is either hardware or software. Post a picture of the mega1284p board you are using. We will look to see if it has an RS232 voltage level translator chip on it like a MAX232. Your multimeter should see -7V sitting on the pin2 from the AVR DB9. The PC DB9 should have -7V on pin3. These are the tx lines passing each other on their way to and from the AVR and PC. It won't work if you try to make PC tx talk to AVR tx. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|