Beruflich Dokumente
Kultur Dokumente
t=21092&start=15
1 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
Author Message
Question then....does it need to be a buffered register that the data comes into? if you are loading the
Joined: 29 Nov 2004
Posts: 4 comparator at the same instant its comparing to the counter could it produce a glitch in the comparator
Location: PA output? Next...for Dave's sake, if you want to consider doing it this way, the cpld chips are pretty cheap i
think...the way I went was with the free Xilinx webpack like you mentioned. There is a little programming
dongle that costs $95 that you use program the chip from the webpack software on your PC . Also, the
webpack software allows you to create your logic a few different ways. One way is by writing code in VHDL
or Verilog, but there is also a whole graphical interface that allows you to actually create your logic
graphically, just like you would a schematic of logic gates, etc. you literally pick and place little logic
symbols on your screen and connect them with lines like your drawing a schematic. Then you download it
to the chip. Its actually very cool and extremely easy. I guess doing that way is a little like programming in
Visual Basic as opposed to assembler...its quick and easy but not necessarily the most resourceful or
streamlined way...that is what I have heard, but for my apps. it has worked great. Maybe someone else has
more input on this. You can find all the info you need and chips and parts on Xilinx.com
I've done an 8-channel PWM on a PIC16F877, running at 60hz. Wouldn't you want to use 60Hz, if these
Joined: 17 Sep 2003
Posts: 46 lamps run off the power line? Mine had a resolution of 1%, but it could have been more.
250KHz is a brisk data rate, but I think it's workable. My approach is usually to set up a timer running as
fast as needed to catch every incoming character by polling, interrupting only on the timer. The characters
just get stuffed into a buffer, for processing outside the interrupt. Then the other thing the timer does is get
divided down to whatever you need to run the outputs, and calculate whether a given output needs to
change or not. Since there are 8 outputs, you could have a register associated with each one, which would
be its turn-off time, or 0 if it never turned on. So every timer tick, you'd check the 8 registers to see
whether any changes were needed in the outputs. At tick 0, you'd turn on every output whose register held
a non-zero value.
John, sorry, I have drifted off the original posting a little, but it was a question of producing 24 pwm
channels at about 2Khz i think...dont think he is intending on using it for a dimmer, but he didnt say...I was
just relating it to a pwm application I did once that was for AC dimmers and recieved DMX like he also
wants to do. I'm sure that with a 40Mhz PIC and enough tweeking of code he could make 8 channels work.
I was trying to think of some other options that would give him more headroom. He needs 24 channels of
PWM, so he will obviousely need a multi-chip solution I think.
I have never tried receiving asyncronous data by polling the receiver. It would seem like you would have to
pole at several times the frame rate of the data coming in in order to guarantee you'll catch each byte. I
guess that might work up to a certain number of PWM channels. If you want 8 bit resolution, your clock
ticks have to be at a frequency 256 times as fast as your duty cycle right? and you have to update all your
registers within the time of each of those ticks.
One thing that DMX does have going for it in his favor is that each channel value is sent only once per
packet, and there is usually a small amount of idle time (maybe a few milliseconds) before the next packet
comes along. I have used this time before to do any data processing I have, so that on top of the
timing-critical pulse shaping thats going on, I'm only doing one other thing at any given time...either
receiving data, or processing it. It all comes down to a question of do you have enough bandwidth around
your PWM routines to take care of everything else in a timely fashion. Anyway, if you read the first few
posts your get an idea of what he needs.
Dave
2 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
One Hundred Hertz is the typical "no visible flicker" frequency. I am more inclined to believe that
Joined: 07 Sep 2003
Posts: 3511 100Hz-500Hz is doable in a single PIC. Are you limited to just the 16 series or do you have the PCH
Location: Atlanta, GA compiler for the 18's
Quote:
Joined: 06 Sep 2003
Posts: 6766 I am dimming Led's so am using PWM - or maybe someone can advise an alternative?
Mark
Joined: 07 Oct 2003
Posts: 76
Location: England I have PCW 3.21 so I should be OK.
Can you give me a bit more detailed explanation of how to set up for the multiple PWM's.
Dave
Did a little testing today and at 20MHz a PIC18 was a bit stressed with the default int handler. I test it with
Joined: 07 Sep 2003
Posts: 3511 a custom one tomorrow and see how it goes. I'll post you some code to go along with it.
Location: Atlanta, GA
Okay, here is a program that will receive the first 24 channels of a DMX stream and generate 24 8bit 200Hz
Joined: 07 Sep 2003
Posts: 3511 PWM's. You could probably up it just a bit more with the present 20MHz clock or a lot more if you run it at
Location: Atlanta, GA 40MHz (which is what I would do but didn't have a board with that value for testing). I tried to comment
best I could and refrained from using assmebler for the most part
The C file
Code:
3 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
#CASE
#include "18F252_.h"
/* This is the frequency of the PWM. To find out the max frequency,
you should sum the max time of the CCP2 isr and the DMX recv int
Now multiply that by 256 and that will give you the period. */
#define PWM_FQ 200
/****************************************************************************
* Card IO *
****************************************************************************/
/* This was the IO for a card I did some testing with. You will need to
setup the IO per your hardware. */
/*
The IO on this card is as follows:
RA0 - RA5 - Used to test the PWMs
4 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
/****************************************************************************
* ISR Save Variables *
****************************************************************************/
int16 fsr0_save;
#locate fsr0_save = 0x05
int8 W_save;
#locate W_save = 0x07
int8 STATUS_save;
#locate STATUS_save = 0x08
int8 BSR_save;
#locate BSR_save = 0x09
int8 SCRATCH3_save;
#locate SCRATCH3_save = 0x0A
typedef struct
{
int16 pwm_value;
int8 outputs[MAX_PWM_ARRAY];
}PWM_LIST_TYPE;
typedef struct
{
int8 level;
int8 channel;
}LEVEL_LIST_TYPE;
int1 Check_Levels=0;
int1 Use_PWM_List1=1;
int1 ISR_using_PWM_List1=1;
/****************************************************************************
* DESCRIPTION: Function for comparing 2 items in an array
* RETURN: (-1) if item1 < item2
* ( 0) if item1 = item2
* (+1) if item1 > item2
* ALGORITHM: none
* NOTES: none
****************************************************************************
*/
signed int8 compare(
LEVEL_LIST_TYPE *arg1, // Item 1 from the array
LEVEL_LIST_TYPE *arg2) // Item 2 from the array
{
if (arg1->level < arg2->level)
return (-1);
else if (arg1->level == arg2->level)
return (0);
else
return (1);
}
/****************************************************************************
* DESCRIPTION: Modified insertion sort for sorting our levels in ascending
* order
* RETURN: none
* ALGORITHM: none
* NOTES: none
****************************************************************************
*/
void isort(
LEVEL_LIST_TYPE *base, // point to the list to sort
int8 nmemb, // number of elements in list
int8 size) // size of each element
{
LEVEL_LIST_TYPE *i, *j, *lim;
5 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
{
char *a, *b;
char tmp;
int8 k;
k = sizeof(base[0]);
a = (char*)j;
b = a + sizeof(base[0]);
do
{
tmp = *a;
*a++ = *b;
*b++ = tmp;
} while (--k);
if (j == base)
break;
}
}
}
/* *************************************************************************
DESCRIPTION: This function clears a bit in an array of byte(s).
RETURN: none
ALGORITHM: none
NOTES: none
****************************************************************************/
void clear_bit(
int8 *p, // pointer to the array of bits
int8 b) // which bit to clear
{
int8 index;
index = b / 8;
b &= 0b00000111;
*(p + index) &= ~(1<<b);
}
/* *************************************************************************
DESCRIPTION: This function computes the ccp values for our DMX levels
RETURN: none
ALGORITHM: none
NOTES: none
****************************************************************************/
void compute_pwm_values(PWM_LIST_TYPE *PWM_List)
{
int8 i, j, level, outputs[MAX_PWM_ARRAY];
LEVEL_LIST_TYPE level_list[MAX_PWMS];
PWM_LIST_TYPE *ptrList;
/* find all the outputs that are off. This will be our starting mask */
i = 0;
while ((level_list[i].level == 0) && (i < MAX_PWMS))
{
clear_bit(outputs, level_list[i].channel);
i++;
}
PWM_List[0].pwm_value = 0xFFFF;
6 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
W = level;
#asm
mullw PWM_STEP
#endasm
ptrList->pwm_value = PROD;
ptrList++;
}
/* Store the output mask. Note that we always set the ccp
value to the max to prevent the ccp2 int from firing once
we are done. The outputs are set at the same time the next
ccp value is set. Therefore, if this were the last output
then we would not want the ccp to fire again. */
ptrList->pwm_value = 0xFFFF;
for (j=0;j<MAX_PWM_ARRAY;j++)
ptrList->outputs[j] = outputs[j];
}
}
/****************************************************************************
* DESCRIPTION: This is the "main" function. It performs the proper
* initialization, then starts the main loop of the program.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void main(void)
{
int8 i;
int1 time_to_update=0;
/* Setup our IO */
setup_adc_ports( NO_ANALOGS );
set_tris_a(PORT_A_TRIS_MASK);
set_tris_b(PORT_B_TRIS_MASK);
set_tris_c(PORT_C_TRIS_MASK);
/* Don't worry about enabling CCP2 just yet, the CCP1 int will
take care of that */
enable_interrupts(INT_CCP1);
/* Setup timer1 */
set_timer1(0);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while (1)
{
/* After each data packet, the receive int will set this flag
to allow us to check for a change. Not the most efficient means
but it works. We could check for a difference in the int and set
a flag if we need more horsepower in the main loop at a sacrifice
of a few more instructions in the receive int */
if (Check_Levels)
{
7 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
Check_Levels = 0;
for (i=0;i<MAX_PWMS;i++)
{
if (DMX_Levels[i] != Rx_Buffer[i])
{
DMX_Levels[i] = Rx_Buffer[i];
time_to_update = 1;
}
}
/* Some levels had changed so we need to get new ccp values */
if (time_to_update)
{
time_to_update = 0;
/* Now we really can't change the ccp values that the int
is using so we have another set to load while the int
is using the first set. */
if (Use_PWM_List1)
{
/* Here we are waiting until the ISR gets the right pointer.
we might have told the isr to use it but it was still using
the last set so we need to wait until the isr sets its pointer */
while(!ISR_using_PWM_List1);
compute_pwm_values(PWM_List2);
Use_PWM_List1 = 0;
}
else
{
/* Wait until the ISR gets the right pointer */
while(ISR_using_PWM_List1);
compute_pwm_values(PWM_List1);
Use_PWM_List1 = 1;
}
}
}
} /* end of forever loop */
}
/****************************************************************************
* ISR routines *
****************************************************************************/
/****************************************************************************
* DESCRIPTION: CCP2 int is responsible for turning off outputs and loading
* the next turn off point. This is the pulse width control.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void ccp2_isr(void)
{
/* Get the next set of values */
ptrPWM_List++;
/****************************************************************************
* DESCRIPTION: This int controls the period of our PWM's and loads the
* initial turn off point for the pwm's
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void ccp1_isr(void)
{
clear_interrupt(INT_CCP1);
8 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
else
{
ptrPWM_List = PWM_List2;
/* Notify the main loop that we are not using the
PWM_List1 values. */
ISR_using_PWM_List1=0;
}
enable_interrupts(INT_CCP2);
}
/****************************************************************************
* DESCRIPTION: Receives DMX data stream
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void dmx_rcv(void)
{
/* Our different receive states */
#define WAIT_FOR_NEXT_BYTE 0
#define WAIT_FOR_BREAK 1
#define WAIT_FOR_START 2
#define RECEIVE_DATA 3
/* State machine for determining the begining of the DMX stream */
static int8 Rx_State = WAIT_FOR_BREAK;
switch (Rx_State)
{
case WAIT_FOR_NEXT_BYTE:
if (!rcsta.bits.FERR)
Rx_State = WAIT_FOR_BREAK;
break;
case WAIT_FOR_BREAK:
/* Check for a framing error */
if (rcsta.bits.FERR)
9 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
{
/* If we did receive a framing error, make sure that the data is 0.
This means that we did Rx the break signal for at least 44us. */
if (!data)
Rx_State = WAIT_FOR_START;
}
break;
case WAIT_FOR_START:
/* Check for a framing error. If we receive one then we need to wait
until we receive a good data byte before we begin looking for our
Break signal */
if (rcsta.bits.FERR)
Rx_State = WAIT_FOR_NEXT_BYTE;
/* The start code for our data packet should always start with 0. */
else
{
if (!data)
{
/* Initialize our pointer to our Rx buffer. */
ptr_Rx = Rx_Buffer;
Rx_State = RECEIVE_DATA;
}
else
Rx_State = WAIT_FOR_BREAK;
}
break;
case RECEIVE_DATA:
/* check for framing error - if we receive a framing error then this
might be the begining of the next packet or a true framing error. */
if (rcsta.bits.FERR)
{
/* if this is the beginging of the next frame then data must = 0
else this is a framing error. */
if (!data)
Rx_State = WAIT_FOR_START;
else
Rx_State = WAIT_FOR_NEXT_BYTE;
}
else
{
/* Store the data received in the Rx buffer */
*ptr_Rx = data;
/****************************************************************************
* DESCRIPTION: The int handler for high priority interrupts
* PARAMETERS: none
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void Int_Handler_High(void)
{
/* Currently these ints only use FSR0 and register 3
so that is all that we need to save */
fsr0_save = FSR0;
SCRATCH3_save = *(0x03);
/* restore data */
FSR0 = fsr0_save;
*(0x03) = SCRATCH3_save;
#asm
retfie 1
#endasm
10 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
#org 0x08,0x0A
/****************************************************************************
* DESCRIPTION: Wrapper for the high priority interrupt
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void Int_Handler_High_Wrapper(void)
{
Int_Handler_High();
}
/****************************************************************************
* DESCRIPTION: The int handler for low priority interrupts
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#org 0x18,0x48
void Int_Handler_Low(void)
{
#asm
movwf W_save
#endasm
STATUS_save = STATUS;
fsr0_save = FSR0;
BSR_save = BSR;
BSR = BSR_save;
FSR0 = fsr0_save;
#asm
movf W_save,W
#endasm
STATUS = STATUS_save;
#asm
retfie 0
#endasm
#ifndef 18F252_H
#define 18F252_H
/********************************************************************** I/O
Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
PORT_B_PULLUPS(), INPUT(),
OUTPUT_LOW(), OUTPUT_HIGH(),
OUTPUT_FLOAT(), OUTPUT_BIT()
Constants used to identify pins in the above are:
***************************************************************************/
#define PIN_A0 31744
#define PIN_A1 31745
#define PIN_A2 31746
#define PIN_A3 31747
#define PIN_A4 31748
#define PIN_A5 31749
11 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
union {
struct {
unsigned char ADON:1;
unsigned char UNUSED0:1;
unsigned char GO:1;
unsigned char CHS0:1;
unsigned char CHS1:1;
unsigned char CHS2:1;
unsigned char ADCS0:1;
unsigned char ADCS1:1;
};
struct {
unsigned char UNUSED1:2;
unsigned char NOT_DONE:1;
};
struct {
unsigned char UNUSED2:2;
unsigned char DONE:1;
};
struct {
unsigned char UNUSED3:2;
unsigned char GO_DONE:1;
};
} ADCON0bits ;
#locate ADCON0bits=0x0FC2
struct {
unsigned char PCFG0:1;
unsigned char PCFG1:1;
unsigned char PCFG2:1;
unsigned char PCFG3:1;
unsigned char UNUSED:2;
unsigned char ADCS2:1;
unsigned char ADFM:1;
} ADCON1bits ;
#locate ADCON1bits=0x0FC1
union {
struct {
unsigned char CCP1M0:1;
unsigned char CCP1M1:1;
unsigned char CCP1M2:1;
unsigned char CCP1M3:1;
unsigned char CCP1Y:1;
unsigned char CCP1X:1;
};
struct {
unsigned char UNUSED:4;
unsigned char DC1B0:1;
unsigned char DC1B1:1;
};
} CCP1CONbits ;
#locate CCP1CONbits=0x0FBD
union {
12 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
struct {
unsigned char CCP2M0:1;
unsigned char CCP2M1:1;
unsigned char CCP2M2:1;
unsigned char CCP2M3:1;
unsigned char CCP2Y:1;
unsigned char CCP2X:1;
};
struct {
unsigned char UNUSED0:4;
unsigned char DC2B0:1;
unsigned char DC2B1:1;
};
struct {
unsigned char UNUSED1:5;
unsigned char DCCPX:1;
};
} CCP2CONbits ;
#locate CCP2CONbits=0x0FBA
struct {
unsigned char RA0:1;
unsigned char RA1:1;
unsigned char RA2:1;
unsigned char RA3:1;
unsigned char RA4:1;
unsigned char RA5:1;
unsigned char RA6:1;
unsigned char RA7:1;
} DDRAbits ;
#locate DDRAbits=0x0F92
struct {
unsigned char RB0:1;
unsigned char RB1:1;
unsigned char RB2:1;
unsigned char RB3:1;
unsigned char RB4:1;
unsigned char RB5:1;
unsigned char RB6:1;
unsigned char RB7:1;
} DDRBbits ;
#locate DDRBbits=0x0F93
struct {
unsigned char RC0:1;
unsigned char RC1:1;
unsigned char RC2:1;
unsigned char RC3:1;
unsigned char RC4:1;
unsigned char RC5:1;
unsigned char RC6:1;
unsigned char RC7:1;
} DDRCbits ;
#locate DDRCbits=0x0F94
struct {
unsigned char RD0:1;
unsigned char RD1:1;
unsigned char RD2:1;
unsigned char RD3:1;
13 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
struct {
unsigned char RG0:1;
unsigned char RG1:1;
unsigned char RG2:1;
unsigned char RG3:1;
unsigned char RG4:1;
} DDRGbits ;
#locate DDRGbits=0x0F98
struct {
unsigned char RH0:1;
unsigned char RH1:1;
unsigned char RH2:1;
unsigned char RH3:1;
unsigned char RH4:1;
unsigned char RH5:1;
unsigned char RH6:1;
unsigned char RH7:1;
} DDRHbits ;
#locate DDRHbits=0x0F99
struct {
unsigned char RJ0:1;
unsigned char RJ1:1;
unsigned char RJ2:1;
unsigned char RJ3:1;
unsigned char RJ4:1;
unsigned char RJ5:1;
unsigned char RJ6:1;
unsigned char RJ7:1;
} DDRJbits ;
#locate DDRJbits=0x0F9A
14 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
} EECON1bits ;
#locate EECON1bits=0x0FA6
struct
{
unsigned char RBIF:1;
unsigned char INT0F:1;
unsigned char T0IF:1;
unsigned char RBIE:1;
unsigned char INT0E:1;
unsigned char T0IE:1;
unsigned char PEIE:1;
unsigned char GIE:1;
} INTCONbits;
#locate INTCONbits=0x0FF2
struct
{
unsigned char RBIP:1;
unsigned char INT3P:1;
unsigned char T0IP:1;
unsigned char INTEDG3:1;
unsigned char INTEDG2:1;
unsigned char INTEDG1:1;
unsigned char INTEDG0:1;
unsigned char RBPU:1;
} INTCON2bits ;
#locate INTCON2bits=0x0FF1
struct
{
unsigned char INT1IF:1;
unsigned char INT2IF:1;
unsigned char INT3IF:1;
unsigned char INT1IE:1;
unsigned char INT2IE:1;
unsigned char INT3IE:1;
unsigned char INT1IP:1;
unsigned char INT2IP:1;
} INTCON3bits ;
15 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
#locate INTCON3bits=0x0FF0
struct {
unsigned char TMR1IP:1;
unsigned char TMR2IP:1;
unsigned char CCP1IP:1;
unsigned char SSPIP:1;
unsigned char TXIP:1;
unsigned char RCIP:1;
unsigned char ADIP:1;
unsigned char PSPIP:1;
} IPR1bits ;
#locate IPR1bits=0x0F9F
struct {
unsigned char CCP2IP:1;
unsigned char TMR3IP:1;
unsigned char LVDIP:1;
unsigned char BCLIP:1;
unsigned char EEIP:1;
} IPR2bits ;
#locate IPR2bits=0x0FA2
struct {
unsigned char LATA0:1;
unsigned char LATA1:1;
unsigned char LATA2:1;
unsigned char LATA3:1;
unsigned char LATA4:1;
unsigned char LATA5:1;
} LATAbits ;
#locate LATAbits=0x0F89
struct {
unsigned char LATB0:1;
unsigned char LATB1:1;
unsigned char LATB2:1;
unsigned char LATB3:1;
unsigned char LATB4:1;
unsigned char LATB5:1;
unsigned char LATB6:1;
unsigned char LATB7:1;
} LATBbits ;
#locate LATBbits=0x0F8A
struct {
unsigned char LATC0:1;
unsigned char LATC1:1;
unsigned char LATC2:1;
unsigned char LATC3:1;
unsigned char LATC4:1;
unsigned char LATC5:1;
unsigned char LATC6:1;
unsigned char LATC7:1;
} LATCbits ;
#locate LATCbits=0x0F8B
struct {
unsigned char LATD0:1;
unsigned char LATD1:1;
unsigned char LATD2:1;
unsigned char LATD3:1;
unsigned char LATD4:1;
unsigned char LATD5:1;
unsigned char LATD6:1;
unsigned char LATD7:1;
} LATDbits ;
#locate LATDbits=0x0F8C
struct {
16 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
struct {
unsigned char LVDL0:1;
unsigned char LVDL1:1;
unsigned char LVDL2:1;
unsigned char LVDL3:1;
unsigned char LVDEN:1;
unsigned char VRST:1;
} LVDCONbits ;
#locate LVDCONbits=0x0FD2
struct {
unsigned char SCS:1;
} OSCCONbits ;
#locate OSCCONbits=0x0FD3
struct {
unsigned char TMR1IE:1;
unsigned char TMR2IE:1;
unsigned char CCP1IE:1;
unsigned char SSPIE:1;
unsigned char TXIE:1;
unsigned char RCIE:1;
unsigned char ADIE:1;
unsigned char PSPIE:1;
} PIE1bits ;
#locate PIE1bits=0x0F9D
struct {
unsigned char CCP2IE:1;
unsigned char TMR3IE:1;
unsigned char LVDIE:1;
unsigned char BCLIE:1;
unsigned char EEIE:1;
} PIE2bits ;
#locate PIE2bits=0x0FA0
struct {
unsigned char TMR1IF:1;
unsigned char TMR2IF:1;
unsigned char CCP1IF:1;
unsigned char SSPIF:1;
unsigned char TXIF:1;
unsigned char RCIF:1;
unsigned char ADIF:1;
unsigned char PSPIF:1;
} PIR1bits ;
#locate PIR1bits=0x0F9E
struct {
unsigned char CCP2IF:1;
unsigned char TMR3IF:1;
unsigned char LVDIF:1;
unsigned char BCLIF:1;
unsigned char EEIF:1;
} PIR2bits ;
#locate PIR2bits=0x0FA1
struct
{
17 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
struct
{
unsigned char RB0:1;
unsigned char RB1:1;
unsigned char RB2:1;
unsigned char RB3:1;
unsigned char RB4:1;
unsigned char RB5:1;
unsigned char RB6:1;
unsigned char RB7:1;
} PORTBbits ;
#locate PORTBbits=0x0F81
struct
{
unsigned char RC0:1;
unsigned char RC1:1;
unsigned char RC2:1;
unsigned char RC3:1;
unsigned char RC4:1;
unsigned char RC5:1;
unsigned char RC6:1;
unsigned char RC7:1;
} PORTCbits ;
#locate PORTCbits=0x0F82
struct
{
unsigned char BOR:1;
unsigned char POR:1;
unsigned char PD:1;
unsigned char TO:1;
unsigned char RI:1;
unsigned char UNUSED1:1;
unsigned char LWRT:1;
unsigned char IPEN:1;
} RCONbits ;
#locate RCONbits=0x0FD0
struct {
unsigned char RX9D:1;
unsigned char OERR:1;
unsigned char FERR:1;
unsigned char ADDEN:1;
unsigned char CREN:1;
unsigned char SREN:1;
unsigned char RX9:1;
unsigned char SPEN:1;
} RCSTAbits ;
#locate RCSTAbits=0x0FAB
18 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
struct {
unsigned char SSPM0:1;
unsigned char SSPM1:1;
unsigned char SSPM2:1;
unsigned char SSPM3:1;
unsigned char CKP:1;
unsigned char SSPEN:1;
unsigned char SSPOV:1;
unsigned char WCOL:1;
} SSPCON1bits ;
#locate SSPCON1bits=0x0FC6
struct {
unsigned char SEN:1;
unsigned char RSEN:1;
unsigned char PEN:1;
unsigned char RCEN:1;
unsigned char ACKEN:1;
unsigned char ACKDT:1;
unsigned char ACKSTAT:1;
unsigned char GCEN:1;
} SSPCON2bits ;
#locate SSPCON2bits=0x0FC5
struct {
unsigned char BF:1;
unsigned char UA:1;
unsigned char R_W:1;
unsigned char S:1;
unsigned char P:1;
unsigned char D_A:1;
unsigned char CKE:1;
unsigned char SMP:1;
} SSPSTATbits ;
#locate SSPSTATbits=0x0FC7
struct {
unsigned char C:1;
unsigned char DC:1;
unsigned char Z:1;
unsigned char OV:1;
unsigned char N:1;
} STATUSbits ;
#locate STATUSbits=0x0FD8
struct
{
unsigned char TMR1ON:1;
unsigned char TMR1CS:1;
unsigned char NOT_T1SYNC:1;
unsigned char T1OSCEN:1;
unsigned char T1CKPS0:1;
unsigned char T1CKPS1:1;
unsigned char UNUSED0:1;
unsigned char RD16:1;
} T1CONbits ;
#locate T1CONbits=0x0FCD
struct {
unsigned char T2CKPS0:1;
unsigned char T2CKPS1:1;
unsigned char TMR2ON:1;
unsigned char TOUTPS0:1;
unsigned char TOUTPS1:1;
unsigned char TOUTPS2:1;
unsigned char TOUTPS3:1;
} T2CONbits ;
19 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
#locate T2CONbits=0x0FCA
struct {
unsigned char TRISA0:1;
unsigned char TRISA1:1;
unsigned char TRISA2:1;
unsigned char TRISA3:1;
unsigned char TRISA4:1;
unsigned char TRISA5:1;
} TRISAbits ;
#locate TRISAbits=0x0F92
struct {
unsigned char TRISB0:1;
unsigned char TRISB1:1;
unsigned char TRISB2:1;
unsigned char TRISB3:1;
unsigned char TRISB4:1;
unsigned char TRISB5:1;
unsigned char TRISB6:1;
unsigned char TRISB7:1;
} TRISBbits ;
#locate TRISBbits=0x0F93
struct {
unsigned char TRISC0:1;
unsigned char TRISC1:1;
unsigned char TRISC2:1;
unsigned char TRISC3:1;
unsigned char TRISC4:1;
unsigned char TRISC5:1;
unsigned char TRISC6:1;
unsigned char TRISC7:1;
} TRISCbits ;
#locate TRISCbits=0x0F94
struct {
unsigned char TRISD0:1;
unsigned char TRISD1:1;
unsigned char TRISD2:1;
unsigned char TRISD3:1;
unsigned char TRISD4:1;
unsigned char TRISD5:1;
unsigned char TRISD6:1;
unsigned char TRISD7:1;
} TRISDbits ;
#locate TRISDbits=0x0F95
struct {
unsigned char TRISE0:1;
unsigned char TRISE1:1;
unsigned char TRISE2:1;
unsigned char TRISE3:1;
unsigned char TRISE4:1;
unsigned char TRISE5:1;
20 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
struct {
unsigned char TX9D:1;
unsigned char TRMT:1;
unsigned char BRGH:1;
unsigned char UNUSED:1;
unsigned char SYNC:1;
unsigned char TXEN:1;
unsigned char TX9:1;
unsigned char CSRC:1;
} TXSTAbits ;
#locate TXSTAbits=0x0FAC
unsigned char W;
#locate W=0x0FE8
/***************************************************************** Control
Control Functions: RESET_CPU(), SLEEP(), RESTART_CAUSE()
Constants returned from RESTART_CAUSE() are:
***************************************************************************/
#define WDT_TIMEOUT 4
#define MCLR_FROM_SLEEP 8
#define NORMAL_POWER_UP 12
#define BROWNOUT_RESTART 14
/***************************************************************** Timer 0
Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER0(),
SET_TIMER0() or SET_RTCC(),
GET_TIMER0() or GET_RTCC()
Constants used for SETUP_TIMER0() are:
***************************************************************************/
#define RTCC_INTERNAL 0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48
#define RTCC_DIV_2 0
#define RTCC_DIV_4 1
#define RTCC_DIV_8 2
#define RTCC_DIV_16 3
#define RTCC_DIV_32 4
#define RTCC_DIV_64 5
#define RTCC_DIV_128 6
#define RTCC_DIV_256 7
#define WDT_18MS 8
#define WDT_36MS 9
#define WDT_72MS 10
#define WDT_144MS 11
#define WDT_288MS 12
#define WDT_576MS 13
#define WDT_1152MS 14
#define WDT_2304MS 15
/******************************************************
Constants used for SETUP_COUNTERS() are the above
constants for the 1st param and the following for
the 2nd param:
******************************************************/
/********************************************************************* WDT
Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
RESTART_WDT()
***************************************************************************/
#define WDT_ON 0x100
21 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
#define WDT_OFF 0
/***************************************************************** Timer 1
Timer 1 Functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1
Constants used for SETUP_TIMER_1() are:
(or (via |) together constants from each group)
***************************************************************************/
#define T1_DISABLED 0
#define T1_INTERNAL 0x85
#define T1_EXTERNAL 0x87
#define T1_EXTERNAL_SYNC 0x83
#define T1_CLK_OUT 8
#define T1_DIV_BY_1 0
#define T1_DIV_BY_2 0x10
#define T1_DIV_BY_4 0x20
#define T1_DIV_BY_8 0x30
#byte TIMER_1_LOW= 0xFD6
#byte TIMER_1_HIGH= 0xFD7
/***************************************************************** Timer 2
Timer 2 Functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2
Constants used for SETUP_TIMER_2() are:
***************************************************************************/
#define T2_DISABLED 0
#define T2_DIV_BY_1 4
#define T2_DIV_BY_4 5
#define T2_DIV_BY_16 6
#byte TIMER_2= 0xFCC
/***************************************************************** Timer 3
Timer 3 Functions: SETUP_TIMER_3, GET_TIMER3, SET_TIMER3
Constants used for SETUP_TIMER_3() are:
(or (via |) together constants from each group)
***************************************************************************/
#define T3_DISABLED 0
#define T3_INTERNAL 0x85
#define T3_EXTERNAL 0x87
#define T3_EXTERNAL_SYNC 0x83
#define T3_DIV_BY_1 0
#define T3_DIV_BY_2 0x10
#define T3_DIV_BY_4 0x20
#define T3_DIV_BY_8 0x30
/********************************************************************* CCP
CCP Functions: SETUP_CCPx, SET_PWMx_DUTY
CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
Constants used for SETUP_CCPx() are:
***************************************************************************/
#define CCP_OFF 0
#define CCP_CAPTURE_FE 4
#define CCP_CAPTURE_RE 5
#define CCP_CAPTURE_DIV_4 6
#define CCP_CAPTURE_DIV_16 7
#define CCP_COMPARE_SET_ON_MATCH 8
#define CCP_COMPARE_CLR_ON_MATCH 9
#define CCP_COMPARE_INT 0xA
#define CCP_COMPARE_RESET_TIMER 0xB
#define CCP_PWM 0xC
#define CCP_PWM_PLUS_1 0x1c
#define CCP_PWM_PLUS_2 0x2c
#define CCP_PWM_PLUS_3 0x3c
#define CCP_USE_TIMER3 0x100
long CCP_1;
#byte CCP_1 = 0xfbe
#byte CCP_1_LOW= 0xfbe
#byte CCP_1_HIGH= 0xfbf
long CCP_2;
#byte CCP_2 = 0xfbb
#byte CCP_2_LOW= 0xfbb
#byte CCP_2_HIGH= 0xfbc
/******************************************************************** SPI
SPI Functions: SETUP_SPI, SPI_WRITE, SPI_READ, SPI_DATA_IN
Constants used in SETUP_SSP() are:
***************************************************************************/
#define SPI_MASTER 0x20
#define SPI_SLAVE 0x24
#define SPI_L_TO_H 0
#define SPI_H_TO_L 0x10
#define SPI_CLK_DIV_4 0
#define SPI_CLK_DIV_16 1
#define SPI_CLK_DIV_64 2
#define SPI_CLK_T2 3
#define SPI_SS_DISABLED 1
22 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
/********************************************************************* ADC
ADC Functions: SETUP_ADC(), SETUP_ADC_PORTS() (aka SETUP_PORT_A),
SET_ADC_CHANNEL(), READ_ADC()
Constants used in SETUP_ADC_PORTS() are:
***************************************************************************/
#define NO_ANALOGS 0x06 /* None */
#define ALL_ANALOG 0x00 /* RA0 RA1 RA2 RA3 RA5 RE0 RE1 RE2 Ref=Vdd */
#define ANALOG_RA3_REF 0x01 /* RA0 RA1 RA2 RA5 RE0 RE1 RE2 Ref=RA3 */
#define A_ANALOG 0x02 /* RA0 RA1 RA2 RA3 RA5 Ref=Vdd */
#define A_ANALOG_RA3_REF 0x03 /* RA0 RA1 RA2 RA5 Ref=RA3 */
#define RA0_RA1_RA3_ANALOG 0x04 /* RA0 RA1 RA3 Ref=Vdd */
#define RA0_RA1_ANALOG_RA3_REF 0x05 /* RA0 RA1 Ref=RA3 */
/********************************************************************* INT
Interrupt Functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(),
EXT_INT_EDGE()
#endif /* 18F252_H */
Last edited by Mark on Wed Jun 21, 2006 8:36 pm; edited 2 times in total
Mark
Joined: 07 Oct 2003
Posts: 76
Location: England I did not expect the whole program!!
Thanks very much for your expert help - very much appreciated!!
I will get round to implementing it in the new year.
Thanks again - and best wishes for you and yours for Christmas and New Year!!!
Dave
Hi Mark
Joined: 07 Oct 2003
Posts: 76
Location: England Had a bit of spare time - thought I would try your code.
I copied the 18f252_.h into the devices file and created a project.
I then tried to compile, but an error comes up:
23 от 24 28.2.2007 г. 09:12
CCS :: View topic - Multiple PWM outputs http://www.ccsinfo.com/forum/viewtopic.php?t=21092&start=15
Any ideas?
Many thanks.
Dave
If you are using MPLAB, goto Configure and then Select Device. Choose 18F252. Let me know if it fixes it.
Joined: 07 Sep 2003
Posts: 3511
Location: Atlanta, GA
Mark
Joined: 07 Oct 2003
Posts: 76
Location: England I am not using mplab.
Just created a project in CCS compiler version 3.210.
Project created manually device-18f252.
I have not ever used the CCS IDE but I know I get that error message when the compiler uses the PCM
Joined: 07 Sep 2003
Posts: 3511 module when it should be using the PCH. This happens if I select the wrong device.
Location: Atlanta, GA
24 от 24 28.2.2007 г. 09:12