-
1 Attachment(s)
12F683, 12LF1840 - Port ON/OFF speeds are different!
Hello.
I'm building an push-pull converter driver using these chips. The code is as follows:
Code:
'PUSH PULL DRIVER
ANSELA = %00000000 'TURN OFF ANALOG
TRISA=%00000000 'SET PORTS TO OUTPUT
OSCCON = %11111111 'SET INTOSC TO 32MHZ
tavuka:
PORTA.2=1
PORTA.2=0
PORTA.4=1
PORTA.4=0
GOTO TAVUKA
The problem is, that measured port OFF times are longer than ON times, as you can see on attached scope:
Attachment 7706
Any ideas how to fix this?
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
Quote:
OSCCON = %11111111 'SET INTOSC TO 32MHZ
looks wrong
OSCCON = %11110000 'SET INTOSC TO 32MHZ would be more appropriate assuming int osc and pll
porta.x = y on a 12f1840@32mhz is just asking for trouble use lata.x=y
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
Yes, config is wrong, but problem is same at ANY clock speed.
Tried with LATA - no difference. ON time is about 220ns, OFF time is about 760ns. In terms of PWM, this means 50% duty, so another 50% is simply wasted.
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
As I see, this is caused by loop, which returns program to beginning.
For example, I've tried to lengthen code by repeating commands 4 times without using loop, and 4 pulses are correct.
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
I hope that you are kidding with us...
Here is your code explained:
tavuka:
PORTA.2=1'<turn on PORTA.2, need 4 osc clock to do that, then next instruction
PORTA.2=0'<turn off PORTA.2 need 4 osc clock to do that, then next instruction
PORTA.4=1'<4 clock to do this, but it doesn't do anything with PORTA.2
PORTA.4=0'<4 clock to do this, but it doesn't do anything with PORTA.2
GOTO TAVUKA '<4 or 8 clocks(can remember) to do this, but it doesn't do anything with PORTA.2
So when you count all clock, you have 4 osc clock long high state on PORTA,2, and 16 clock low state on PORTA.2.
Similar situation is with PORTA.4...
Program execute exactly what you are tell, Not what you want...
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
Even if code is like this:
Code:
HEAD:
PORTA.2=1
PORTA.2=0
GOTO HEAD
the "goto" occupies much more time. Is there a way to shorten it?
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
No, there's not way to shorten the execution time (in instruction cycles that is) of a GOTO. What you can do is to "lengthen" the time of the other instructions.
Code:
Head:
PortA.2 = 1
@ NOP ' Two nops to compensate for the GOTO
@ NOP
PortA.2 = 0
GOTO Head
Obviously this will also change the frequency.
/Henrik.
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
How about if you toggle pin in loop?
Code:
HEAD:
TOGGLE PORTA.2
GOTO HEAD
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
I don't want to "lengthen" time, because it significantly lowers the frequency, from about 1mhz to 200khz, which is bad. I've found a partial workaround - I've inserted
Code:
PORTA.2=1
PORTA.2=0
PORTA.4=1
PORTA.4=0
16 times, so now having about 90% duty cycle, which is ok.
But, is there a way to fix this otherwise?
Try 18 series PIC, or 24 series?
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
Have you considered doing this in assembly??
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
It's same thing in ASM.
ASM
tavukaASM:
BSF PORTA,2
BCF PORTAM2
BSF PORTA,4
BCF PORTA,4
GOTO tavukaASM
ENDASM
That is ASM code equivalent of his PBP code.
Still same situation....
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
Would it be easier to do this with PWM module? With 32MHz you can reach 4MHz output frequency and accurate duty cycle.
I think these PIC's have just one PWM module. If that is not enough, then select other which have more PWM outputs.
At least, trials can be run with your current PIC's.
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
Well, I asked that before...
I use 2 channels as you can see from scope, and I need to have adjustable dead time between outputs, to avoid short circuit. Is it possible to synchronise 2 PWM generators in that way?
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
I think that you will not be able to do phase shift (delay) between 2 PWM outputs in same PIC. With 2 PIC's this might bee possible.
If your system is so time critical that GOTO-command will generate problems then how you will monitor and adjust outputs?
Therefore I don't see any other options than using HW modules (PWM) and PIC code just monitor and control HW module(s).
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
With another pic, it can be done easy.
PIC18F14K22 have everything what you need:
Enhanced Capture/Compare/PWM (ECCP)
module:
- One, two or four PWM outputs
- Selectable polarity
- Programmable dead time
- Auto-shutdown and Auto-restart
- PWM output steering control
And all that controlled from comparators outputs.
If comparator output is low or high(selectable) pwm outpu can go to some state, high or low.
You can turn on/off hysteresis on comparators, etc...
Just read this 404 pages and you will know everything you need :)
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
Another guess is that PIC18F14K22 won't be available in SOIC-8.... :D
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
Take a look at the 12F1501, it might do what you want and comes in 8pin package.
-
Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!
the 1840 in ECCP half bridge mode looks to be fine too, no ???
Alain