timer0 and PWM

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times

timer0 and PWM

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post 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.
Last edited by Benj on Thu Jan 10, 2008 10:42 am, edited 1 time in total.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Post 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.

Post Reply