CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F887 and steering mode
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 12, 2010 12:46 pm     Reply with quote

You could write directly to the PWM1CON register, or you could make
a little function to do it. Example:
Code:

// Call this routine to set the PWM deadband.
// The deadband value can be from 0 to 127,
// and is in units of Instruction Cycles (Fosc/4).
// For example, with a 4 MHz crystal, an instruction
// cycle is 1 us.   
void set_deadband(int8 deadband)
{
#byte PWM1CON = 0x9B

if(deadband > 127)   // Do a limit check on the value.
   deadband == 127;

PWM1CON = deadband;
}

This function should be called after you call the setup_ccp1()
function.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sat May 15, 2010 3:49 pm     Reply with quote

I am writing a test program for 16F1826.
I might have misunderstood something but the device header file does not contain any definitions for CCP_PULSE_STEERING_A or similar keywords.
I don't think setting TRIS register is enough to get the PWM signal on P1A, P1B, P1C and P1D.

Is it a wrong .h file? Can I copy those declarations from another .h file?
v4.106
cheers
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 15, 2010 4:51 pm     Reply with quote

If it's not in the .h file, CCS may not support it yet. These are new PICs.
I'll check on a work-around for you later.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 17, 2010 2:41 pm     Reply with quote

I don't have a 16F1826 to test, but I think the following work-around code
may work. In the test program shown below, after you call setup_ccp1()
you just call set_pulse_steering() function. Use the constants shown
below to select which channels (P1A, P1B, P1C, P1D) you want to use
for PWM output. I compiled this with vs. 4.107.
Code:

#include <16F1826.h>
#fuses INTRC_IO, NOWDT, PUT, NOLVP
#use delay(clock=4000000)

// These are the default PWM output pins for the 16F1826.
// Note: Alternate pins are available for P1A, P1C, P1D
// by setting bits in the APFCON0 register.
#define P1A  PIN_B3   // Alternate is  Pin B0
#define P1B  PIN_B5   // No alernate pin
#define P1C  PIN_B6   // Alternate is Pin A7
#define P1D  PIN_B7   // Alternate is Pin A6

// Constants for Pulse Steering.
#define CCP_PULSE_STEERING_A    0x01000000
#define CCP_PULSE_STEERING_B    0x02000000
#define CCP_PULSE_STEERING_C    0x04000000
#define CCP_PULSE_STEERING_D    0x08000000
#define CCP_PULSE_STEERING_SYNC 0x10000000
 
// Call this routine to set the PWM steering.  You can OR
// together the PWM steering constants from the PIC's
// header file.  (In this case, use the constants shown
// above, since the header file doesn't have them).
void set_pulse_steering(int32 steering)
{
int8 temp;
#byte PSTR1CON = 0x296

temp = make8(steering, 3);  // Get high byte only

PSTR1CON = temp;   // Setup PWM steering register

// Set the TRIS to outputs for the enabled steering pins.
// Also set the selected pins to a low level.
if(temp & 1)
   output_low(P1A);
if(temp & 2)
   output_low(P1B);
if(temp & 4)
   output_low(P1C);
if(temp & 8)
   output_low(P1D);
}


//===========================================
void main()
{
setup_timer_2(T2_DIV_BY_16, 124, 1);  // Set 1000 Hz PWM freq

set_pwm1_duty(31);  // Set PWM for 25% duty cycle

// Set up PWM so that all four outputs are active high.
setup_ccp1(CCP_PWM_H_H);

// Enable PWM output on all four pins.
set_pulse_steering( CCP_PULSE_STEERING_A |
                    CCP_PULSE_STEERING_B |
                    CCP_PULSE_STEERING_C |
                    CCP_PULSE_STEERING_D);


while(1);
}
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue May 18, 2010 2:05 am     Reply with quote

thanks a lot,
I am gonna test it out during the weekend.

Cheers
Meereck
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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