Forum: Mikrocontroller und Digitale Elektronik 16Bit Access beim Atmega 8535


von Mike M. (mikeii)


Lesenswert?

Hallo,
könnte mir mal jemand auf die Sprünge beim Atmega 8535 helfen?

Ich verstehe das Datenblatt nicht so recht.

Ich möchte das Register OCR1A beschreiben.

Auszug:

The 16-bit register must be byte accessed using two read or
write operations. Each 16-bit timer has a single 8-bit register for 
temporary storing of the
high byte of the 16-bit access. The same temporary register is shared 
between all 16-bit
registers within each 16-bit timer. Accessing the low byte triggers the 
16-bit read or write
operation. When the low byte of a 16-bit register is written by the CPU, 
the high byte
stored in the temporary register, and the low byte written are both 
copied into the 16-bit
register in the same clock cycle.


D.h. ich soll in das OCR1AH mein Highbyte schreiben
und dann in das OCR1AL mein Lowbyte?

Wenn ich das mache, funktioniert es einfach nicht. Es gibt ganz einfach 
einen Überlauf, als ob ich nur 8 Byte schreiben würde

    OCR1AH  = timevalue>>8;
    OCR1AL  = timevalue&0xFF;


Wie geht das richtig?

von da1l6 (Gast)


Lesenswert?

So:

OCR1A  = timevalue

Der Compiler macht den Rest.

da1l6

von Mike M. (mikeii)


Lesenswert?

Dann mache ich irgendwas falsch :(

1
void activate_timer_long(uint16_t timevalue){
2
    //Prescaler 1024
3
    TCCR1B = (1<<CS10) | (1<<CS12) | (1<<WGM12);  
4
    OCR1A  = timevalue;
5
}

und als Timevalue nehme ich vom ADC eine Spannung zwischen 0 und 5 V.
Die Spannung kommt von einem Poti.
Wenn ich das Poti rumdrehe, dann habe ich 3 Überläufe, also 4 "Bereiche"

Der ADC ist mit 10 Bit, also kommt das gut hin mit den 4 Bereichen,
da der Wertebereich auch 4 mal größer ist.

Hier ein kurzer Codeauszug:
1
uint16_t readADC(uint8_t channel)
2
{
3
4
    ADMUX = channel;
5
    // Ref:5V 
6
    ADMUX |= (1<<REFS0);  
7
8
    ADCSRA |= (1<<ADSC);
9
    while ( ADCSRA & (1<<ADSC) );
10
11
12
    return ADCW;
13
}
1
    activate_timer_long(readADC(0));

von Mike M. (mikeii)


Lesenswert?

Oh jetzt wirds peinlich... hatte den Wert des ADC in einer 8 Bit 
Variable zwischengespeichert...

von Marian (phiarc) Benutzerseite


Lesenswert?

Solche Fehler kennen wir alle :-)

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.