|
|
View previous topic :: View next topic |
Author |
Message |
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
Using Pin select and CLC's on Pic16F18346 |
Posted: Thu Aug 24, 2017 1:23 pm |
|
|
Hi
I have been struggling in understanding in using the CLC functions with CCS compiler. I originally posted some code using PIC16F1619 but used the Microchips Code Configurator not the CCS internal CLC functions. I got it working using by assigning values directly to the CLC registers from code generated from Code Configurator with also including with using CCS #pin select definitions. This was with compiler version 5.052. I had to upgrade to the PIC16F18346 because I needed more code space. CCS v5.052 did not support PIC16F18346 so I use the device editor to add chip and got it to compile. I was not sure if I had done it right, but found the CLC selection and Timer 3 and Timer 5 as counters did not work. So I decided to upgrade the compiler to v5.074 $$$$ . To my surprise it still does not work.
The code posted below compiles with both versions modified v5.052 & v5.074, and works only with the generated code from Code Configurator code, not using CCS CLC functions.
Most CCS examples never show real schematic to code. I have tried to understand the use of CCS CLC functions based on schematic also below.
What am I doing wrong
Code: |
#device PIC16F18346
#include <16F18346.h>
#fuses RSTOSC_HFINTRC_PLL, nowdt, noprotect, nolvp, put //16F18346
#fuses nomclr, nodebug
#device *=16
#device adc=8
#byte CLC1GLS0 = getenv("SFR:CLC1GLS0")
#byte CLC1GLS1 = getenv("SFR:CLC1GLS1")
#byte CLC1GLS2 = getenv("SFR:CLC1GLS2")
#byte CLC1GLS3 = getenv("SFR:CLC1GLS3")
#byte CLC1SEL0 = getenv("SFR:CLC1SEL0")
#byte CLC1SEL1 = getenv("SFR:CLC1SEL1")
#byte CLC1SEL2 = getenv("SFR:CLC1SEL2")
#byte CLC1SEL3 = getenv("SFR:CLC1SEL3")
#byte CLC1POL = getenv("SFR:CLC1POL")
#byte CLC1CON = getenv("SFR:CLC1CON")
#byte CLCDATA = getenv("SFR:CLCDATA")
#byte CLC2GLS0 = getenv("SFR:CLC2GLS0")
#byte CLC2GLS1 = getenv("SFR:CLC2GLS1")
#byte CLC2GLS2 = getenv("SFR:CLC2GLS2")
#byte CLC2GLS3 = getenv("SFR:CLC2GLS3")
#byte CLC2SEL0 = getenv("SFR:CLC2SEL0")
#byte CLC2SEL1 = getenv("SFR:CLC2SEL1")
#byte CLC2SEL2 = getenv("SFR:CLC2SEL2")
#byte CLC2SEL3 = getenv("SFR:CLC2SEL3")
#byte CLC2POL = getenv("SFR:CLC2POL")
#byte CLC2CON = getenv("SFR:CLC2CON")
#define MOTDIR PIN_C1 // Pin Controls motor direction
#case
#use delay(clock=32000000, internal) //one instruction=0.2us
#define BAUD1_SPEED 9600
#define BAUD2_SPEED 19200
#define BAUD3_SPEED 38400
#define BAUD4_SPEED 115200
#pin_select U1TX = PIN_B7
#pin_select U1RX = PIN_B5
#pin_select SDA1OUT = PIN_B4
#pin_select SDA1IN = PIN_B4
#pin_select SCL1OUT = PIN_B6
#pin_select SCL1IN = PIN_B6
#pin_select CLC1OUT = PIN_C5
#pin_select CLC2OUT = PIN_C0
#pin_select T3CKI = PIN_C5
#pin_select T5CKI = PIN_C0
#pin_select T0CKI = PIN_C5
#pin_select T1CKI = PIN_C0
#pin_select CLCIN0 = PIN_A4
#pin_select CLCIN1 = PIN_C7
#pin_select CLCIN2 = PIN_C3
#pin_select CLCIN3 = PIN_C4
#use rs232(baud=BAUD4_SPEED, UART1, ERRORS, stream=HOSTPC)
#use pwm(PWM5, OUTPUT=PIN_C6, TIMER=4, FREQUENCY=15000, BITS=10, PWM_ON, STREAM=PWM5)
void cfgCLC(void) // Timer3 & Timer 5
{
// CCS Code for schematic Below ???
setup_clc1(CLC_ENABLED | CLC_MODE_1_INPUT_D_FLIP_FLOP);
clc1_setup_input(1, CLC_INPUT_CLCIN0);
clc1_setup_input(4, CLC_INPUT_CLCIN1);
clc1_setup_gate(1, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_1);
clc1_setup_gate(2, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_2);
clc1_setup_gate(3, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_3);
clc1_setup_gate(4, CLC_GATE_CLEAR | CLC_GATE_NON_INVERTED_INPUT_4);
setup_clc2(CLC_ENABLED | CLC_MODE_1_INPUT_D_FLIP_FLOP);
clc2_setup_input(1, CLC_INPUT_CLCIN2);
clc2_setup_input(4, CLC_INPUT_CLCIN3);
clc2_setup_gate(1, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_1);
clc2_setup_gate(2, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_2);
clc2_setup_gate(3, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_3);
clc2_setup_gate(4, CLC_GATE_CLEAR | CLC_GATE_NON_INVERTED_INPUT_4);
// Code below is from Microchips code Configurator sort of, which is working
//! CLC1POL = 0x04;
//! CLC1SEL0 = 0x00;
//! CLC1SEL1 = 0x00;
//! CLC1SEL2 = 0x00;
//! CLC1SEL3 = 0x01;
//! CLC1GLS0 = 0x80;
//! CLC1GLS1 = 0x02;
//! CLC1GLS2 = 0x02;
//! CLC1GLS3 = 0x00;
//! CLC1CON = 0x84;
//!
//! CLC2POL = 0x04;
//! CLC2SEL0 = 0x02;
//! CLC2SEL1 = 0x00;
//! CLC2SEL2 = 0x00;
//! CLC2SEL3 = 0x03;
//! CLC2GLS0 = 0x02;
//! CLC2GLS1 = 0x80;
//! CLC2GLS2 = 0x80;
//! CLC2GLS3 = 0x00;
//! CLC2CON = 0x84;
}
void Setup()
{
setup_wdt(WDT_ON);
// Setup A/D converter FIX
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
set_tris_a(0b00011001);
port_a_pullups(0x2D);
set_tris_b(0b11110111); // All Inputs Lower nibble Interrupt on change
set_tris_c(0b10011000); // Mode for ??
port_c_pullups(0x98);
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); // 1 ms refresh rate
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_EXTERNAL_SYNC); // 1 ms refresh rate
set_timer0(0L);
set_timer1(0L);
setup_timer_3(T3_EXTERNAL_SYNC | T3_DIV_BY_1); // 1 ms refresh rate
setup_timer_5(T5_EXTERNAL_SYNC | T5_DIV_BY_1); // 1 ms refresh rate
set_timer3(0L);
set_timer5(0L);
setup_timer_2(T2_DIV_BY_4, 255, 10); // approx. 15.531k kHz
pwm_set_duty(PWM5, 128); //motor starts at 0 velocity
// clear_interrupt(INT_TIMER2); // Timer2
// clear_interrupt(INT_SSP); /* Enable MSSP interrupts. */
//
// clear_interrupt(INT_RDA); // RDA
//
// enable_interrupts(INT_TIMER2); // TIMER2 Int
// enable_interrupts(INT_SSP); /* Enable MSSP interrupts. */
//
// enable_interrupts(INT_RDA); // Serial Int
//
// enable_interrupts(GLOBAL);
fprintf(HOSTPC, "\r\nCCS PIC16F18346 CLC Test\r\n");
}
main()
{
Setup();
cfgCLC();
while(1)
{
fprintf(HOSTPC, "T0 = %ld T1 = %ld \r\n", get_timer0(), get_timer1());
fprintf(HOSTPC, "T3 = %ld T5 = %ld \r\n", get_timer3(), get_timer5());
delay_ms(1000);
output_toggle(MOTDIR);
delay_ms(1000);
}
}
|
This just test code.
The code above starts a motor rotating with attached encoders for 1 second CW then reverse direction CCW and displays timer counts.
Timers
T0 & T1 works shows counts
T3 & T5 does not work, these did work with PIC16F1619
Code: |
#pin_select CLC1OUT = PIN_C5
#pin_select CLC2OUT = PIN_C0
#pin_select T3CKI = PIN_C5
#pin_select T5CKI = PIN_C0
#pin_select T0CKI = PIN_C5
#pin_select T1CKI = PIN_C0
|
I assigned both CLCXOUT pins to both sets of timers above, but also tried them using timer T3 & T5 separately, still does not count.
My overall objective is to understand how to use the CCS CLC functions with a real example.
The timers T3 & T5 is possibly a compiler issue?? But need to get it working with T3 & T5.
Schematic at link below:
[img] https://s29.postimg.org/bjke6nkfr/CLC_Example.png [/img]
Original Schematic used CLC1 RA3 & RC7. This code is using RC4 & RC7.
Sorry for long post and explanation.
Thanks in advance.
Jerry |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 24, 2017 7:37 pm |
|
|
Can you post two source code programs:
1. A program done with direct register access, that works correctly.
2. An equivalent program done with CCS functions that doesn't work.
If you can do that, I can compare the .LST files and see what's missing
from the CCS functions and hopefully fix it for you.
Make these programs as short as possible, and don't put any commented
out code in them. In other words, I just want simple clean programs that
I can compile and look at.
Both programs should be for vs. 5.074.
The reason I want you to make two separate programs for me is that
I don't want to try to take apart your posted code by myself. It's better
if you do it, because you understand what you want in the programs. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Aug 25, 2017 12:18 am |
|
|
Have a look at this thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=56448>
Haven't checked whether your chip might have the same problem, but on this chip only the low 4 bits of the selection value was being written by the CCS function. As you will see CCS have acknowledged this and will fix in the next release. The CCS 'values' still work correctly, but only if written directly to the actual selection register for any one needing setting to a value above 15.
Most (all) of the last generation of CLC's only had 3 or 4 bits for the selection value. MicroChip's own configurator tool gives the same fault if you use an old version. |
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
|
Posted: Fri Aug 25, 2017 11:12 am |
|
|
This version is working but using MPLAB Code Configurator output for PIC16F1619
Also T3 & T5 counters Worked on the PIC16F1619
Code: |
#device PIC16F18346
#nolist
#include <16F18346.h>
#fuses RSTOSC_HFINTRC_PLL, nowdt, noprotect, nolvp, put //16F18346
#fuses nomclr, nodebug
#device *=16
#device adc=8
#byte CLC1GLS0 = getenv("SFR:CLC1GLS0")
#byte CLC1GLS1 = getenv("SFR:CLC1GLS1")
#byte CLC1GLS2 = getenv("SFR:CLC1GLS2")
#byte CLC1GLS3 = getenv("SFR:CLC1GLS3")
#byte CLC1SEL0 = getenv("SFR:CLC1SEL0")
#byte CLC1SEL1 = getenv("SFR:CLC1SEL1")
#byte CLC1SEL2 = getenv("SFR:CLC1SEL2")
#byte CLC1SEL3 = getenv("SFR:CLC1SEL3")
#byte CLC1POL = getenv("SFR:CLC1POL")
#byte CLC1CON = getenv("SFR:CLC1CON")
#byte CLCDATA = getenv("SFR:CLCDATA")
#byte CLC2GLS0 = getenv("SFR:CLC2GLS0")
#byte CLC2GLS1 = getenv("SFR:CLC2GLS1")
#byte CLC2GLS2 = getenv("SFR:CLC2GLS2")
#byte CLC2GLS3 = getenv("SFR:CLC2GLS3")
#byte CLC2SEL0 = getenv("SFR:CLC2SEL0")
#byte CLC2SEL1 = getenv("SFR:CLC2SEL1")
#byte CLC2SEL2 = getenv("SFR:CLC2SEL2")
#byte CLC2SEL3 = getenv("SFR:CLC2SEL3")
#byte CLC2POL = getenv("SFR:CLC2POL")
#byte CLC2CON = getenv("SFR:CLC2CON")
#define MOTDIR PIN_C1 // Pin Controls motor direction
#case
#use delay(clock=32000000, internal) //one instruction=0.2us
define BAUD4_SPEED 115200
#pin_select U1TX = PIN_B7
#pin_select U1RX = PIN_B5
#pin_select SDA1OUT = PIN_B4
#pin_select SDA1IN = PIN_B4
#pin_select SCL1OUT = PIN_B6
#pin_select SCL1IN = PIN_B6
#pin_select CLC1OUT = PIN_C5
#pin_select CLC2OUT = PIN_C0
#pin_select T3CKI = PIN_C5
#pin_select T5CKI = PIN_C0
#pin_select T0CKI = PIN_C5
#pin_select T1CKI = PIN_C0
#pin_select CLCIN0 = PIN_A4
#pin_select CLCIN1 = PIN_C7
#pin_select CLCIN2 = PIN_C3
#pin_select CLCIN3 = PIN_C4
#use rs232(baud=BAUD4_SPEED, UART1, ERRORS, stream=HOSTPC)
#use pwm(PWM5, OUTPUT=PIN_C6, TIMER=4, FREQUENCY=15000, BITS=10, PWM_ON, STREAM=PWM5)
// CCS Code for schematic Below ???
void cfgCLC(void) // Timer3 & Timer 5
{
CLC1POL = 0x04;
CLC1SEL0 = 0x00;
CLC1SEL1 = 0x00;
CLC1SEL2 = 0x01;
CLC1SEL3 = 0x01;
CLC1GLS0 = 0x80;
CLC1GLS1 = 0x02;
CLC1GLS2 = 0x02;
CLC1GLS3 = 0x00;
CLC1CON = 0x84;
CLC2POL = 0x04;
CLC2SEL0 = 0x02;
CLC2SEL1 = 0x02;
CLC2SEL2 = 0x03;
CLC2SEL3 = 0x03;
CLC2GLS0 = 0x02;
CLC2GLS1 = 0x80;
CLC2GLS2 = 0x80;
CLC2GLS3 = 0x00;
CLC2CON = 0x84;
}
void Setup()
{
setup_wdt(WDT_ON);
// Setup A/D converter FIXX
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
set_tris_a(0b00011001);
port_a_pullups(0x2D);
set_tris_b(0b11110111); // All Inputs Lower nibble Interrupt on change
set_tris_c(0b10011000); // Mode for ??
port_c_pullups(0x98);
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); // 1 ms refresh rate
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_EXTERNAL_SYNC); // 1 ms refresh rate
set_timer0(0L);
set_timer1(0L);
setup_timer_3(T3_EXTERNAL_SYNC | T3_DIV_BY_1); // 1 ms refresh rate
setup_timer_5(T5_EXTERNAL_SYNC | T5_DIV_BY_1); // 1 ms refresh rate
set_timer3(0L);
set_timer5(0L);
setup_timer_2(T2_DIV_BY_4, 255, 10); // approx. 15.531k kHz
pwm_set_duty(PWM5, 128); //motor starts at slow velocity
fprintf(HOSTPC, "\r\nCCS PIC16F18346 CLC Test\r\n");
}
main()
{
Setup();
cfgCLC();
while(1)
{
fprintf(HOSTPC, "T0 = %ld T1 = %ld \r\n", get_timer0(), get_timer1());
fprintf(HOSTPC, "T3 = %ld T5 = %ld \r\n", get_timer3(), get_timer5());
delay_ms(1000);
output_toggle(MOTDIR);
delay_ms(1000);
}
}
|
Thanks PCM Programmer |
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
|
Posted: Fri Aug 25, 2017 11:17 am |
|
|
This version is MPLAB Modified Output which I took some output values to the CLC registers. The version for PIC16F18346 DID NOT WORK
Code: |
#device PIC16F18346
#nolist
#include <16F18346.h>
#fuses RSTOSC_HFINTRC_PLL, nowdt, noprotect, nolvp, put //16F18346
#fuses nomclr, nodebug
#device *=16
#device adc=8
#byte CLC1GLS0 = getenv("SFR:CLC1GLS0")
#byte CLC1GLS1 = getenv("SFR:CLC1GLS1")
#byte CLC1GLS2 = getenv("SFR:CLC1GLS2")
#byte CLC1GLS3 = getenv("SFR:CLC1GLS3")
#byte CLC1SEL0 = getenv("SFR:CLC1SEL0")
#byte CLC1SEL1 = getenv("SFR:CLC1SEL1")
#byte CLC1SEL2 = getenv("SFR:CLC1SEL2")
#byte CLC1SEL3 = getenv("SFR:CLC1SEL3")
#byte CLC1POL = getenv("SFR:CLC1POL")
#byte CLC1CON = getenv("SFR:CLC1CON")
#byte CLCDATA = getenv("SFR:CLCDATA")
#byte CLC2GLS0 = getenv("SFR:CLC2GLS0")
#byte CLC2GLS1 = getenv("SFR:CLC2GLS1")
#byte CLC2GLS2 = getenv("SFR:CLC2GLS2")
#byte CLC2GLS3 = getenv("SFR:CLC2GLS3")
#byte CLC2SEL0 = getenv("SFR:CLC2SEL0")
#byte CLC2SEL1 = getenv("SFR:CLC2SEL1")
#byte CLC2SEL2 = getenv("SFR:CLC2SEL2")
#byte CLC2SEL3 = getenv("SFR:CLC2SEL3")
#byte CLC2POL = getenv("SFR:CLC2POL")
#byte CLC2CON = getenv("SFR:CLC2CON")
#define MOTDIR PIN_C1 // Pin Controls motor direction
#case
#use delay(clock=32000000, internal) //one instruction=0.2us
#define BAUD4_SPEED 115200
#pin_select U1TX = PIN_B7
#pin_select U1RX = PIN_B5
#pin_select SDA1OUT = PIN_B4
#pin_select SDA1IN = PIN_B4
#pin_select SCL1OUT = PIN_B6
#pin_select SCL1IN = PIN_B6
#pin_select CLC1OUT = PIN_C5
#pin_select CLC2OUT = PIN_C0
#pin_select T3CKI = PIN_C5
#pin_select T5CKI = PIN_C0
#pin_select T0CKI = PIN_C5
#pin_select T1CKI = PIN_C0
#pin_select CLCIN0 = PIN_A4
#pin_select CLCIN1 = PIN_C7
#pin_select CLCIN2 = PIN_C3
#pin_select CLCIN3 = PIN_C4
#use rs232(baud=BAUD4_SPEED, UART1, ERRORS, stream=HOSTPC)
#use pwm(PWM5, OUTPUT=PIN_C6, TIMER=4, FREQUENCY=15000, BITS=10, PWM_ON, STREAM=PWM5)
// CCS Code for schematic Below ???
void cfgCLC(void) // Timer3 & Timer 5
{
CLC1POL = 0x04;
CLC1SEL0 = 0x00;
CLC1SEL1 = 0x00;
CLC1SEL2 = 0x00;
CLC1SEL3 = 0x01;
CLC1GLS0 = 0x80;
CLC1GLS1 = 0x02;
CLC1GLS2 = 0x02;
CLC1GLS3 = 0x00;
CLC1CON = 0x84;
CLC2POL = 0x04;
CLC2SEL0 = 0x02;
CLC2SEL1 = 0x00;
CLC2SEL2 = 0x00;
CLC2SEL3 = 0x03;
CLC2GLS0 = 0x02;
CLC2GLS1 = 0x80;
CLC2GLS2 = 0x80;
CLC2GLS3 = 0x00;
CLC2CON = 0x84;
}
void Setup()
{
setup_wdt(WDT_ON);
// Setup A/D converter FIXX
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
set_tris_a(0b00011001);
port_a_pullups(0x2D);
set_tris_b(0b11110111); // All Inputs Lower nibble Interrupt on change
set_tris_c(0b10011000); // Mode for ??
port_c_pullups(0x98);
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); // 1 ms refresh rate
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_EXTERNAL_SYNC); // 1 ms refresh rate
set_timer0(0L);
set_timer1(0L);
setup_timer_3(T3_EXTERNAL_SYNC | T3_DIV_BY_1); // 1 ms refresh rate
setup_timer_5(T5_EXTERNAL_SYNC | T5_DIV_BY_1); // 1 ms refresh rate
set_timer3(0L);
set_timer5(0L);
setup_timer_2(T2_DIV_BY_4, 255, 10); // approx. 15.531k kHz
pwm_set_duty(PWM5, 128); //motor starts at slow velocity
fprintf(HOSTPC, "\r\nCCS PIC16F18346 CLC Test\r\n");
}
main()
{
Setup();
cfgCLC();
while(1)
{
fprintf(HOSTPC, "T0 = %ld T1 = %ld \r\n", get_timer0(), get_timer1());
fprintf(HOSTPC, "T3 = %ld T5 = %ld \r\n", get_timer3(), get_timer5());
delay_ms(1000);
output_toggle(MOTDIR);
delay_ms(1000);
}
}
|
Thanks |
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
|
Posted: Fri Aug 25, 2017 11:20 am |
|
|
The is the CCS version using the CLC Functions
Code: |
#device PIC16F18346
#nolist
#include <16F18346.h>
#fuses RSTOSC_HFINTRC_PLL, nowdt, noprotect, nolvp, put //16F18346
#fuses nomclr, nodebug
#device *=16
#device adc=8
#define MOTDIR PIN_C1 // Pin Controls motor direction
#case
#use delay(clock=32000000, internal) //one instruction=0.2us
#define BAUD4_SPEED 115200
#pin_select U1TX = PIN_B7
#pin_select U1RX = PIN_B5
#pin_select SDA1OUT = PIN_B4
#pin_select SDA1IN = PIN_B4
#pin_select SCL1OUT = PIN_B6
#pin_select SCL1IN = PIN_B6
#pin_select CLC1OUT = PIN_C5
#pin_select CLC2OUT = PIN_C0
#pin_select T3CKI = PIN_C5
#pin_select T5CKI = PIN_C0
#pin_select T0CKI = PIN_C5
#pin_select T1CKI = PIN_C0
#pin_select CLCIN0 = PIN_A4
#pin_select CLCIN1 = PIN_C7
#pin_select CLCIN2 = PIN_C3
#pin_select CLCIN3 = PIN_C4
#use rs232(baud=BAUD4_SPEED, UART1, ERRORS, stream=HOSTPC)
#use pwm(PWM5, OUTPUT=PIN_C6, TIMER=4, FREQUENCY=15000, BITS=10, PWM_ON, STREAM=PWM5)
void cfgCLC(void) // Timer3 & Timer 5
{
setup_clc1(CLC_ENABLED | CLC_MODE_1_INPUT_D_FLIP_FLOP);
clc1_setup_input(1, CLC_INPUT_CLCIN0);
clc1_setup_input(4, CLC_INPUT_CLCIN1);
clc1_setup_gate(1, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_1);
clc1_setup_gate(2, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_2);
clc1_setup_gate(3, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_3);
clc1_setup_gate(4, CLC_GATE_CLEAR | CLC_GATE_NON_INVERTED_INPUT_4);
setup_clc2(CLC_ENABLED | CLC_MODE_1_INPUT_D_FLIP_FLOP);
clc2_setup_input(1, CLC_INPUT_CLCIN2);
clc2_setup_input(4, CLC_INPUT_CLCIN3);
clc2_setup_gate(1, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_1);
clc2_setup_gate(2, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_2);
clc2_setup_gate(3, CLC_GATE_OR | CLC_GATE_NON_INVERTED_INPUT_3);
clc2_setup_gate(4, CLC_GATE_CLEAR | CLC_GATE_NON_INVERTED_INPUT_4);
}
void Setup()
{
setup_wdt(WDT_ON);
// Setup A/D converter FIXX
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
set_tris_a(0b00011001);
port_a_pullups(0x2D);
set_tris_b(0b11110111); // All Inputs Lower nibble Interrupt on change
set_tris_c(0b10011000); // Mode for ??
port_c_pullups(0x98);
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); // 1 ms refresh rate
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_EXTERNAL_SYNC); // 1 ms refresh rate
set_timer0(0L);
set_timer1(0L);
setup_timer_3(T3_EXTERNAL_SYNC | T3_DIV_BY_1); // 1 ms refresh rate
setup_timer_5(T5_EXTERNAL_SYNC | T5_DIV_BY_1); // 1 ms refresh rate
set_timer3(0L);
set_timer5(0L);
setup_timer_2(T2_DIV_BY_4, 255, 10); // approx. 15.531k kHz
pwm_set_duty(PWM5, 128); //motor starts at slow velocity
fprintf(HOSTPC, "\r\nCCS PIC16F18346 CLC Test\r\n");
}
main()
{
Setup();
cfgCLC();
while(1)
{
fprintf(HOSTPC, "T0 = %ld T1 = %ld \r\n", get_timer0(), get_timer1());
fprintf(HOSTPC, "T3 = %ld T5 = %ld \r\n", get_timer3(), get_timer5());
delay_ms(1000);
output_toggle(MOTDIR);
delay_ms(1000);
}
}
|
Thanks Again. \
I had to rush this. Hope its fine |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|