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.

[PIC] How to generate 3 PWM signals from pic12f

Status
Not open for further replies.

Hatem_SAMMARI

Newbie level 5
Joined
Oct 12, 2016
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
76
Hello everyone (PWM controller for RGB LEDs using PIC12F)
I want to generate 3 PWM signals with the cheapest and the smallest PIC UC (like 10f, 12f or 16f).
Should I use timers and interruptions or doing something else?
I will be grateful for your help.
 

I want to generate 3 PWM signals with the cheapest and the smallest PIC UC (like 10f, 12f or 16f)

You can do in many ways, from a simple code in assembler based on a PIC 10F/12F, but the question itself lacks details, such as, what other tasks that uC must perform, what external or internal parameter control the PWM output, etc... ?
 

Try a parametric search on the Microchip web site (https://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1001).
From there you can quickly see the cost of a device as well as how many PWM peripherals it has.
It took me less than a minute to find a suitable example in the PIC12(L)F1571/2 which has 3 hardware PWM modules.
Susan
 
Subject to you being able to answer Andre's questions, yes, it is possible using some fairly simple timer routines. The principle is:

Start with target values from 0 to 255 for each of the outputs and counting registers declared as 8-bits wide for each output.

1. make all three outputs high (call this time zero)
2. use a timer interrupt to increment all the counting registers
3. if the counting register matches the target value, make that output low
4. when the counting registers reach 256 (roll over), go back to step 1.

Using larger PICs I have produced 12 PWM outputs using that method but it could be expanded to more.

Brian.
 
Thanks a lot for your reply, in fact, I am a PIC programming beginner and I m using miKroC pro for pic, yes there is another task: reading a button to changing colors.

Aussie Susan helped me to choose the right PIC which is 12f1572 to generate the three signals.

but I still have a question and it will be so kind to have a response; can I generate 2 pwm signals from the same time using interruption?
 

can I generate 2 pwm signals from the same time using interruption?
Timer interrupt driven pwm involves some timing inaccuracy and jitter due to interrupt latency and limited processor speed, but it's well possible to control a large number of PWM signals by a single timer interrupt, particularly if pwm frequency is low (appropriate for LED control).

Simply calculate the time delta up to the next event and program the timer respectively. For time deltas below a certain limit, e.g. 5 or 10 µs, you can stay within the timer interrupt and poll the timer.
 

problem with generating PWM signal usin PIX 12F1501.

Hello everyone,

Can anyone help me with generating pwm signal from pic12f1501.

I followed the PWM configuration procedure described in the data sheet, but the results was rongs.

There are the parameters pwm_frequwency = 8KHz and 8MHz internal oscillator, so I loaded the pr2 reg with 249.

Well the problem is that when I choose a HIGH duty cycle value I don't get the appropriate signal, it generates a square signal which has another frequency = PWM_frequency *2!! and even when i increase the duty cycle it don't change.

But when I choose a low duty cycle value it works correctly until become high.

I will be grateful for your help.

there is my code



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/***********************************************************************
*  PIC 12F1501
*  PWM pin is RA0
*  Oscillator frequency=8MHz
*  PWM frequency = 8KHz
***********************************************************************/
 
void main() 
{
 TRISA=0;
 PORTA=0;
 ANSELA=0;
 
 PWM2CON=0; //clear the PWM2 register
 
 PR2=249;   // period register = 249
 
 PWM2DCH=0;     //duty cycle =0
 PWM2DCL=0;
 
 IRCF0_bit=0;    //prescaler =1
 IRCF1_bit=1;
 IRCF2_bit=1;
 IRCF3_bit=1;
 
 TMR2IF_bit=0;
 
 T2CON=0;
 T2CKPS0_bit=0;
 T2CKPS1_bit=0;
 
 TMR2ON_bit=1;     //start timer2
 
  TMR2IF_bit=0;
  PWM2EN_bit=1;  //PWM2 module enabled
 
 while (!TMR2IF_bit);
 
   TRISA0_bit=0;
  
   PWM2EN_bit=1;
   PWM2OE_bit=1;
   PWM2POL_bit=0;
 
   PWM2DCH=0b11111111;       //loading dutycycle registers
   PWM2DCL=0b00000000;
 
}

 
Last edited by a moderator:

Re: problem with generating PWM signal usin PIX 12F1501.

Do you also want to change duty cycle of PWm signals ? What will be the frequency (common) of the PWM signals generated using timer interrupt ?
 

Re: problem with generating PWM signal usin PIX 12F1501.

Thanks for your reply, yes i want to change PWM duty cycle during the operation.

I want to use PWM module.
 

Now every thing works fine but i have a question.

The pwm2DC is a 10 bit register so I must load it with a value which is between 0 and 1023 ((2^10) -1). Everything works fine unless the duty cycle's value exceed0x3E9 (1000 in decimal).

why 100% duty cycle is equal to 1000 instead 1023.
 

Now every thing works fine but i have a question.

The pwm2DC is a 10 bit register so I must load it with a value which is between 0 and 1023 ((2^10) -1). Everything works fine unless the duty cycle's value exceed0x3E9 (1000 in decimal).

why 100% duty cycle is equal to 1000 instead 1023.

The anser is that I must take care of the PWM resolution
 

In STM8S devices is there option to get 3 PWMs with 3 different frequencies ? In PIC we can't get. If we have 3 PWMs in PIC then all the PWMs will have same frequency. In PIC it uses Timer2 for all the PWM channels.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top