split timer0 and timer2 initialization. Move timer2 init early
This commit is contained in:
parent
20c3f4cb77
commit
698499f00d
@ -1013,6 +1013,8 @@ static void w25x20cl_err_msg()
|
|||||||
// are initialized by the main() routine provided by the Arduino framework.
|
// are initialized by the main() routine provided by the Arduino framework.
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
timer2_init(); // enables functional millis
|
||||||
|
|
||||||
mmu_init();
|
mmu_init();
|
||||||
|
|
||||||
ultralcd_init();
|
ultralcd_init();
|
||||||
|
@ -1124,7 +1124,10 @@ void tp_init()
|
|||||||
|
|
||||||
adc_init();
|
adc_init();
|
||||||
|
|
||||||
timer0_init();
|
timer0_init(); //enables the heatbed timer.
|
||||||
|
|
||||||
|
// timer2 already enabled earlier in the code
|
||||||
|
// now enable the COMPB temperature interrupt
|
||||||
OCR2B = 128;
|
OCR2B = 128;
|
||||||
TIMSK2 |= (1<<OCIE2B);
|
TIMSK2 |= (1<<OCIE2B);
|
||||||
|
|
||||||
|
@ -9,13 +9,11 @@
|
|||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
void timer0_init(void)
|
void timer0_init(void)
|
||||||
{
|
{
|
||||||
//save sreg
|
CRITICAL_SECTION_START;
|
||||||
uint8_t _sreg = SREG;
|
|
||||||
//disable interrupts for sure
|
|
||||||
cli();
|
|
||||||
|
|
||||||
TCNT0 = 0;
|
TCNT0 = 0;
|
||||||
// Fast PWM duty (0-255).
|
// Fast PWM duty (0-255).
|
||||||
@ -25,7 +23,14 @@ void timer0_init(void)
|
|||||||
TCCR0A = (1 << WGM01) | (1 << WGM00) | (1 << COM0B1) | (1 << COM0B0);
|
TCCR0A = (1 << WGM01) | (1 << WGM00) | (1 << COM0B1) | (1 << COM0B0);
|
||||||
TCCR0B = (1 << CS01); // CLK/8 prescaling
|
TCCR0B = (1 << CS01); // CLK/8 prescaling
|
||||||
TIMSK0 |= (1 << TOIE0); // enable timer overflow interrupt
|
TIMSK0 |= (1 << TOIE0); // enable timer overflow interrupt
|
||||||
|
|
||||||
|
CRITICAL_SECTION_END;
|
||||||
|
}
|
||||||
|
|
||||||
|
void timer2_init(void)
|
||||||
|
{
|
||||||
|
CRITICAL_SECTION_START;
|
||||||
|
|
||||||
// Everything, that used to be on timer0 was moved to timer2 (delay, beeping, millis etc.)
|
// Everything, that used to be on timer0 was moved to timer2 (delay, beeping, millis etc.)
|
||||||
//setup timer2
|
//setup timer2
|
||||||
TCCR2A = 0x00; //COM_A-B=00, WGM_0-1=00
|
TCCR2A = 0x00; //COM_A-B=00, WGM_0-1=00
|
||||||
@ -36,9 +41,8 @@ void timer0_init(void)
|
|||||||
TIMSK2 &= ~(1<<OCIE2B);
|
TIMSK2 &= ~(1<<OCIE2B);
|
||||||
//set timer2 OCR registers (OCRB interrupt generated 0.5ms after OVF interrupt)
|
//set timer2 OCR registers (OCRB interrupt generated 0.5ms after OVF interrupt)
|
||||||
OCR2A = 0;
|
OCR2A = 0;
|
||||||
OCR2B = 128;
|
|
||||||
//restore sreg (enable interrupts)
|
CRITICAL_SECTION_END;
|
||||||
SREG = _sreg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,9 @@ extern "C" {
|
|||||||
///! Initializes TIMER0 for fast PWM mode-driven bed heating
|
///! Initializes TIMER0 for fast PWM mode-driven bed heating
|
||||||
extern void timer0_init(void);
|
extern void timer0_init(void);
|
||||||
|
|
||||||
|
///! Initializes TIMER2 for time keeping and temperature interrupt
|
||||||
|
extern void timer2_init(void);
|
||||||
|
|
||||||
///! Reimplemented original millis() using timer2
|
///! Reimplemented original millis() using timer2
|
||||||
extern unsigned long millis2(void);
|
extern unsigned long millis2(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user