Jason:
Can anyone tell me how to translate I/O pins on the STM32F405 to PWM channels. I am using pins 41 and 42 which seem to be TIM1_CH1 and TIM1_CH2 respectively.
PWM pwmLEDb;
PWM pwmLEDc;
pwmLEDb = new PWM(Cpu.PWMChannel.PWM_1, 500, 100, false);
pwmLEDc = new PWM(Cpu.PWMChannel.PWM_2, 500, 100, false);
pwmLEDb.Start();
pwmLEDc.Start();
Using the code above nothing happens to the LEDs on these two pins.
What am I doing wrong?
Re: “Can anyone tell me how to translate I/O pins on the STM32F405 to PWM channels”
The Datasheet is wrong. Its posted in the specs section about the error in the Datasheet and Pin Maps but I cant find it now. Site Changes…
EDIT: Found it:
[b]
Known Issues
Hardware
On boards version 1.1, sockets 5 and 6 are mislabeled. These sockets have PWM feature so they should also include P socket type.
[/b]
Page removed but I had a saved copy…
Where PWM is shown to be X5 and X6 on the Datasheet, its incorrect and its actually on X3 and X4, Pins 7, 8 and 9 See below.
I have started some code on the register access to configure PMW, see: https://www.ghielectronics.com/community/codeshare/entry/931
Also I wonder if this may help some, I wrote a helper class:
public sealed class PWMChannel : PWM
{
#region PWM Pin Outs...
// X3...
// Pin 7
// Pin 8
// Pin 9
// X4...
// Pin 7
// Pin 8
// Pin 9
#endregion
#region Below does not work...
// X5...
// Pin 7
// Pin 8
// Pin 9
// X6...
// Pin 7
// Pin 8
// Pin 9
// X8...
// Pin 7
#endregion
/////////////////////////////////////////////////////////////////////////
// See for more information: //
// http://msdn.microsoft.com/en-us/library/jj633523(v=vs.102).aspx //
// http://msdn.microsoft.com/en-us/library/jj646655(v=vs.102).aspx //
/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// References the Library: "Microsoft.SPOT.Hardware.PWM" //
// Add using statement: using Microsoft.SPOT.Hardware; //
///////////////////////////////////////////////////////////////
/// <summary>
/// Get or Set PWMChannel's Frequency using the inhetited member 'Frequency'...
/// </summary>
private uint ChannelFrequency
{
get { return (uint)Frequency; }
set { Frequency = value; }
}
/// <summary>
/// Get or Set the PWMChannel's Duty Cycle using the inhetited member 'DutyCycle'...
/// </summary>
private double ChannelDutyCycle
{
get { return DutyCycle; }
set { DutyCycle = value; }
}
/// <summary>
/// Channel 1 - Set for output on Pins 8 on X3.
/// </summary>
public static PWMChannel Channel_1 = new PWMChannel(Cpu.PWMChannel.PWM_1, 10, 0, GlobalVariable.InvertChannel_1);
/// <summary>
/// Channel 2 - Set for output on Pins 9 on X3.
/// </summary>
public static PWMChannel Channel_2 = new PWMChannel(Cpu.PWMChannel.PWM_2, 10, 0, GlobalVariable.InvertChannel_2);
/// <summary>
/// Channel 3 - Set for output on Pins 8 on X4.
/// </summary>
public static PWMChannel Channel_3 = new PWMChannel(Cpu.PWMChannel.PWM_3, 10, 0, GlobalVariable.InvertChannel_3);
/// <summary>
/// Channel 4 - Set for output on Pins 9 on X4.
/// </summary>
public static PWMChannel Channel_4 = new PWMChannel(Cpu.PWMChannel.PWM_5, 10, 0, GlobalVariable.InvertChannel_4);
/// <summary>
/// Stop Set Parameters and Start PWM on the desired Configuration...
/// </summary>
/// <param name="frequency_Hz">The Frequency in Hertz</param>
/// <param name="dutyCycle">Duty Cycle expressed in Percentage EG: 0.5 gives 50% Duty Cycle of the Frequency</param>
/// <param name="invert">Inverts the Output Pin</param>
public void Configure(uint frequency_Hz, double dutyCycle)
{
this.Stop();
ChannelFrequency = frequency_Hz;
ChannelDutyCycle = dutyCycle;
this.Start();
}
/// <summary>
/// All Stop! Stops the Channel's PWM...
/// </summary>
public void ChannelStop()
{
this.Stop();
}
/// <summary>
/// Standard Constructor, explicit PWM Inheritance.
/// </summary>
/// <param name="channel">The Cpu.PWMChannel Channel</param>
/// <param name="frequency_Hz">The Frequency in Hertz</param>
/// <param name="dutyCycle">Duty Cycle expressed in Percentage EG: 0.5 gives 50% Duty Cycle of the Frequency</param>
/// <param name="invert">Inverts the Output Pin</param>
private PWMChannel(Cpu.PWMChannel channel, uint frequency_Hz, double dutyCycle, bool invert) : base(channel, frequency_Hz, dutyCycle, invert)
{
Debug.Print("PWMChannel Class Instantiated - First Constructor called...");
}
/// <summary>
/// Standard Constructor, explicit PWM Inheritance.
/// </summary>
/// <param name="channel">The Cpu.PWMChannel Channel</param>
/// <param name="period">The period of the pulse in microseconds.</param>
/// <param name="duration">The duration of the pulse in microseconds. This value should be a fraction of the period parameter.</param>
/// <param name="scale">PWM.ScaleFactor Enumeration - Provides scale factor values for duration and period.</param>
/// <param name="invert">Inverts the Output Pin</param>
private PWMChannel(Cpu.PWMChannel channel, uint period, uint duration, PWM.ScaleFactor scale, bool invert) : base(channel, period, duration, scale, invert)
{
Debug.Print("PWMChannel Class Instantiated - First Constructor called...");
}
} // END of Class...
This code does actually make some features come to life, EG: PWM Changes are much better…
To Use this Code:
PWMChannel.Channel_1.Configure(184000, 0.5);
All the best
Chris