CCS _ View topic - Multiple PWM outputs

Embed Size (px)

Text of CCS _ View topic - Multiple PWM outputs

CCS :: View topic - Multiple PWM outputs

http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15

FAQ

Forum Help Profile

Official CCS Support

Search

Register Log in

Log in to check your private messages

Multiple PWM outputsGoto page Previous 1, 2, 3, 4 Next

CCS Forum Index -> General CCS C Discussion

1 24

28.2.2007 . 09:12

CCS :: View topic - Multiple PWM outputs

http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15

View previous topic :: View next topic Author ChrisSPosted: Mon Nov 29, 2004 4:06 pm

Message

Joined: 29 Nov 2004 Posts: 4 Location: PA

Question then....does it need to be a buffered register that the data comes into? if you are loading the comparator at the same instant its comparing to the counter could it produce a glitch in the comparator output? Next...for Dave's sake, if you want to consider doing it this way, the cpld chips are pretty cheap i think...the way I went was with the free Xilinx webpack like you mentioned. There is a little programming dongle that costs $95 that you use program the chip from the webpack software on your PC . Also, the webpack software allows you to create your logic a few different ways. One way is by writing code in VHDL or Verilog, but there is also a whole graphical interface that allows you to actually create your logic graphically, just like you would a schematic of logic gates, etc. you literally pick and place little logic symbols on your screen and connect them with lines like your drawing a schematic. Then you download it to the chip. Its actually very cool and extremely easy. I guess doing that way is a little like programming in Visual Basic as opposed to assembler...its quick and easy but not necessarily the most resourceful or streamlined way...that is what I have heard, but for my apps. it has worked great. Maybe someone else has more input on this. You can find all the info you need and chips and parts on Xilinx.com

John P

Posted: Mon Nov 29, 2004 8:03 pm

Joined: 17 Sep 2003 Posts: 46

I've done an 8-channel PWM on a PIC16F877, running at 60hz. Wouldn't you want to use 60Hz, if these lamps run off the power line? Mine had a resolution of 1%, but it could have been more. 250KHz is a brisk data rate, but I think it's workable. My approach is usually to set up a timer running as fast as needed to catch every incoming character by polling, interrupting only on the timer. The characters just get stuffed into a buffer, for processing outside the interrupt. Then the other thing the timer does is get divided down to whatever you need to run the outputs, and calculate whether a given output needs to change or not. Since there are 8 outputs, you could have a register associated with each one, which would be its turn-off time, or 0 if it never turned on. So every timer tick, you'd check the 8 registers to see whether any changes were needed in the outputs. At tick 0, you'd turn on every output whose register held a non-zero value.

Guest

Posted: Tue Nov 30, 2004 1:59 am

John, sorry, I have drifted off the original posting a little, but it was a question of producing 24 pwm channels at about 2Khz i think...dont think he is intending on using it for a dimmer, but he didnt say...I was just relating it to a pwm application I did once that was for AC dimmers and recieved DMX like he also wants to do. I'm sure that with a 40Mhz PIC and enough tweeking of code he could make 8 channels work. I was trying to think of some other options that would give him more headroom. He needs 24 channels of PWM, so he will obviousely need a multi-chip solution I think. I have never tried receiving asyncronous data by polling the receiver. It would seem like you would have to pole at several times the frame rate of the data coming in in order to guarantee you'll catch each byte. I guess that might work up to a certain number of PWM channels. If you want 8 bit resolution, your clock ticks have to be at a frequency 256 times as fast as your duty cycle right? and you have to update all your registers within the time of each of those ticks. One thing that DMX does have going for it in his favor is that each channel value is sent only once per packet, and there is usually a small amount of idle time (maybe a few milliseconds) before the next packet comes along. I have used this time before to do any data processing I have, so that on top of the timing-critical pulse shaping thats going on, I'm only doing one other thing at any given time...either receiving data, or processing it. It all comes down to a question of do you have enough bandwidth around your PWM routines to take care of everything else in a timely fashion. Anyway, if you read the first few posts your get an idea of what he needs.davtPosted: Tue Nov 30, 2004 4:01 am

Joined: 07 Oct 2003 Posts: 76 Location: England

Thanks everybody for your input! Mark you must be a very clever fellow or have very long lunch breaks - obviously the former! I am dimming Led's so am using PWM - or maybe someone can advise an alternative? I have built an analogue lighting board of 20 channels using 10x12f675 (2 software PWM's / chip) I thought it would be nice to go digital (DMX)throughout and try and put it all onto one chip. I suppose I could go down to 400 or 500 hundred Hz or maybe lower so long as I can avoide flicker. Regards. Dave

2 24

28.2.2007 . 09:12

CCS :: View topic - Multiple PWM outputs

http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15

Mark

Posted: Tue Nov 30, 2004 7:20 am

Joined: 07 Sep 2003 Posts: 3511 Location: Atlanta, GA

One Hundred Hertz is the typical "no visible flicker" frequency. I am more inclined to believe that 100Hz-500Hz is doable in a single PIC. Are you limited to just the 16 series or do you have the PCH compiler for the 18's

PCM programmer

Posted: Tue Nov 30, 2004 9:17 am

Joined: 06 Sep 2003 Posts: 6766

Quote: I am dimming Led's so am using PWM - or maybe someone can advise an alternative?

I wondered if that was your application. Look at the TLC59xx series of LED drivers, such as the TLC5904. They will do 256 gray levels (or more). For a small number of LEDs, they're a better solution than the FPGA mentioned previously, because they have built-in constant current drivers and other features. With an FPGA, you would have to add an external constant current driver chip. In the US, they are available from http://www.digikey.com http://focus.ti.com/paramsearch/docs/parametricsearch.tsp?templateId=5&paramTable=yes&familyId=480davtPosted: Tue Nov 30, 2004 9:37 am

Joined: 07 Oct 2003 Posts: 76 Location: England

Mark I have PCW 3.21 so I should be OK. Can you give me a bit more detailed explanation of how to set up for the multiple PWM's. Thank you 'pcm programmer' I will look into those chips!! Many thanks Mark. Dave

Mark

Posted: Tue Nov 30, 2004 6:31 pm

Joined: 07 Sep 2003 Posts: 3511 Location: Atlanta, GA

Did a little testing today and at 20MHz a PIC18 was a bit stressed with the default int handler. I test it with a custom one tomorrow and see how it goes. I'll post you some code to go along with it.

davt

Posted: Thu Dec 02, 2004 3:34 am

Joined: 07 Oct 2003 Posts: 76 Location: England

Thanks for that Mark

Mark

Posted: Thu Dec 02, 2004 8:25 am

Joined: 07 Sep 2003 Posts: 3511 Location: Atlanta, GA

Okay, here is a program that will receive the first 24 channels of a DMX stream and generate 24 8bit 200Hz PWM's. You could probably up it just a bit more with the present 20MHz clock or a lot more if you run it at 40MHz (which is what I would do but didn't have a board with that value for testing). I tried to comment best I could and refrained from using assmebler for the most part The C fileCode:

3 24

28.2.2007 . 09:12

CCS :: View topic - Multiple PWM outputs

http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15

#CASE #include "18F252_.h" /* used to setup device specifications for programming the chips HS - oscillator type WDT- watchdog timer NOPROTECT - do not protect code PUT - power up timer on BROWNOUT - brownout detect on */ #fuses NOLVP, HS, NOWDT, PUT, BROWNOUT, NOPROTECT /* initialize all RAM locations to zero */ #ZERO_RAM #define CLOCK_FREQUENCY 20000000 #define FOSC (CLOCK_FREQUENCY/4) #USE DELAY(CLOCK = CLOCK_FREQUENCY) #USE STANDARD_IO(A) #USE STANDARD_IO(B) #USE STANDARD_IO(C) /* DMX is 250K baud. I wouldn't put errors in here. It is handled in the int. */ #USE RS232(baud=250000,rcv=PIN_C7,xmit=PIN_C6)

/* Timer1 prescale value */ #define T1_PRESCALE 1 /* This is the frequency of the PWM. To find out the max frequency, you should sum the max time of the CCP2 isr and the DMX recv int Now multiply that by 256 and that will give you the period. */ #define PWM_FQ 200 /* This sets the size of our buffers. */ #define MAX_PWMS 24 #define MAX_PWM_ARRAY (((MAX_PWMS-1)/8)+1) /* This would be the width of the smallest pulse, level = 1 */ #define PWM_STEP (((FOSC/256)/T1_PRESCALE)/PWM_FQ) /* This is the period for the PWM. I substracted 1 from the value so that a level of 255 would actually exceed the period of the PWM and thus the outputs would never turn off */ const int16 PWM_PERIOD = (255*PWM_STEP)-1; /**************************************************************************** * Card IO * ****************************************************************************/ /* This was the IO for a card I did some testing with. You will need to setup the IO per your hardware. */ /* The IO on this card is as follows: RA0 - RA5 - Used to test the PWMs TRISA - 0000 0000 - 00h RB0 - INT - Zero Cross Interrupt (input) R