![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi,
I am relatively new to programming so am looking for some advice... I want to programme a PIC to produce a square wave with a period of 50us (f = 20kHz) and need to be able to set the on and off times of the square wave. I need this as this will control an igbt's switching in a DC-DC boost converter. What limited programming i have done has been on a 16f84 but looking at some datasheets i have found that the 16f877 has a PWM mode where i think it is possible to set the on and off times of the square wave. What are people's opinions of this? would the 16f877 be a better choice? I am planning on writing the code in assembler (MPLAB IDE), i'm trying to keep the code as simple as possible but would the use of interrupts be the best way to do it? Any help or suggestions on the choice of PIC and implementation in the code would be very helpful. Thanks |
|
|
|
|
|
|
(permalink) |
|
Unless you need lots of I/O then use a 16F628 or better still a 16F88. Both have the PWM module and an internal oscillator as well. Implementing any sort of SMPS is tricky with a pic, however, I vaguely remember a AN about it. Have a search on Microchips site for SMPS.
Mike. |
|
|
|
|
|
|
(permalink) |
|
You can use the 16F877(40-pin) but the 16F628A, which is 18-pin PIC to replace the old 16F84, has PWM too.
Get the datasheet from Microchip and have a look at section 9.3.2 where it said using a 20MHz clocking, you can have 10-bit PWM resolution at 19.53KHz. If you want higher PWM frequency than that, the resolution would decrease. But I think 19.52KHz is close enough for your purpose. You don't need interrupt to make hardware PWM works. Once the PWM has been setup, no more user programming is required except to change/adjust the duty cycle, by writing different values to the CCPR1L and the CCP1CON[5..4] bits. That's it, everything is taken care of, a ~20KHz PWM output with your desired duty cycle.
__________________
L.Chung |
|
|
|
|
|
|
(permalink) |
|
thanks for your quick replies, will look into the 16F628A....
|
|
|
|
|
|
|
(permalink) |
|
Using a 20MHz crystal as Clock, TMR2 prescalar=1, setting PR2 to 249(0xF9) instead of 0xFF would give you an exact 20KHz PWM frequency output.
Just make sure that the CCPR1L value be 248(0xF8) or less at all times else the PWM output will never go LOW(duty cycle exceeds 100%).
__________________
L.Chung |
|
|
|
|
|
|
(permalink) | |
|
Quote:
i dont think writing your code in assembly will be the simplest way.Try some high level language like mikrobasic.Its much simpler than assembly,its really helpful when your writing large programs.The PWM your trying to do could be done in 2 or more lines of code if you use mikrobasic.The compiler trial version is free to download(trial version is limited to 2K words of code,2K words of code is really big,so there is no chance that your program exceed that limit).Also you can get much support if you are stuck as it has a forum dedicated to its use,manual to download and free online books about programming PICs in mikrobasic.take a look at the websites for more info: http://www.mikroe.com/en/compilers/m.../pic/index.htm http://www.mikroe.com/en/books/picbook/picbook.htm http://www.mikroe.com/en/books/picbasicbook/00.htm
__________________
Have a nice day.Be happy!! $ViNkE |
||
|
|
|
|
|
(permalink) |
|
Whats so large about an adjustable PWM? OP's post will consume more character based bytes then OP's objective.
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
Have a nice day.Be happy!! $ViNkE |
||
|
|
|
|
|
(permalink) |
|
For a DC-DC boost converter I would use the highest frequency possible. You can get 78.2Khz with 8bit resolution which should give you ample resolution. You will need to implement a simple PID control loop to give it a stable output.
I used a very simple PI loop in a 16F684 based 11-15V 20Amp booster I designed to eliminate the voltage drop between my truck and camper. It also functions as a battery charger controller when plugged into 110vac by regulating the rectified 12V output from the standard power converter.
__________________
--- The days of the digital watch are numbered. --- |
|
|
|
|
|
|
(permalink) |
|
With the higher frequency there's going to be higher switching losses so it really depends on the exact components to be used, at higher frequencies like 78khz, dedicated high speed drivers are more inteligent. For a simple IGBT run from a micro controller a lower frequency might be more sensible, and flame resistant =)
__________________
"Because I be what I be. I would tell you what you want to know if I
could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." |
|
|
|
|
|
|
(permalink) | |
|
Quote:
He starts off his solar irrigation project using a trial version compiler with a 2K code limit, which he claims he doesn't know about, and reaches the code space limit soon after. He asked about the price of the full version but it costs $149 and he can't find the money to pay for it, yet. He is now stuck. I would have guessed he can probably done the whole project comfortably within 1K code size using ASM instead.
__________________
L.Chung |
||
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
Have a nice day.Be happy!! $ViNkE |
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Question about Inchworm+ | Quan | Micro Controllers | 54 | 28th October 2007 12:20 AM |
| Grr... high frequency square wave | dandare99 | Electronic Projects Design/Ideas/Reviews | 10 | 27th January 2007 08:53 PM |
| square wave to sine wave | tony Ben | Electronic Projects Design/Ideas/Reviews | 2 | 26th January 2005 04:04 AM |
| circuit help: square and sin wave input = square wave output | spyghost | Electronic Projects Design/Ideas/Reviews | 2 | 28th April 2004 01:08 AM |
| How can I convert a square wave to sine wave?? | kken6248 | General Electronics Chat | 6 | 1st April 2004 03:27 PM |