Gday,
Thanks for your reply. I am testing some of your methods. I have a few queries.
1. This voltage i require is to be read by a vehicle ecu. If you use PWM will it see that as a voltage or will it see the pulses?
2. I have put together some code to test the PWM output. It is giving a PWM signal as expected but when I input a figure in a terminal it does not put the same figure to the display or PWM output. It does change but not as expected. Any ideas why?
Thanks
INCLUDE "modedefs.bas" ' Include serial modes
SI VAR PORTB.1 ' Serial Input pin
B0 VAR BYTE
Define OSC 10
Define LCD_DREG PORTA ' RA0..3
Define LCD_DBIT 0
Define LCD_RSREG PORTA ' RA6
Define LCD_RSBIT 6
Define LCD_EREG PORTA ' RA4
Define LCD_EBIT 4
Define LCD_BITS 4
TRISA = 0
TRISB = 0
CMCON = 7
Pause 1000 ' Wait for LCD to startup
duty VAR WORD ' Duty cycle value (CCPR3L:CCP3CON<5:4>)
TRISB.3 = 0 ' Set PORTB.5 (CCP3) to output
CCP1CON = %00001100 ' Set CCP3 to PWM
T2CON = %00010101 ' Turn on Timer2, Prescale=4
' Use formula to determine PR2 value for a 1KHz signal,
' 4MHz clock, and prescale=4. (4E6/(4*4*1E3))-1=249
PR2 = 249 ' Set PR2 to get 1KHz out
' Use formula to determine CCPR3L:CCP3CON<5:4> value for
' ends of range 20% to 80%. (249+1)*4*0.2=200 (20% value)
' (249+1)*4*0.8=800 (80% value)
duty = 200 ' Set duty cycle to 20%
loop: SerIn SI,T9600,duty
CCP1CON.4 = duty.0 ' Store duty to registers as
CCP1CON.5 = duty.1 ' a 10-bit word
CCPR1L = duty >> 2
'duty = duty + 5 ' Increase duty cycle
LCDOut $FE,1 ' Clear LCD screen
LCDOut # duty ' Display line 1
pause 1000
' Since the total sweep of duty is 600 (800-200) and
' we are adding 10 for each loop, that results in 60
' steps min to max. 1 second divided by 60 = 16.67mS
Pause 17 ' Pause 1/60 of second
'IF (duty < 900) Then loop ' Do it again unless 80% duty cycle
'duty = 200 ' Reset to 20% duty cycle
GoTo loop ' Do it forever




Bookmarks