View previous topic :: View next topic |
Author |
Message |
dslapo
Joined: 06 Apr 2004 Posts: 2
|
18FXX31 PWM TIME BASE INTERRUPS |
Posted: Fri Aug 27, 2004 12:48 pm |
|
|
I am writing PWM code to drive LED's. I would like to us an interrup to help me to know when to update the duty cycle register. How do I read PTMOD AND PTOPS? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
Reading/Writing Internal Registers |
Posted: Fri Aug 27, 2004 1:38 pm |
|
|
See the CCS manual FAQ section on Reading/Writing internal registers on page 213
All the interrupts and PWM settings are defined in the chip header file 18F4331.h etc.
According to the data sheet the PTMOD and PTOPS bits are in register PTCOM0 at 0xF7F in the 18F4331 chip |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 27, 2004 1:42 pm |
|
|
Quote: | How do I read PTMOD AND PTOPS ? |
Create a structure with bitfields. Then define the memory address
of that register with the #locate statement. (Or, the #byte statement
would work as well, in this case). Then you can read or write to the
register bits, just as if they were memory variables.
Remember that when you read a bitfield, the compiler will right-justify
the result.
Code: | #include <18F4431.H>
#fuses XT, NOPROTECT, PUT, NOBROWNOUT, NOWDT, NOLVP
#use delay(clock=4000000)
struct
{
unsigned char ptmod:2;
unsigned char ptckps:2;
unsigned char ptops:4;
}PTCON0;
#locate PTCON0 = 0xF7F
//=================================
main()
{
char value;
value = PTCON0.ptops;
value = PTCON0.ptmod;
while(1);
}
|
|
|
|
dslapo
Joined: 06 Apr 2004 Posts: 2
|
18FXX31 PWM TIME BASE INTERRUPS |
Posted: Fri Aug 27, 2004 2:20 pm |
|
|
Thank you for your time.
Dave |
|
|
|