PDA

View Full Version : medir duty y frecuencia



callecuatro
- 12th July 2016, 15:39
hola tengo problema con mi código me parpadea la pantalla y no logro una medición estable alguna idea de como mejorarlo y que tenga mas fluidez
DEFINE LCD_DREG PORTC
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 0
define lcd_lines 2
define intosc 4
low portc.2
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
ANSEL = %11111111
ANSELH = %00000000
lectura var word
lectura2 var word
resultado VAR word
resultado2 var word
f var word
bajo VAR WORD
alto VAR WORD
total VAR WORD
duty VAR WORD



lcdout $fe,1," iniciando "
PAUSE 500
LCDOUT $FE, 1

inicio:


ADCIN 1, LECTURA
RESULTADO = (LECTURA */ 500)
adcin 3,lectura2
resultado2 = (lectura2 */500)
PULSIN PORTB.0 , 0 , bajo
PULSIN PORTB.0 , 1 , alto
total=bajo + alto
duty = ( bajo * 100 ) / total
if duty < 5 then duty = 0
if duty > 90 then duty = 100
count portB.0,200,f
f=f *5



paUSE 100
LCDOut $fe , 1
lcdout $fe ,$80 ,"DUTY:" , DEC2 duty ,"%"
LCDOUT $fe , $C0 ,"CPS:" , DEC3 f ,"hz"
LCDOUT $fe, $8a, "V=", DEC (RESULTADO/10),".",dec1 resultado
lcdout $fe,$c9, " A=", dec (resultado2/100),".",dec1 resultado2



GOTO inicio
end

AvionicsMaster1
- 15th July 2016, 01:43
Well, I don't see a chip number in there anywhere and a schematic would be nice. Would be good also if you gave the part number of the display.

I've yet to see the oscillator set using define intosc 4 but I've been wrong recently.

callecuatro
- 16th July 2016, 13:10
perdon pic16f883

callecuatro
- 16th July 2016, 13:18
subo simulacion en proteus y archivos

AvionicsMaster1
- 17th July 2016, 01:06
Well I don't have Proteus so I can't look at your simulation. However define lcd_lines 2 needs to be define LCD_LINES 2. Define can be anything but just like all your other lcd stuff the define itself has to be in upper case.

It looks like you need to do some setting of configs for the oscillator also.

callecuatro
- 25th July 2016, 23:25
Cambie el oscilador a 8mhz y puse en mayúsculas las definiciones lcd y sigue andando mal algún ejemplo para hacerlo con el timer1 voy usar pic16f883

AvionicsMaster1
- 26th July 2016, 13:26
So Google translate is failing me but if you're still using the code from post #1 and using a 16f883 you need to set the OSCCON and maybe the CONFIG1 register. Telling PBP3 to interpret the code at 8 MHZ is done by "define OSC 8" where you've got define intosc 4. The OSCCON register is where you set the chip to run at 8 MHz. If you've updated your code please use the code tags box and post your code.

Sometimes the issue is the LCD so giving the part number of it may help. There are quite a few examples in this forum using timer 1 but I'm not sure why, with above code, you need it. Although some will scream heresy I'd recommend slowing down the display of the values so you can see what's going on. PAUSE 100 may not allow you to see what's happening.

I also think your LCDOUT lines need work. I'm not sure where lines $8a or $c9 are located. At least they're not in the PBP chart. Maybe $80 and $C0 will work better.