Skip to main content
deleted 1 character in body
Source Link
gre_gor
  • 1.7k
  • 4
  • 18
  • 30

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, and I had to comment out a section once to use my own ISR with Timer 3 on a 32u4, because no matter where or how I set it, the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with your settings.

You will need go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/, and under that directory you need to find file wiring.c. This file contains all the setup of the timers for PWM and the millis() or or micros() functions.

Go to line 342. Located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

Here you can place another #if defined() macro around this, resulting in:

#if !defined(doNotSetTimer5)

  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif

#endif

Now when you want to use your custom settings, you will put the following at the top of your .ino file:

#define doNotSetTimer5
#include <wiring.c>

That does not block the Arduino environment from setting up Timer 5 when compiled with other code, but only when you want to use custom settings (changed because of @Gerbens@Gerben's suggestion). When you change these settings you will lose PWM on 3 pins: 44 45 46. But you will be able to make use of setting your own PWM up or a CTC ISR().

This doesn't mess with anything else and is the easiest way to do it.

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, and I had to comment out a section once to use my own ISR with Timer 3 on a 32u4, because no matter where or how I set it, the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with your settings.

You will need go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/, and under that directory you need to find file wiring.c. This file contains all the setup of the timers for PWM and the millis() or micros() functions.

Go to line 342. Located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

Here you can place another #if defined() macro around this, resulting in:

#if !defined(doNotSetTimer5)

  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif

#endif

Now when you want to use your custom settings, you will put the following at the top of your .ino file:

#define doNotSetTimer5
#include <wiring.c>

That does not block the Arduino environment from setting up Timer 5 when compiled with other code, but only when you want to use custom settings (changed because of @Gerbens suggestion). When you change these settings you will lose PWM on 3 pins: 44 45 46. But you will be able to make use of setting your own PWM up or a CTC ISR().

This doesn't mess with anything else and is the easiest way to do it.

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, and I had to comment out a section once to use my own ISR with Timer 3 on a 32u4, because no matter where or how I set it, the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with your settings.

You will need go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/, and under that directory you need to find file wiring.c. This file contains all the setup of the timers for PWM and the millis() or micros() functions.

Go to line 342. Located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

Here you can place another #if defined() macro around this, resulting in:

#if !defined(doNotSetTimer5)

  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif

#endif

Now when you want to use your custom settings, you will put the following at the top of your .ino file:

#define doNotSetTimer5
#include <wiring.c>

That does not block the Arduino environment from setting up Timer 5 when compiled with other code, but only when you want to use custom settings (changed because of @Gerben's suggestion). When you change these settings you will lose PWM on 3 pins: 44 45 46. But you will be able to make use of setting your own PWM up or a CTC ISR().

This doesn't mess with anything else and is the easiest way to do it.

Copy edited (e.g. ref. <https://en.wiktionary.org/wiki/setup#Noun> and <https://en.wiktionary.org/wiki/lose#Verb>).
Source Link

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, and I had to comment out a section once to use my own ISR with Timer 3 3 on a 32u4, because no matter where or how I set it, the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with youyour settings.

What youYou will need to do is go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/, and under that directory you need to find file wiring.c thus. This file contains all the set upsetup of the timers for PWM and the millis() or micros() functions.

Go to line 342, located. Located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

WhatHere you can do here is place another #if defined() macro around this, resulting in:

#if !defined(doNotSetTimer5) 

  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif 

#endif

Now when you want to use your custom settings, you will put the following at the top of your ino.ino file:

#define doNotSetTimer5
#include <wiring.c>

That does not block the Arduino environment from setting up Timer 5 5 when compiled with other code, but only when you want to use custom settings  (changed because of @Gerbens suggestion). When you change these settings you will looselose PWM on 3 pins: 44 45 46. But you will be able to make use of setting your own PWM up or a CTC ISR().

This doesn't mess with anything else and is the easiest way to do it.

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, I had to comment out a section once to use my own ISR with Timer 3 on a 32u4 because no matter where or how I set it the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with you settings.

What you will need to do is go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/ under that directory you need to find wiring.c thus file contains all the set up of the timers for PWM and the millis() or micros().

Go to line 342, located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

What you can do here is place another #if defined() macro around this resulting in:

#if !defined(doNotSetTimer5)
  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif
#endif

Now when you want to use your custom settings, you will put the following at the top of your ino file:

#define doNotSetTimer5
#include <wiring.c>

That does not block the Arduino environment from setting up Timer 5 when compiled with other code but only when you want to use custom settings(changed because of @Gerbens suggestion). When you change these settings you will loose PWM on 3 pins: 44 45 46. But be able to make use of setting your own PWM up or a CTC ISR().

This doesn't mess anything else and is the easiest way to do it.

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, and I had to comment out a section once to use my own ISR with Timer 3 on a 32u4, because no matter where or how I set it, the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with your settings.

You will need go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/, and under that directory you need to find file wiring.c. This file contains all the setup of the timers for PWM and the millis() or micros() functions.

Go to line 342. Located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

Here you can place another #if defined() macro around this, resulting in:

#if !defined(doNotSetTimer5) 

  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif 

#endif

Now when you want to use your custom settings, you will put the following at the top of your .ino file:

#define doNotSetTimer5
#include <wiring.c>

That does not block the Arduino environment from setting up Timer 5 when compiled with other code, but only when you want to use custom settings  (changed because of @Gerbens suggestion). When you change these settings you will lose PWM on 3 pins: 44 45 46. But you will be able to make use of setting your own PWM up or a CTC ISR().

This doesn't mess with anything else and is the easiest way to do it.

edit per gerbans suggestion to make it not break Arduino ide; added 51 characters in body
Source Link
RSM
  • 1.5k
  • 1
  • 11
  • 27

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, I had to comment out a section once to use my own ISR with Timer 3 on a 32u4 because no matter where or how I set it the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with you settings.

What you will need to do is go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/ under that directory you need to find wiring.c thus file contains all the set up of the timers for PWM and the millis() or micros().

Go to line 342, located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

What you can do here is place another #if defined() macro around this resulting in:

#if !defined(UsePWMdoNotSetTimer5)
  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif
#endif

Now what thatwhen you want to use your custom settings, you will put the following at the top of your ino file:

#define doNotSetTimer5
#include <wiring.c>

That does isnot block the Arduino environment from changing yoursetting up Timer 5 when compiled with other code but only when you want to use custom settings(changed because of @Gerbens suggestion). Now whenWhen you change these settings you will loose PWM on 3 pins: 44 45 46. All you need to doBut be able to make use those pins with PWM is to do this at the beginning of you .into files:

#define UsePWM
#include <wiring.c>
…

That will make thesetting your own PWM functionalup or a CTC ISR().

This doesn't mess anything else and is the easiest way to do it.

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, I had to comment out a section once to use my own ISR with Timer 3 on a 32u4 because no matter where or how I set it the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with you settings.

What you will need to do is go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/ under that directory you need to find wiring.c thus file contains all the set up of the timers for PWM and the millis() or micros().

Go to line 342, located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

What you can do here is place another #if defined() macro around this resulting in:

#if defined(UsePWM)
  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif
#endif

Now what that does is block the Arduino environment from changing your settings. Now when you change these settings you will loose PWM on 3 pins: 44 45 46. All you need to do to use those pins with PWM is to do this at the beginning of you .into files:

#define UsePWM
#include <wiring.c>
…

That will make the PWM functional.

This doesn't mess anything else and is the easiest way to do it.

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, I had to comment out a section once to use my own ISR with Timer 3 on a 32u4 because no matter where or how I set it the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with you settings.

What you will need to do is go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/ under that directory you need to find wiring.c thus file contains all the set up of the timers for PWM and the millis() or micros().

Go to line 342, located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

What you can do here is place another #if defined() macro around this resulting in:

#if !defined(doNotSetTimer5)
  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif
#endif

Now when you want to use your custom settings, you will put the following at the top of your ino file:

#define doNotSetTimer5
#include <wiring.c>

That does not block the Arduino environment from setting up Timer 5 when compiled with other code but only when you want to use custom settings(changed because of @Gerbens suggestion). When you change these settings you will loose PWM on 3 pins: 44 45 46. But be able to make use of setting your own PWM up or a CTC ISR().

This doesn't mess anything else and is the easiest way to do it.

Source Link
RSM
  • 1.5k
  • 1
  • 11
  • 27
Loading