vacm
unread,Apr 17, 2011, 2:45:32 PM4/17/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ConexionElectronica
Hola, buenas tardes.
Estoy usando MikroBasic para controlar una salida PWM con un
microcontrolador PIC16F876, pero el dato que envía el ADC es de 10
bits, al recibir la informción la dividí entre 4 para que me diera
como máximo 256 cuando el ADC diera 1023, el problema reside en que
quiero representar en porcentaje el valor PWM, pero me da un dato así:
95.983588 y quiero quitarle los decimales, hay alguna forma de
hacerlo?
Dejo una copia del código fuente para que vean si cometí algún error o
si me falta algo.
program PWM_Prueba4
' Declarations section
Dim duty As Word 'Valor de ciclo de pwm
dutyt As String[6] 'Valor de Duty en texto
estado As Byte 'Indica el valor de los botones
DA As Float 'Valor del canal analógico
DATxt As String[6] 'Valor del canal analógico en texto
Dim LCD_RS As sbit At RB4_Bit
LCD_EN As sbit At RB5_Bit
LCD_D4 As sbit At RB0_Bit
LCD_D5 As sbit At RB1_Bit
LCD_D6 As sbit At RB2_Bit
LCD_D7 As sbit At RB3_Bit
'------------------------------
LCD_RS_Direction As sbit At TRISB4_Bit
LCD_EN_Direction As sbit At TRISB5_Bit
LCD_D4_Direction As sbit At TRISB0_Bit
LCD_D5_Direction As sbit At TRISB1_Bit
LCD_D6_Direction As sbit At TRISB2_Bit
LCD_D7_Direction As sbit At TRISB3_Bit
'------------------------------
main: ' Main program
ADCON0 = %00001001 'ponemos a trabajar el canal analógico
ADCON1 = %00001110 'Selección del canal analógico
LCD_Init()
LCD_Cmd(_LCD_Clear)
LCD_Cmd(_LCD_Cursor_Off)
LCD_Out(1,1, "Duty 1: ")
'LCD_Out(2,1, "PWM: ") '
PWM1_Init(5000)
duty = 179
estado = 0
'PWM1_Start()
Loopis:
duty = Adc_Read(0) div 4 '
WordToStr(duty, dutyt) '
LCD_Out(1,10, dutyt) '
DA = (duty / 255)*100
FloatToStr(DA, DaTxt) '
LCD_Chr(2,1, DaTxt[0]) '
LCD_Chr(2,2, DaTxt[1]) '
LCD_Chr(2,3, DaTxt[2]) '
' LCD_Chr(2,3, ".") '
' LCD_Chr(2,4, DaTxt[3]) '
' LCD_Chr(2,5, DaTxt[4]) '
PWM1_Set_Duty(duty)
estado = Button(PORTB,6,50,1)
if estado = 255 then
GoSub IniciaPWM
end if
estado = Button(PORTB,7,50,1)
if estado = 255 then
GoSub DetienePWM
end if
Goto Loopis
IniciaPWM:
PWM1_Start()
Delay_Ms(100)
Return
DetienePWM:
PWM1_Stop()
Delay_Ms(100)
Return
end.
Saludos y de antemano muchas gracias.