![]() | ![]() | ![]() |
| | |||||||
| Notices |
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink (permalink)) |
| Code: Delay movlw d'39' ; load this to the timer Loop btfss _intcon,2 ; if tmr0 overflow is not set goto Loop ; loop, else skip bcf _intcon,2 ; clear the timer interrupt flag decfsz w,w ; loop until the wreg is zero goto Loop ; it isn't zero so loop return ; zero, so we return Clock speed of 4000000Hz/4 = 1000000hz This 1/4th value is further divided by my pre-scaler of choice /256: 1000000hz/256 = 3906.25hz 3906.25 pulses take 1 second - so to count 10ms delay we need to count when this has tripped over 39 times. To prove this 1/3906.25 = 2.56x10-4 * 39 = 9.98ms. Right or wrong? Is there anything else needed to get the TMR0 overflow to work? Thanks, Mike
__________________ "Ambition is the last refuge of failure..." --Oscar Wilde "Success is not final, failure is not fatal: it is the courage to continue that counts." -- Winston Churchill | |
| | |
| | (permalink (permalink)) | |
| Quote:
Why not simply use the delay code generator on the PICList to generate delay code for you? - it's far more versatile!. Are you sure you are setting everything up correctly?, you've only posted a small piece of the code, so there's no indication of how it's set up at all. | ||
| | |
| | (permalink (permalink)) |
| I move to RPO and have set this: movlw b'10100000' movwf _intcon however by using this delay: Delay clrf _tmr0 tloop movlw d'39' subwf _tmr0,w btfss _status,0 goto tloop return I have got it to work - but it alters tmr0. I could also count 10000 lines of code (big nested loop...) and it'll work... I will settle for the way I've posted above...thanks Mike
__________________ "Ambition is the last refuge of failure..." --Oscar Wilde "Success is not final, failure is not fatal: it is the courage to continue that counts." -- Winston Churchill | |
| | |
| | (permalink (permalink)) |
| Code: ; Delay = 0.01 seconds ; Clock frequency = 4 MHz ; Actual delay = 0.01 seconds = 10000 cycles ; Error = 0 % cblock cnt1 cnt1_1 endc Delay ;9993 cycles movlw 0xCE movwf cnt1 movlw 0x08 movwf cnt1_1 Delay_0 decfsz cnt1, f goto $+2 decfsz cnt1_1, f goto Delay_0 ;3 cycles goto $+1 nop ;4 cycles (including call) return
__________________ "Ambition is the last refuge of failure..." --Oscar Wilde "Success is not final, failure is not fatal: it is the courage to continue that counts." -- Winston Churchill | |
| | |
| | (permalink (permalink)) | |
| Quote:
Don't worry about it, just use it!. | ||
| | |
| | (permalink (permalink)) |
| I took a quick glance at your code. You can't use the ff. sequence because the W register is not a regular file register. Code: decfsz w,w ; loop until the wreg is zero goto Loop ; it isn't zero so loop
__________________ "Having to do with Motion Control" | |
| | |