Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC complete discussion for all

Status
Not open for further replies.
values is 511. So there is the value you need to put into the CCPRxL:CCPxCON<5:4>, 10-bits to generate a 50/50 PWM.

the MSB of CCPR1L is 512 right but since we have a 50% duty cycle 1023/2 = 511.5 ..
if I will round it off into 512 I I will not set anymore the CCPRxL:CCPxCON<5:4> right? then the value of my CCPR1L will be 0b10000000xx ?

---------- Post added at 06:27 ---------- Previous post was at 06:17 ----------

so now if I want to use the 511.5 then the value of my register is 0b0111111111.. = 511.. correct?? how about the 0.5 ? hehe

---------- Post added at 06:30 ---------- Previous post was at 06:28 ----------

I hope im correct... hehe
 
Last edited:

the MSB of CCPR1L is 512 right but since we have a 50% duty cycle 1023/2 = 511.5 ..
if I will round it off into 512 I I will not set anymore the CCPRxL:CCPxCON<5:4> right? then the value of my CCPR1L will be 0b10000000xx ?

If I dont want to round it up then I shoul use the 511.5 value.. I stll dont get it how to utilize the 2 LSB bits.. hehe

I can't reply unless I use the advanced reply feature, the forum is beginning to get very flaky again!

Why round it off, if you want a true 50/50 PWM you would set the CCPRxL:CCPxCON<5:4> bits to 0b0111111111 or set the CCPRxL to 0b01111111 and the CCPxCON<5:4> to 0b11. I realize this is awkward and this is the reason a lot of apps only use the CCPRxL or 8-bits of resolution. If you do not need to control the duty cycle by very small time duration increments, in this case approximately 0.4µS per bit or 410µS/1024bits you could utilize only the 8-bits of CCPRxL which would represent approximately 1.6µS per bit or 410µS/256bits.

The same principle can be apply to ADC, DAC or any other digitized value. Which is the reason why a lot apps only use the eight most significant bits of an ADC value, 19.5 mV per bit vs 4.88 mV per bit resolution, for 5V maximum value of 8-bit vs 10-bit ADC respectfully.

In other words the fewer bits, the lower the resolution and the less accuracy of the value. It just depends on your apps needs.
 
hehe I got it right.. I edited my previous post I have the same answer with you.. hehe lol..

yeah I understand now.. thanks so much..
 

correct?? how about the 0.5 ? hehe

I hope im correct... hehe

Yes for 512 the value you specified would be correct. The .5 or 50% value is the example I've given above. I still sense you are a little shaky on the concept of bits of resolution, did the last example help clear this up? I saw you had some question concerning this issue, when some of the other members were covering the topic of ADC and 10-bits vs 8-bits.

Hope the examples help.

Edited after your edit:

Ok, good. Bits of resolution is often a tough subject for people to grasp. "How can I just throw away those two LSbits?" which is often the response I get.
 
got it.. thanks so much.. I will prepare another question for sure If I don't understand something....

today Im doing business to my fellow students and hobbyist to have extra income... hehe
 

I should also add, there are times you cannot use all 10-bits of the CCPRxL:CCPxCON<5:4> to control the duty cycle. The issue is discussed in the datasheet, but not explained well I'm afraid.

Reference PIC18F2455/2550/4455/4550 Data Sheet, pg. 149, EQUATION 15-3 and TABLE 15-4: EXAMPLE PWM FREQUENCIES AND RESOLUTIONS AT 40 MHz
The maximum PWM resolution (bits) for a given PWM
frequency is given by the equation:

As the frequency of the PWM is increased and the period of the PWM grows shorter and shorter, it may be come obvious to you that the MCU can not physically manage resolution bit increments approaching or shorter then the MCU's clock period. Due to this fact as the frequency of the generated PWM increases, the number of bits to control the duty cycle eventually decreases. Checkout the table referenced above for examples.

---------- Post added at 06:28 ---------- Previous post was at 06:03 ----------

today Im doing business to my fellow students and hobbyist to have extra income... hehe


Is this your tutorship service or are you selling parts? You've become quite the entrepreneur!
 
That's one way of putting the thing, you can look at it another way, like I said before, using decimal places:
The value of CCPR1L is to be between 0 and 255. DC1B1 and DC1B0 set the decimal places. Here's the setting:

DC1B1 = 0, DC1B0 = 0, Decimal point value = 0
DC1B1 = 0, DC1B0 = 1, Decimal point value = 0.25
DC1B1 = 1, DC1B0 = 0, Decimal point value = 0.5
DC1B1 = 1, DC1B0 = 1, Decimal point value = 0.75

So, if you set PR2 to 255, using CCPR1L = 127 and DC1B1 = 1, DC1B0 = 0, gives you exactly 127.5 for duty cycle control (50%).

If you compare and use this method, you will see that this is more or less the same thing as what bigdogguru has explained. However, I use this method, because, when coding, I like to keep it in my head that the value of the register representing the duty cycle has to be less than PR2 and a percentage of PR2, proportional to the duty cycle.

Hope this helps.
Tahmid.
 
thaks tamid.. now very clear about that two registers..

I just noticed PIC18 is a heavy load for protues with motors in the simulation running in high frequency.. the CPU load of proteus is 94%..
 

Remove the motor and just observe the duty cycle with an oscilloscope. If it is still too slow, remove the transistor and MOSFET and observe output at the PIC output. Most programs are heavy loads and very few will run in real-time due to the large number of calculations involved and also because Proteus is a single-threaded application.

Hope this helps.
Tahmid.
 
Hi,,

what these modes in CCP1CON register? I only used the
1100 = PWM mode: P1A, P1C active-high; P1B, P1D active-high
to enable as PWM but I tried all that modes below and nothing happened... Im thinking if I can output another pwm to other pins

1100 = PWM mode: P1A, P1C active-high; P1B, P1D active-high
1101 = PWM mode: P1A, P1C active-high; P1B, P1D active-low
1110 = PWM mode: P1A, P1C active-low; P1B, P1D active-high
1111 = PWM mode: P1A, P1C active-low; P1B, P1D active-low


---------- Post added at 09:29 ---------- Previous post was at 09:27 ----------

Remove the motor and just observe the duty cycle with an oscilloscope. If it is still too slow, remove the transistor and MOSFET and observe output at the PIC output. Most programs are heavy loads and very few will run in real-time due to the large number of calculations involved and also because Proteus is a single-threaded application

yeah I already remove them all and only the oscilloscope left.. it's working properly based on the pulse..
 

Hi,

Active high means that the output device turns on when a positive voltage is received. So, at 30% duty cycle at a 100us period, the controller will output 1 or high for 30us and 0 or low for the remaining 70us.
Active low means the the output device turns on when zero voltage is received. So, at 30% duty cycle at a 100us period, the controller will output 0 or low for 30us and 1 or high for the remaining 70us.

Hope this helps.
Tahmid.

---------- Post added at 13:35 ---------- Previous post was at 13:32 ----------

To output another PWM on another pin, you can use CCP2. There are 2 CCP modules in 18F4550. So, you can use registers CCP2CON, CCP2RL. But the time-base, PR2, will be the same. So, PWM on both pins will be at the same frequency. You can also use the ECCP (enhanced CCP) module to output PWM on 2 or 4 pins in half-bridge or full-bridge mode.

Hope this helps.
Tahmid.

---------- Post added at 13:36 ---------- Previous post was at 13:35 ----------

Or, you can set up PWM manually using CCP2 set in compare mode and using TMR1. This will require a little more coding though.
 
To output another PWM on another pin, you can use CCP2. There are 2 CCP modules in 18F4550. So, you can use registers CCP2CON, CCP2RL. But the time-base, PR2, will be the same. So, PWM on both pins will be at the same frequency. You can also use the ECCP (enhanced CCP) module to output PWM on 2 or 4 pins in half-bridge or full-bridge mode.

This looks complicated.. hehe I will study this later... hehe
why I cannot locate the CCP2CON register like the CCP1CON? all the bits of CCP1CON is describe in the datasheet but the CCP2CON is not..

---------- Post added at 09:45 ---------- Previous post was at 09:43 ----------

i Think the configuration of CCP2CON is exactly the same with the CCP1CON register..
 

Hi,
In the datasheet, it is written as CCPxCON, CCPRxL. x can be 1 or 2. So, this means that CCP1CON and CCP2CON have the same register configuration, difference between 1 and 2. So, set up CCP2 like you set up CCP1 and you'll see that it works fine.

Hope this helps.
Tahmid.

---------- Post added at 13:47 ---------- Previous post was at 13:46 ----------

However, the frequency will be the same as both PWM modules (CCP1 and CCP2) have a common time base PR2.
 

Hi,
In the datasheet, it is written as CCPxCON, CCPRxL. x can be 1 or 2. So, this means that CCP1CON and CCP2CON have the same register configuration, difference between 1 and 2. So, set up CCP2 like you set up CCP1 and you'll see that it works fine.

Hope this helps.
Tahmid.

yeah thanks so much...

I will try..

by the way are you an engineer?
 

by the way are you an engineer?
Not by certificate. I learnt electronics with the help of my dad. I am just a student in grade XI. You can call that high school or college.
 

thanks so much TAmid.. I have now two working PWM output.. hehe

---------- Post added at 10:09 ---------- Previous post was at 09:50 ----------

Active high means that the output device turns on when a positive voltage is received. So, at 30% duty cycle at a 100us period, the controller will output 1 or high for 30us and 0 or low for the remaining 70us.
Active low means the the output device turns on when zero voltage is received. So, at 30% duty cycle at a 100us period, the controller will output 0 or low for 30us and 1 or high for the remaining 70us.
I thought those bits will enable my 2nd pwm output.. Im wrong..instead the CCP2CON does.
 

Maybe it is time to close this thread as this is deviating the topic as romel had asked me to keep it in single thread..
I thought it would be restricted only to PIC18f4550 and its peripherals..

Romel please start a new thread.. I am purposefully not getting involved into this as it is going offtopic very often...

maybe other moderators may take objection...

It was supposed to be a example for everyone who wants to learn PIC. but may not be too much interested in these deviated topic as it is personal to you.
 
Isn't this similar to what you are already selling? I would recommend waiting for a used genuine Microchip ICD2. I have both ICD2 and ICD3s and still used both, I think the ICD2 is a little more rugged.

most likely the same.. hehe
I changed my mind I don't what to buy it.. hehe


The the photos help you understand the TRIAC/PWM relationship, I'm not sure if they are using a zero-crossing detector in the second example, just remember the PWM in your project should start at the zero-crossing point.
the first picture show's it clearly..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top