PWM Channels and 16 bit operation
Posted: Wed Apr 08, 2009 6:51 pm
Hello,
I am using the Mod 5213 to control a voltage based servo motor. As such, I need to use pulse width modulation in order to control the position of the servo motor. I stumbled upon a PWM example for the Netburner and it has been working with limited success. The code is as follows:
Pins[24].function(PIN24_PWM0); // Enable PWM functionality for pin 24
sim.pwm.pwme = 0; // Disable all PWM channels before making any settings
sim.pwm.pwmpol &= ~0x01; // Set to have an initial low signal, then set high on duty cycle output compare
sim.pwm.pwmclk |= 0x01; // Set to use clock SA (Scale A)
sim.pwm.pwmprclk |= 0xF; // Set to use clock A prescale value of 2
sim.pwm.pwmcae &= ~0x07; // Set to operate channel 0 in left-aligned output mode
sim.pwm.pwmctl = 0; // All channels are 8-bit channels, doze and debug mode disabled
sim.pwm.pwmscla = 0x04; // Use scale divisor value of 2 to generate clock SA from clock A
sim.pwm.pwmcnt[0] = 1; // Write any value to this register to reset the counter and start off clean
sim.pwm.pwmper[0] = 100; // Set PWM channel period register to a value
sim.pwm.pwmdty[0] = 30; // Set PWM channel duty register to a value of 3
sim.pwm.pwme |= 0x01; // Enable PWM output for PWM channel 0
This code does work (I have checked on an oscilloscope) but I am having difficulty in a couple of areas.
1) I can only get this code to function for pin 24. I have tried everything that I can think of, but can't seem to adjust the code to work on another PWM enabled pin.
2) I am trying to get this code to operate in 16-bit mode (using 2 concatenated 8 bits) by altering pwm.pwmctl according to the application notes. However, I cannot get anything to work, let alone compile, as every syntax I have tried, fails.
If I could get some help with this, I would greatly appreciate it!
I am using the Mod 5213 to control a voltage based servo motor. As such, I need to use pulse width modulation in order to control the position of the servo motor. I stumbled upon a PWM example for the Netburner and it has been working with limited success. The code is as follows:
Pins[24].function(PIN24_PWM0); // Enable PWM functionality for pin 24
sim.pwm.pwme = 0; // Disable all PWM channels before making any settings
sim.pwm.pwmpol &= ~0x01; // Set to have an initial low signal, then set high on duty cycle output compare
sim.pwm.pwmclk |= 0x01; // Set to use clock SA (Scale A)
sim.pwm.pwmprclk |= 0xF; // Set to use clock A prescale value of 2
sim.pwm.pwmcae &= ~0x07; // Set to operate channel 0 in left-aligned output mode
sim.pwm.pwmctl = 0; // All channels are 8-bit channels, doze and debug mode disabled
sim.pwm.pwmscla = 0x04; // Use scale divisor value of 2 to generate clock SA from clock A
sim.pwm.pwmcnt[0] = 1; // Write any value to this register to reset the counter and start off clean
sim.pwm.pwmper[0] = 100; // Set PWM channel period register to a value
sim.pwm.pwmdty[0] = 30; // Set PWM channel duty register to a value of 3
sim.pwm.pwme |= 0x01; // Enable PWM output for PWM channel 0
This code does work (I have checked on an oscilloscope) but I am having difficulty in a couple of areas.
1) I can only get this code to function for pin 24. I have tried everything that I can think of, but can't seem to adjust the code to work on another PWM enabled pin.
2) I am trying to get this code to operate in 16-bit mode (using 2 concatenated 8 bits) by altering pwm.pwmctl according to the application notes. However, I cannot get anything to work, let alone compile, as every syntax I have tried, fails.
If I could get some help with this, I would greatly appreciate it!