ATMega323 port for ATMega16L

nobody wrote on Thursday, May 26, 2005:

Hi I use a STK500 board with ATMega16L processor. I have tried the demo program with this microcontroller but nothing works. It feels like the processor is not switched on at all. (I mjean no visual indication on leds connected to portb or activity on the serial port.)

I know the processor is fine as my program using the serial port works fine. I have changed the value of configTOTAL_HEAP_SIZE from 1500 to 800 to accomodate for the 1kByte of SRAM in the mega16. Are there any other changes i need to make? I am running the processor at 8MHz.

nobody wrote on Thursday, May 26, 2005:

The demo application uses all the heap - so if you have reduced the heap size it is likely that the scheduler is running out of memory and not starting.

Try reducing the number of tasks that are created - in FreeRTOS/Demo/AVR_ATMega323_WinAVR/main.c comment out the lines:

vStartIntegerMathsTasks()
vAltStartComTestTasks()
vStartPolledQueueTasks()
xTaskCreate( vErrorChecks, …

This should just leave the LED flash tasks so you can see if anything is running.

nobody wrote on Thursday, May 26, 2005:

Thanks it works now! :slight_smile: But i am surprised at the number of tasks that can run in parallel with 1KByte of RAM!

Next i plan to use the ATmega128 with 4KBytes of RAM. How many tasks can i run in parallel assuming default default default stack size and Global variables not exceeding 200 bytes?

rtel wrote on Thursday, May 26, 2005:

Take a look at this page:

it should give you a good idea of the requirements.  The numbers actually come from the AVR port, but prior to the V3.0.0 release.  V3.0.0 uses a bit less RAM but only very slightly.

Regards.

nobody wrote on Thursday, May 26, 2005:

Also… I would like to know if anyone has ever overclocked these processors (the mega128)? What are the effects of doing so?

nobody wrote on Thursday, May 26, 2005:

That sounds fun :slight_smile:

I have on occassion overclocked various devices and bus systems and normally it still works.  This is of coarse using the device out of specification so would not be a good idea for a commercial product. 

nobody wrote on Friday, May 27, 2005:

My current setup is like this…

portSHORT main( void )
{
//    prvIncrementResetCount();

    /* Setup the LED’s for output. */
    vParTestInitialise();

//    vStartIntegerMathTasks( tskIDLE_PRIORITY );
//    vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
    vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
//    vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );

//    xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );

    /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
    as 1 in portmacro.h.  To use the cooperative scheduler define
    configUSE_PREEMPTION as 0. */
    vTaskStartScheduler();

    return 0;
}

flash.c has the declaration
#define ledNUMBER_OF_LEDS    ( 3 )

While reducing this number is ok, increasing it to even 4 stalls the microcontroller. With this number 3 and my current main config, how many threads are running in parallel?

My guess is it is 3 for the flasing leds and 1 for the idle task. I have set the heap size to 750.

nobody wrote on Friday, May 27, 2005:

Yes - 4 tasks will be running.  Can you run your code in the AVR Studio simulator?  If so then step into the vTaskStartScheduler() function and see what happens.  When the idle task is created you will be able to see how much RAM is left.  Alternatively try filling the entire heap with a known value - then you will also be able to see in the simulator how much is left.

nobody wrote on Friday, May 27, 2005:

Try uncommenting the vStartIntegerMathTasks line.  This will start just 1 extra "known good" task.

nobody wrote on Saturday, May 28, 2005:

I do not have access to avr studio as i work on linux. AFAIK the flash led task does not use any additional memory consuming functions yet teh device fails to add any more than 3.

I have tried uncommenting the vStartIntegerMathTasks task but the system does not work unless i reduce the number of led flash tasks from 3 to 1. Even reducing it to 2 does not help.

rtel wrote on Sunday, May 29, 2005:

I have tried running the project in the simulator with:

+ Stack set to 700
+ Integer math tasks
+ 3 flash tasks
+ no optimisation

and find that everything executes with no problem - and that following the creation of all the tasks (including the idle task) there are 95 bytes of stack remaining.  At least enough to create another task.

Have you remembered to change the line:

MCU = atmega323

in the makefile to the correct CPU being used?  Maybe there is a linker problem.

Regards.

nobody wrote on Sunday, May 29, 2005:

Yes i have. The changes i have made from the demo downloaded to my setup include making

MCU = atmega16

in the makefile and,

#define configTOTAL_HEAP_SIZE        ( (size_t ) ( 750 ) )

in FreeRTOSConfig.h

I am using the avr tool chain on debian linux, downloaded from the debian repositories.

rtel wrote on Sunday, May 29, 2005:

I just remembered that I had an ATMega16 lying around so gave it a go.

Having made the two changes (heap size and processor definition) I find that the program still runs with no problems, even with vStartIntegerMathTasks() uncommented.

To try and get it to go wrong I have tried full optimisation, no optimisation, with debug info and without debug info.  It is happy with all these configurations.

Which version of GCC do your Linux tools use?  WinAVR currently uses V3.4.3.  I have used older versions also though.

Other than commenting out some of the tasks, the cpu definition and the heap size definition - have you changed any thing else?

nobody wrote on Sunday, May 29, 2005:

Now that you have mentioned, i decided unpack my downloaded FreeRTOS again check and these are the changes i made.

In FreeRTOS.h
changed ProjDefs.h to projdefs.h

In FreeRTOSConfig.h made heap size 750

In the makefile made MCU = atmega16 and setup avrdude
AVRDUDE_PROGRAMMER = stk500v2
AVRDUDE_PORT = /dev/ttyS0

These are all the changes i made. Compiled and flashed the micro and it does not execute.

I am using avr-gcc v3.4.3 and avr-libc v1.2.3