I'm new to flowcode and need a little help
i used to use proton ide to program a 12f615 with 2 pwm output's (same frequency but 180 deg's out of phase) using pins (5&7)
how do i this with flowcode?
12f615 Pwm
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: 12f615 Pwm
Hello,
To do this you simply create a program using the PWM component if the device supports 2 hardware PWM channels or using a software method as shown here.
http://www.matrixmultimedia.com/article.php?a=52
To do this you simply create a program using the PWM component if the device supports 2 hardware PWM channels or using a software method as shown here.
http://www.matrixmultimedia.com/article.php?a=52
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: 12f615 Pwm
Normally when using the pwm, even if pwm 1 and pwm2 are set at different duties (if chip has at least 2 pwm channels). Then both ports connected to PWM (CCP1 and CCP2) go high in value when internal register TMR2 rolls over from 255 to 0. when TMR2 equals internal CCPR1L (assuming 8 bit pwm is used) then CCP1 pin goes low. or in the case of 2 pwms when TMR2 equals internal CCPR2L (again assuming 8 bit pwm is used) then CCP2 pin goes low. The only way these can be inverted is by using a chip with half bridge function
Using 12F615, since there is not a PWM half bridge arrangement, there will be two ways round this.
1) Use some clever custom code embedded within the PWM component (although that's a pure guess of course). You cant read the port register since that is not controllng the pin for PWM. Thats a pity since it would make this project a lot eaiser
)
2) Use Bit bang PWM. can be done and there are numerous example on this. but more difficult to control.
A good bit bang software control PWM can be found here:
http://www.matrixmultimedia.com/mmforum ... 891#p22891
Then its a simple case of bit for PortA0 =! bit for PortA5 which means if A0=1 then A5=0 or if A0=0 then A5=1 Etc
I Have decided to give option 1 a try. Although I can't do the clever custom part. I have used a bit of C code embedded in timer 0 interrupt.
The idea is the timer interrupt would activate much faster than PWM, so would keep checking the internal registers that control PWM o/p.
Since the flowchart usies the PWM component, you should be able to alter its duty or frequency much easier than bit bang method.
You have not stated the OSC or pwm frequency, so the for the former i have just used the internal 8MHz osc.
As for the frequency I have just randomly thought of a number and used that.
The duty is variable from 0 to 100%.
The o/p from GP0 should be inverted to GP5.
If you have a OSC frequency, and type eg. internal/external etc., PWM frequcey and duty in mind then im sure I could adjust the flowchart to suit your needs.
That's if works the way you have intended of course.
Note: Because I'm using a bit of C, the inverse port function will not simulate. Therefore I have attached a screen shot from a simulator that runs form hex generated files.: Martin
Using 12F615, since there is not a PWM half bridge arrangement, there will be two ways round this.
1) Use some clever custom code embedded within the PWM component (although that's a pure guess of course). You cant read the port register since that is not controllng the pin for PWM. Thats a pity since it would make this project a lot eaiser
2) Use Bit bang PWM. can be done and there are numerous example on this. but more difficult to control.
A good bit bang software control PWM can be found here:
http://www.matrixmultimedia.com/mmforum ... 891#p22891
Then its a simple case of bit for PortA0 =! bit for PortA5 which means if A0=1 then A5=0 or if A0=0 then A5=1 Etc
I Have decided to give option 1 a try. Although I can't do the clever custom part. I have used a bit of C code embedded in timer 0 interrupt.
The idea is the timer interrupt would activate much faster than PWM, so would keep checking the internal registers that control PWM o/p.
Since the flowchart usies the PWM component, you should be able to alter its duty or frequency much easier than bit bang method.
You have not stated the OSC or pwm frequency, so the for the former i have just used the internal 8MHz osc.
As for the frequency I have just randomly thought of a number and used that.
The duty is variable from 0 to 100%.
The o/p from GP0 should be inverted to GP5.
If you have a OSC frequency, and type eg. internal/external etc., PWM frequcey and duty in mind then im sure I could adjust the flowchart to suit your needs.
That's if works the way you have intended of course.
Note: Because I'm using a bit of C, the inverse port function will not simulate. Therefore I have attached a screen shot from a simulator that runs form hex generated files.: Martin
- Attachments
-
- PWM & 180 inv.fcf
- (7 KiB) Downloaded 397 times
Martin
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: 12f615 Pwm
Your welcome. So long as it did help (and works on hardware of course )that's the main thing.CubyteJ wrote:thanks for the example it's a great help
There will be a point when it does not work so well as you increase PWM frequency above a certain value(do not know the maximum frequency of PWM will be)
Timer0 frequency can be increased more to compensate but there will be limits.
So it worked on your hardware the way you wanted it to?
Martin
Martin
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: 12f615 Pwm
The way I achieved the desired effect as stated earlier is to check if tmr2>ccpr1l etc.
I checked with a scope and this does work well if lower PWM frequencies are used.
If frequency is about 4KHz then is a small time delay of about 20uS
Between CCP1 going high and GP0 going low etc.
Even with tmr0=+220;
Is there a better method?
My idea is to use custom code and as soon as flag for port CCP1 changes, then use GP0=!ccp1.
Does anyone know how this custom code can be placed.
I believe since tmr2 is auto running all the time due to osc, then where the code is placed should be where the actual comparing takes place.
Placed anywhere else like timer0 or main etc., then there will be some delay.
Thanks
Martin
If frequency is about 4KHz then is a small time delay of about 20uS
Between CCP1 going high and GP0 going low etc.
Even with tmr0=+220;
Is there a better method?
My idea is to use custom code and as soon as flag for port CCP1 changes, then use GP0=!ccp1.
Does anyone know how this custom code can be placed.
I believe since tmr2 is auto running all the time due to osc, then where the code is placed should be where the actual comparing takes place.
Placed anywhere else like timer0 or main etc., then there will be some delay.
Thanks
Martin
Martin