PWM HCS08 starter kit, prototype LED light.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PWM HCS08 starter kit, prototype LED light.

4,327 Views
karmabobby
Contributor I
Hi, I just thought I'd ask some questions regarding a project I am doing at University. I have been asked to build a prototype LED light. 25 one colour and 25 another. Both will look white but will have different spectra properties due to the type of LED. This is for a filming project in my Audio and Video Engineering course.

I have been told I need to program a microcontroller using PWM to alter the light intensity of each set of LED's. My supervisor told me to get PWM generated and displayed on an oscilloscope. This is where I am confused. How would I test with an oscilloscope? I wasn't really taught PWM properly last year(if anyone knows any good tutorials that would be great). What kind of frequency would I be looking at just to get started and having a successful PWM sub routine working?

These are general questions and I am not looking for complete answers, just some pointers from the more experienced programmers out there. Thank you.

ps I have downloaded all the data sheets, and do know what registers need using...just not sure how to get started.
Labels (1)
Tags (1)
0 Kudos
7 Replies

636 Views
bigmac
Specialist III
Hello,
 
You will need to use two channels associated with a TPM module, one channel for each group of LEDs.  Each TPM channel has an associated pin used to output the PWM signal in this case.  To minimize strobe effects, I would suspect that the PWM frequency would need to be much greater than the frame rate of the film or video, i.e. many on/off cycles during the exposure time for each frame.
 
With reference to the TPM section of the datasheet -
 
1)  Setup the TPMSC register for the required clock source and pre-scale value.  Maybe use edge aligned PWM.
2)  Set TPMMOD register to produce the required PWM frequency (in conjunction with clock source and prescale value).
3)  Setup each of the TPMCnSC registers for PWM mode, and with the polarity that you require.
4)  Set each TPMCnV register for the duty cyle required for each channel.  If the value should exceed the TPMMOD setting, this will give a duty cycle of 100 percent.
 
You should then be able to observe the PWM waveform at each output pin.  Of course you will need additional hardware in order to drive the multiple LEDs on each channel.
 
Regards,
Mac
 
0 Kudos

636 Views
karmabobby
Contributor I
I am not looking to drive any LED's just yet. I just need to get some form of PWM generated and displayed on an oscilloscope. Im not sure how to do this, do I just drive a couple of pins as outputs and connect them to the oscilloscope. I will also need to later on be able to adjust the duty cycle so I can control the intensity of the light. I will have my first draft of code posted up later on. It probably wont be much more than some register configurations. How would I set an LED on the board to be a test output? Do I just set the required PTAD and It will drive itself? Probably not, so if someone could give us a clue I would be very grateful
0 Kudos

636 Views
bigmac
Specialist III
Hello,
 
Whenever a TPM channel has PWM mode enabled (TPMCnSC register setting), the pin associated with the particular channel will become an output, and this will over-ride any setting that the pin may have for general purpose use.  Each channel uses a designated pin.  Refer to the datasheet for the device you are using.
 
Regards,
Mac
 
0 Kudos

636 Views
karmabobby
Contributor I
Firstly thank you for your pointers. I have had a look over the data sheet and come up with the following register values.
 
TPMSC  = 0x0C;
 
This is set to use edge aligned PWM with the bus clock and a prescale divisor of 64.
 
TPMC1SC = 0x74;
 
No Interrupts (software polling), with high true pulses.
 
TPMMOD = 0x00FA;
 
TPMC1V = 0x0032;
 
The output pin for this channel is PTB5.
 
PTBDD = 0x20; to drive PTB5 as an output(may not be needed, not sure)
 
Ok so with these settings I am hoping to get a PWM signal at 500Hz which is true for 10%(50Hz) of the signal. This will be just to get a basic PWM sub routine going in the lab to show PWM generation on an oscilloscope. If theres any problems with the above settings then let me know.
 
The board I am using is the MC9S08QG4 demo board.
0 Kudos

636 Views
bigmac
Specialist III
Hello,


karmabobby wrote:

TPMSC  = 0x0C;
This is set to use edge aligned PWM with the bus clock and a prescale divisor of 64.
 
TPMC1SC = 0x74;
 No Interrupts (software polling), with high true pulses.
 
TPMMOD = 0x00FA;
 TPMC1V = 0x0032;
 
The output pin for this channel is PTB5.
 PTBDD = 0x20; to drive PTB5 as an output(may not be needed, not sure)
 
Ok so with these settings I am hoping to get a PWM signal at 500Hz which is true for 10%(50Hz) of the signal. This will be just to get a basic PWM sub routine going in the lab to show PWM generation on an oscilloscope. If theres any problems with the above settings then let me know.
 
The board I am using is the MC9S08QG4 demo board.


For PWM mode with high true pulses, and no interrupt, I might have expected the TPM1SC value to be 0x28.  Also, when PWM mode is selected, the PTB5 pin will become an output independent of the PTBDD setting.

The settings for TPMC1V and TPMMOD will produce a duty cycle of approximately 20 percent, rather than 10 percent.  An alternative would be to use a prescale setting of 1, and increase the values within both registers by a factor of 16.  This would provide improved resolution for the same PWM frequency.

TPMSC = 0x08;
TPMMOD = 3999;
TPMC1V = 800;  // 20% duty


Regards,
Mac



0 Kudos

636 Views
Lundin
Senior Contributor IV
I don't know what frequency you need, but you can easily experiment with that. A plain TV has an update frequency of 25Hz and the human eye never notices it.

PWM is real easy to use. You just set the period and the duty cycle and it takes care of everything in the hardware. You could for example have a period of 100Hz and change the duty cycle.
0 Kudos

636 Views
karmabobby
Contributor I
Yeah it doesn't seem to bad from what I have been reading. A few basic calculations and setting correct values in a few registers. Ill post back with what I have come up with. Thanks anyway
0 Kudos