Sample Code for PWM Control

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Sample Code for PWM Control

跳至解决方案
3,017 次查看
stevejanisch
Contributor IV

Hello.  I am working on a MCF5441X Tower and hoping to find some sample code to control the PWM.

 

I did find one Application Note -- Specifically AN4429 -- which has been sort of helpful.  The note is written for DSCs MCF56F8xxx devices, but notes that the MCF5441x is similar.  It is sort of difficult to follow since the code examples are not written with the Tower in mind and isn't really a step-by-step tutorial.

 

Does anyone know whether such an example, tutorial, or guideline exists?

标签 (1)
标记 (3)
1 解答
1,739 次查看
stevejanisch
Contributor IV

I have successfully gotten the examples referenced in AN4485 to work with the TWR-MCR5441X.  Like all things, it is wonderfully simple once you truly figure it out.  Perhaps once I clean up the code a bit I could post it somewhere in case anyone ever runs into the issue again.

在原帖中查看解决方案

10 回复数
1,740 次查看
stevejanisch
Contributor IV

I have successfully gotten the examples referenced in AN4485 to work with the TWR-MCR5441X.  Like all things, it is wonderfully simple once you truly figure it out.  Perhaps once I clean up the code a bit I could post it somewhere in case anyone ever runs into the issue again.

1,739 次查看
stevejanisch
Contributor IV

Continuing my conversation with myself...

I did find another Application Note that (I hope) will be helpful and get me further in this saga.  AN4485 - Using eFlexPWM with MC56F82xx DSC.  This of course is not the MCF5441X tower I am working on, but AN4429 alludes that the mcPWM in the MCF5441X is basically similar to the eFlexPWM in the MCF56F825x.  AN4485 is great because it has (drum-role) REAL SAMPLE CODE.  If you search for AN4485 from freescale.com you should see the sample code listed.

http://cache.freescale.com/files/dsp/doc/app_note/AN4485SW.zip

There are some small modifications that need to be made...various register defines that are slightly different, but the first example mode -- Edge-aligned PWM -- did compile and appears to run on the board.

I do see register values (namely the PWM_SM0CNT register) changing, but alas I still do not have output on the pins that I can see on an oscilloscope so don't really know what is up with that.  If anyone has any insight to why that might be or any suggestions to try I would greatly appreciate your thoughts.

0 项奖励
回复
1,739 次查看
TomE
Specialist II

> Kinetis (wish I were working with that; seems like support for it is more mature).

Support is a reason to choose one family of chips over another.

Did you find AN4254? It details motor control on a Tower system using an MCF5441x, but assumes you're using MQX. Depending on how much your time is worth, MQX may be worthwhile.

> I still do not have output on the pins

It would help if you said which pins you're monitoring and expecting to toggle, and whether they're "CPU Pins" or some connector or test point on the Tower board.

The MCF5441x has eight PWM outputs, PWMA0-3 and PWMB0-3.

Signal Name     GPIO     Alternate 1   Alternate 2

SDHC_CLK       PG5      PWM_A0     DSPI1_SCK

SDHC_DAT3     PF2      PWM_A1      DSPI1_PCS0

SDHC_DAT1     PF0      PWM_A2      DSPI1_PCS1

UART2_RXD     PE4      PWM_A3      SSI1_RXD

SDHC_CMD      PG6     PWM_B0      DSPI1_SIN

SDHC_DAT2     PF1      PWM_B1      DSPI1_PCS2

SDHC_DAT0     PG7      PWM_B2     DSPI1_SOUT

UART2_TXD      PE3      PWM_B3     SSI1_TXD

On the Tower board, the four "SDHC_DATn" ones are marked "SDHC_DAT[3:0]" on the board. The other two SDHC ones are CMD and CLK pins. The remaining two PWM signals are U2RXD and U2TX.D.

I don't have a Tower system, only one schematic, so I don't know what access you have for these pins, and what they're pinned out to or connected to. They may be connected to an SDHC card socket for all I know, or perhaps that's an option.

Back to the CPU. The PWM signals are all "Alternate 1" connections to these pins. If you're used to simpler CPUs (like the 8-bitters), then the selection of which function is connected to which pin depends on which peripheral is enabled. If you enable the UART (for instance) then it "owns" the pins, otherwise they're GPIO. On all ColdFire CPUs except for the MCF41 ones you have to explicitly program what device is using the pin.

For PWM_A3 and PWM_B3 you have to program "15.3.6.8 UARTn Pin Assignment Registers (PAR_UARTn)". For the other ones you have to program "15.3.6.9 eSDHC Pin Assignment Registers (PAR_SDHCH & PAR_SDHCL)".

On some CPUs, every I/O pin on the CPU has a separate register. They take a lot of programming (or setting up of tables) to get going.

You may have already done all of the above and it may not be working for some other reason, but the above is my first guess from your posts.

Tom

1,739 次查看
stevejanisch
Contributor IV

Thanks for your comments.  AN4254 is mostly theory without code, which is why I focused more on AN4429 (which has pseudo code) and especially AN4485, which has real code.  I had reviewed all the manuals for the board and had configured the board for the alternate pins (the PWM_A0 and B0 pins are brought out to one of the tower modules), but it is always good to have some suggestions.

GREAT UPDATE: Late Friday I actually started to get something at the output pins.  It is not exactly as predicted... more like short pulses rather than a full PWM cycle.  At this point I would have to say the code that accompanies AN4485 is the best example code for PWM, although I would like to ensure I understand it a bit better and have tested all the modes successfully.  At any rate, I think I am very close.

0 项奖励
回复
1,739 次查看
TomE
Specialist II

> more like short pulses

I was going to suggest that it might be code expecting 8-bit PWM on 16-bit PWM hardware, but I've just scanned the mcPWM chapter. That's a horribly complicated part. Welcome to the world of "Reverse Engineering". It once took me about two years before I got a Freescale chip programmed properly as there was no documentation or sample code.

I'd suggest you try GPIO writes to the ports to make sure your connections are as you expect, then try programming one of the simpler timers to make sure all the clocks are running at the speed you expect and able to drive outputs. Then find the simplest possible PWM mode to start with.

I'd also suggest googling for keywords, like register names. I've found sample code like that before. But I've tried that and didn't find anything out there for this module and chip.


Good luck.

Tom


1,739 次查看
stevejanisch
Contributor IV

All very good recommendations.  Actually it was Google rather than any internal Freescale searches that led me to AN4485, which has been the most useful document.  I finally understand all the concepts and registers and it actually works quite well.


Overall a very good internal module and in the end very simple to code.  Pity getting started was so difficult.  Now I can dig into my application a bit more.

0 项奖励
回复
1,739 次查看
stevejanisch
Contributor IV

I continue to work with AN4429 and continue to be road blocked.  Maybe because I don't have a firm grasp of what the mcPWM (aka eFlexPWM) module is and how it is supposed to work.

The MCF5441X only support Peripheral Initialization in Processor Expert, and there is a "Init_mcPWM" component in CW 10.3.  I attempt to configure the Component Inspector for this component and it compiles but nothing really happens at the PWM output pins.  I would hope I would set a bunch of registers and then finally see some type of pulse out of the pins.

This is my first try at Processor Expert as well as the Tower board, so don't know what to expect.  I know the processor expert is working since I can initialize GPIO Port G which sets some LEDs on the board.

So far there are a few things that Processor Expert is doing that conflict with the pseudo code in AN4429 and also somewhat with the MCF5441x Reference Manual on the mcPWM module.

For example, in AN4429 it sets the PWM_OUTEN register to 0x0770 while Processor Expert sets it to 0xF111.  The low nibbles might not matter since I've only selected one channel in PE while AN4429 seems to use all.  But the highest nibble according to the reference manual are reserved and must be cleared.

So perhaps tomorrow I will try and manually enter PE-like code in that matches the AN4429 pseudo code.  Just would be nice to know if anyone has ever stumbled through this before.

0 项奖励
回复
1,739 次查看
stevejanisch
Contributor IV

Doesn't seem like there is much.  I did find the following threads that address the same question:

https://community.freescale.com/thread/303038

https://community.freescale.com/thread/138114

https://community.freescale.com/thread/94086

0 项奖励
回复
1,739 次查看
Monica
Senior Contributor III

Hello Steve,

do any of those threads respond to your question?

Please let us know! :smileywink:

Best regards,

Monica.

0 项奖励
回复
1,739 次查看
stevejanisch
Contributor IV

No.  Two of the threads are for the Kinetis (wish I were working with that; seems like support for it is more mature).  The other thread (303038) was really just a repeat question like mine.  It did mention Processor Expert, and I tried to stumble through that but without the high level component support in the MCF5441x I'm still left with having to try and understand and piece together the pseudo code from AN4429.

I do appreciate your response, and any information or direction you could add.

0 项奖励
回复