View Full Version : 12F683, 12LF1840 - Port ON/OFF speeds are different!
CuriousOne
- 3rd February 2015, 11:20
Hello.
I'm building an push-pull converter driver using these chips. The code is as follows:
'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:
7706
Any ideas how to fix this?
richard
- 3rd February 2015, 11:42
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
CuriousOne
- 3rd February 2015, 11:50
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.
CuriousOne
- 3rd February 2015, 11:52
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.
pedja089
- 3rd February 2015, 14:10
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...
CuriousOne
- 3rd February 2015, 16:28
Even if code is like this:
HEAD:
PORTA.2=1
PORTA.2=0
GOTO HEAD
the "goto" occupies much more time. Is there a way to shorten it?
HenrikOlsson
- 3rd February 2015, 16:39
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.
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.
Gusse
- 3rd February 2015, 17:25
How about if you toggle pin in loop?
HEAD:
TOGGLE PORTA.2
GOTO HEAD
CuriousOne
- 3rd February 2015, 19:22
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
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?
Heckler
- 3rd February 2015, 20:04
Have you considered doing this in assembly??
pedja089
- 3rd February 2015, 20:05
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....
Gusse
- 3rd February 2015, 20:47
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.
CuriousOne
- 4th February 2015, 03:52
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?
Gusse
- 4th February 2015, 07:12
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).
pedja089
- 4th February 2015, 07:56
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 (http://ww1.microchip.com/downloads/en/DeviceDoc/41365E.pdf) 404 pages and you will know everything you need :)
CuriousOne
- 4th February 2015, 09:36
Another guess is that PIC18F14K22 won't be available in SOIC-8.... :D
HenrikOlsson
- 4th February 2015, 10:15
Take a look at the 12F1501, it might do what you want and comes in 8pin package.
Acetronics2
- 4th February 2015, 14:35
the 1840 in ECCP half bridge mode looks to be fine too, no ???
Alain
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.