Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
;10 - TMR2 module
;Used to materialize a nominal [5 ms] time base. On the next cycle after
;matching PR2, TMR2 resets to 0 and requests an interrupt. The respective ISR
;sets a flag, used by the DECR_COUNTERS routine, called continuously from the
;main loop. Prior exiting the ISR, the interrupt flag is reset. This sequency
;repeats indefinitely.
;******************************************************************************
IF CLOCK ==4000000 ;4 MHz
;With a 4 MHz xtal, the clock feeding TMR2 through the prescaler is
;4/4 MHz = 1 MHz so the Tcy = 1us.
;To get a 5 ms overflow, we need: 5ms/1us = 5.000 counts.
;We make [4*250*5] =5.000 counts (5 ms), so we set:
;prescaler 1:4 - PR2 =250 - postscaler 1:5
BCF T2CON,T2CKPS1 ;0
BSF T2CON,T2CKPS0 ;1 prescaler 1:4
LOADREG PR2,250
BCF T2CON,T2OUTPS3 ;0
BSF T2CON,T2OUTPS2 ;1
BCF T2CON,T2OUTPS1 ;0
BCF T2CON,T2OUTPS0 ;0 postscaler 1:5
BSF T2CON,TMR2ON ;start TMR2
ENDIF
;******************************************************************************
LOADREG MACRO REG,VAL
MOVLW VAL
MOVWF REG
ENDM
'182431 INT 8Mhz TIMER TEST 10.00 14.12.15
'This needs both sides of each H-Bridge pair connected together
Define SIMULATION_WAITMS_VALUE = 1
Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
'PORTC.2 as CCP1 [pwm1] Forward
'PORTC,1 as CCP2 [pwm2] Reverse
'When running in Oshonsoft Sim
'to view PWM use Scope, Normal , Settings, display width 1000
'to check use Hardware UART
ADCON0 = %01000001
ADCON1 = %00000000
OSCCON = %01110010 'internal 8Mhz clock
Dim duty1 As Byte
Dim duty2 As Byte
Dim pwm1 As Byte
Dim pwm2 As Byte
Dim time As Byte
TRISA = %00000001
TRISB = %00000000
TRISC = %10001000
'assign PWM pins
PWMon 1, 8 'RC1 CCP1, Mode at 8MHz at 7812Hz, to change this look at the Manual Tables
PWMon 2, 8 'RC2 CCP2
duty1 = 100
duty2 = 155
'set up timer 1
T1CON.T1CKPS1 = 0 'bits 5 - 4 prescaler rate Select bits
T1CON.T1CKPS0 = 1 ' Bit 4
T1CON.T1OSCEN = 1 ' Bit 3 Timer1 Oscillator Enable Control Bit 1 = On
T1CON.T1SYNC = 1 ' Bit 2 Timer1 External Clock Input Synchronization Control Bit...1 = Do Not synchronize external clock Input
T1CON.TMR1CS = 0 ' Bit 1 Timer1 Clock Source Select Bit...0 = Internal clock (FOSC/4)
'testing only
main:
If RA0 = 1 Then
RB4 = 1
Else
RB4 = 0
Endif
Toggle RB6
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'wait for 10mS
TMR1H = 216
TMR1L = 242 ' Prescale for 10mS
T1CON.TMR1ON = 1
While
PIR1.TMR1IF
Wend
T1CON.TMR1ON = 0
time = time + 1
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
' carry on
If PORTA.3 = 0 Then
PWMduty 2, 0
'ASM: bcf CCP2CON,DC2B0
'ASM: bcf ccp2con,dc2b1
'ASM: movlw 0x00
'ASM: movwf ccpr2l
'Adcin 0, duty1>>>>>>>>>>>>>>>>>>>>>>>>>>>>.Not supported
PWMduty 1, duty1
Endif
If PORTA.3 = 1 Then
PWMduty 1, 0
'ASM: bcf CCP1CON,DC1B0
'ASM: bcf ccp1con,dc1b1
'ASM: movlw 0x00
'ASM: movwf ccpr1l
'Adcin 0, duty1>>>>>>>>>>>>>>>>>>>>>>>Not supported
PWMduty 2, duty1
Endif
Goto main
Sorry for the delay!! Really busy day at work today!!! I am going bald VERY quickly!!
I'm just running through all the data!!! This chip has PWM control... Full H bridge...!!!
You are using CCP1 and CCP2 for your bridge.... Unfortunately TM2 is out of bounds as the CCP modules are using them..
We must use timer 0 timer 1 or timer 5...
Timer 1 isn't the same as timer 2 so I'll need to a bit of homework on this... It's a real shame Oshonsoft doesn't support the PWM modules.... Maybe I could write the low level functions for you!!
I'll get back to you later on this..
To be honest... I don't really know why you need a timer to measure 10mS and not waitms 10..
I should imagine you just need a heartbeat... Each 10mS that passes the time is incremented!!!... Is this what you need??
To be honest... I don't really know why you need a timer to measure 10mS and not waitms 10..
I should imagine you just need a heartbeat... Each 10mS that passes the time is incremented!!!... Is this what you need??