[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] allocation of constant table

From: ericw
Subject: Re: [avr-gcc-list] allocation of constant table
Date: Tue, 30 Aug 2005 15:19:42 -0600
User-agent: Internet Messaging Program (IMP) 3.2.3

Quoting juan antonio jimenez martinez <address@hidden>:

> OK, I have my table in the address that I want, but now I have another
> detail, I have been trying to read back those values to update the OCR2 for
> the Fast PWM mode of timer2, and I do it in this way:
> #include <avr/io.h>
> #include <avr/interrupt.h> //para sei(); y cli();
> #include <avr/signal.h> // para las rutinas SIGNAL(){};
> //#include <avr/pgmspace.h>
> #include "./sampler.txt"// my file with 1024 samples of data
> //the array is declared as
> // __attribute__((section (".flashtable"))) unsigned char tabla[1024]={0x78,
> ....};
> // in the address 0x400 of the program space
> volatile unsigned int i=0;
> /************************************************************
> Interrupcion del PWM
> *************************************************************/
>       OCR2 = table[i];//actualiza valor de arreglo
>       i++;
>       if(i==1023) i=0;
> }
> int main(void){
>       cli();
>       DDRB = (1<<PB3);
>     TCCR2 = (1<<WGM21)|(1<<WGM20)|(1<<COM21)|(1<<CS22)|(1<<CS21);
>       //modo FAST PWM, prende OC2 cuando es igual al valor comparado, reloj
>       //preescalamiento de 256
>       //OCR2 = 51;//para PWM del 80% =204,20%=51
>       TIFR = TIFR|(1<<OCIE2);//habilita interrupcion por comparacion en timer2
>       sei();
>       //sbi(PORTB,PB3);
>       for(;;){}
> }
> please can any one give me some clues to read and update the value in the
> OCR2 register..

1. Make sure you are using the correct definition. In
SIGNAL(SIG_OUTPUT_COMPARE2) you assign from the array *table*, yet you define
the array with the identifier *tabla*. I hope that this is just an email typo.

2. You should be using the pgm_read_byte() macros to read data that is stored in
Flash. See the avr-libc user manual in the Program Space String Utilities


This message was sent using IMP, the Internet Messaging Program.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]