Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with PWM output in some instances #1

Open
unforgiven512 opened this issue Feb 16, 2018 · 0 comments
Open

Incompatible with PWM output in some instances #1

unforgiven512 opened this issue Feb 16, 2018 · 0 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@unforgiven512
Copy link
Owner

Due to this implementation's use of the SparkIntervalTimer library, in certain instances, this can cause PWM functionality to become inoperable on certain groups of pins on the Photon (NOTE: this may be true for other Particle devices, as well; I only have a Photon for testing), depending on which hardware timer is allocated to the timer_isr() function at the time of instantiation.

When the timer_isr() function is instantiated, the "dynamic timer allocation" feature will cause the timer to use interrupts generated by one of the following timers on the Photon:

  • TIM3
  • TIM4
  • TIM5
  • TIM6
  • TIM7

Now, this is all and well, however, the Photon uses the timers TIM3, TIM4, and TIM5 for the generation of PWM signals on various pins:

PIN TIMER NOTES
D0 TIM4
D1 TIM4
D2 TIM3
D3 TIM3
A4 TIM3
A5 TIM3
WKP TIM5

Timer TIM6 and TIM7 are not (directly) connected to any I/O pins on the Photon, so it would be preferential to use these two timers by directly specifiying one of the two during the instantiation of the IntervalTimer object.

However, as both this library (IRRemote) and the SparkIntervalTimer library support both the Core and Photon as target platforms, it would not be wise to simply assume that TIM6 or TIM7 is available.

The Core has TIM2, TIM3, and TIM4 available, all of which as associated with PWM output pins, so at least some of the PWM functionality will be lost. Unfortunately, my Core is no longer working (the CC3000 WiFi module has failed solder connections, causing the device to remain in an unbootable state), so I am unable to perform any testing for this target.

Platform detection can be performed via conditional preprocessor directives:

#if defined(STM32F10X_MD) || !defined(PLATFORM_ID)
#define PIO_PLATFORM_CORE
#elif defined(STM32F2XX) && defined(PLATFORM_ID)
#define PIO_PLATFORM_PHOTON
#else
#error "--- ERROR: Device is not supported by this library. Only Particle Core and Particle Photon are supported. ---"
#endif /* <PLATFORM DETECTION> */

An ideal solution may be to allow the user to specify their preferred timer (in any case), use automatic allocation on the Core target, and (if not explicitly selected), use either TIM6 or TIM7 on the Photon target. I am currently unsure if TIM6 or TIM7 are used elsewhere; if they are used elsewhere, it may be ideal to select one based on some type of "priority" scheme.

@unforgiven512 unforgiven512 self-assigned this Feb 16, 2018
@unforgiven512 unforgiven512 added bug Something isn't working enhancement New feature or request good first issue Good for newcomers labels Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant