Page 1 of 1

timer0 and PWM

Posted: Wed Jan 09, 2008 6:22 pm
by Ron
Hi,

I want to use timer0 to bit bang digital outputs (PWM) for controlling LEDs and small servo motors. In theory it should work based on everything I have read on the www.

My questions are:

1) If I am reading/writing EEPROM addresses and the Tmr0 code begins to solve, will this interuption corrupt the eerpom read/write command and/or information?

2) Same question for analog reads and writes, same for other component macros.

Thanks

Ron

Posted: Thu Jan 10, 2008 10:42 am
by Benj
Hello Ron

In answer to your questions.

1) The EEPROM write routine disables the interrupts before the critical part of the code, This means that your timer interrupt may come slightly late if you are writing to the EEPROM at that particular moment. This will not affect the Timer0 count value and it should interrupt again the next time as if there hadnt been any delay.

2) EEPROM writes are the only totally critical pieces of code. Other code can normally be interrupted without causing adverse affects. The only problem would be if you had taken an ADC sample and then an interrut occurred, Then inside the interrupt you sample a different analogue channel. Obviously this would corrupt the original data so if possible leave things like ADC sample outside of the interrupt routine.

Posted: Thu Jan 10, 2008 10:42 am
by Sean
Hello Ron,

The use of the timer 0 interrupt should not significantly affect any of the other functions if the standard interrupt service rules are observed:
  • Keep the service routines short.
    Take care when modifying registers and global variables that may be being used in the main program.
The macro that writes to the internal EEPROM temporarily disables interrupts during a critical part of the process - as recommended by the manufacturer.

Interrupt services will not affect the timing of the adc, uart, spi etc. as these are hardware controlled.