Exact match. Not showing close matches.
PICList
Thread
'[PIC]: Timer Module'
2003\03\18@185737
by
Brent Brown
|
Sid Weaver wrote:
> I understand it is possible to write a program using Timer 0 or Timer
> 1 that runs in the background and generates a square wave. I need a
> square wave at 100 Hz 50% duty cycle to pulse large LCDs.
>
> Can some one tell me how to do this using PBasic, since I don't know
> Assembly. I have the F870, F873, F876 and F877.
Note: [PIC]: tag added to subject. Sounds like an excellent job for
the on-chip PWM module which uses Timer 1. Although it produces ASM
code, have a look at the absolutely brilliant "PWM calculator"
program thant Tony Nixon posted here just last week. At the very
least it will give you a good understanding on how the PWM module
works.
Tony Nixon wrote:
> I just posted a PIC PWM calculator for Windows if anyones interested.
>
> Set the PWM how you want it and the code is copied to the clipboard
> ready for pasting into your ASM file.
>
> http://www.bubblesoftonline.com/demo/picpwm.zip
--
Brent Brown, Electronic Design Solutions
16 English Street, Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile/txt: 025 334 069
eMail: spam_OUTbrent.brownTakeThisOuT
clear.net.nz
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
2003\03\19@035204
by
Jinx
> Sid
>
> If I remember right Pbasic does not have an ON_INTERRUPT
> command nor does it have a HPWM command
Can you use asm routines with Pbasic ? A timer interrupt in asm
would be fairly trivial
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
2003\03\19@060634
by
Timothy Box
|
Yes I agree. When I first thought about it I could see there was a problem
with placing the code in the right place. However a look through the manual
reveals that you can insert it in a file PBH.INC in the INC subdirectory.
I quote
" The interrupt handler itself may be placed in the file PBH.INC in the INC
subdirectory. Near the end of the file is the label Start. This is where the
PICmicro MCU will start executing code on reset, location 0. A few lines
down is a section of code that has been commented out. If this code is
uncommented, it will enable you to insert your interrupt handler at location
4. Place your assembly language interrupt handler routine after the ORG 4.
The routine should end with an RETI instruction to return from the interrupt
and allow the processor to pick up where it left off in your PicBasic
program."
The one last problem is forcing the WSAVE etc variables into the correct
bank to make them available where ever the interrupt gets you. It should be
possible but I have not found it yet.
Still with that in mind you can then use something like this:-
PS This is just the interrupt code not the Basic required to initialise TMR1
to start running interrupt etc.
Tim
MOVWF WSAVE ; SAVE THE W REG
SWAPF STATUS,W ; SAVE THE STATUS REG
CLRF STATUS
MOVWF SSAVE
MOVF PCLATH,W ; SAVE THE PCLATH REG
MOVWF PSAVE
TMR1_VAL =((65536)-(OSC*1250))+7 ; CALCULATE OSC OFFSET VALUES FOR 200HZ
INTERRUPTS (OSC = FREQ IN MHZ)
BCF T1CON,TMR1ON ; TURN OFF TIMER
MOVLW LOW(TMR1_VAL)
ADDWF TMR1L,F ; RELOAD TIMER WITH CORRECT VALUE
BTFSC STATUS,C
INCF TMR1H,F
MOVLW HIGH(TMR1_VAL)
ADDWF TMR1H,F
BSF T1CON,TMR1ON ; TURN IT BACK ON
BTFSS PORTX,X
GOTO SETBIT
BSC PORTX,X ; TOGGLE PORT,X BIT X
GOTO EXIT
SETBIT
BSF PORTX,X
EXIT
BCF PIR1,0 ; CLEAR TMR1 INTERRUPT FLAG
MOVF PSAVE,W ; RESTORE THE PCLATH REG
MOVWF PCLATH
SWAPF SSAVE,W ; RESTORE THE STATUS REG
MOVWF STATUS
SWAPF WSAVE,F
SWAPF WSAVE,W ; RESTORE W REG
RETFIE ; EXIT THE INTERRUPT ROUTIN
{Original Message removed}
2003\03\19@075522
by
Olin Lathrop
> Note: [PIC]: tag added to subject. Sounds like an excellent job for
> the on-chip PWM module which uses Timer 1.
Actually, it uses timer 2.
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
2003\03\19@164720
by
Brent Brown
> > Note: [PIC]: tag added to subject. Sounds like an excellent job for
> > the on-chip PWM module which uses Timer 1.
>
> Actually, it uses timer 2.
>
Doh!
--
Brent Brown, Electronic Design Solutions
16 English Street, Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile/txt: 025 334 069
eMail: .....brent.brownKILLspam
@spam@clear.net.nz
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
More... (looser matching)
- Last day of these posts
- In 2003
, 2004 only
- Today
- New search...