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

24FJ PWM function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

24FJ PWM function
PostPosted: Mon Dec 17, 2007 9:36 pm     Reply with quote

Hi,
I am having problems in getting PWM (OC) to work in the 24FJ64GA004 micro the code below is a test program I have been trying.
Code:
//*****************************************************************************/
#include <24FJ64GA004.h>
#device *=16
#device adc=10

#fuses NOWDT
#FUSES FRC                 //Internal Fast RC oscillator with PLL

#use delay(clock=8000000)

//********** ASSIGN PIN TO PERIPHICALS
//RS232 PINS
#Pin_select U1TX=PIN_B0
#Pin_select U1RX=PIN_B1

//PWM 0-10 V REF OUT
#Pin_select OC1=PIN_B9

//PWM OUTPUT PINS
#Pin_select OC2=PIN_C5
#Pin_select OC3=PIN_B6
#Pin_select OC4=PIN_C2
#Pin_select OC5=PIN_C7

//COMMS LAN    
#use rs232(baud=9600, UART1, ERRORS)             //RS232 TERMINAL VT100

void main(void)
{
   unsigned int16 value;

 //  output_High(PIN_C2);  //OC1
   output_High(PIN_C4); //CPU

   setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8, 0xFFC0);
   
   setup_adc_ports(ALL_ANALOG);
   setup_adc(adc_clock_internal);
   set_adc_channel(0);
   
   setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);

  while(TRUE)
  {
    value=read_adc();
    set_pwm_duty(1,value * (int16)64);
  }

}

I am not able to get the code output any think. I can drive the o/p on or off OK (output_high/output_low) however when trying the OC pwm on OC1 nothing.
Any guidance will be appreciated. Confused and not Surprised
Wink
_________________
What has been learnt if you make the same mistake? Wink
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 18, 2007 1:10 pm     Reply with quote

As it turned out it was this line
Code:
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 0xFFC0);

I had to increase the rate on timer 2 to get a true value, I was looking at the LED on the output and it showed flickering, it wasn't until I used a multi meter on the output that I saw what was happening. (op amp for 0 to 10V)
now I get a steady LED ranging from 0V to 10V Smile Smile
_________________
What has been learnt if you make the same mistake? Wink
hobgoblin



Joined: 10 Sep 2003
Posts: 7

View user's profile Send private message

RE: Sample code to remap I/O for PIC24FJ256GB110?
PostPosted: Mon Jun 30, 2008 4:33 am     Reply with quote

Hi Storic,

That's great, many thanks, but is this all that is required?

The reason I ask is because Microchip gives example C code for their C30 C compiler that includes dedicated assembly code to unlock and relock the pin that ties up with the same example in the data sheet for the PIC24FJ256GB110.

As I said, up until now I have found no examples of how PICC does it.

Could you please confirm if your PICC example...

#Pin_select U1TX=PIN_B0
#Pin_select U1RX=PIN_B1

...generates and invokes this pin unlock/lock code too? (see below)


Taken from Microchip compiler example:

//INPUTS **********************

//U2RX = RP19
RPINR19bits.U2RXR = 19;

//OUTPUTS *********************

//RP25 = U2TX
RPOR12bits.RP25R = U2TX_IO;

/********************************
* Function: lockIO
* Preconditions: None.
* Overview: This executes the necessary process to set the IOLOCK bit
* to lock I/O mapping from being modified.
* Input: None.
* Output: None.
********************************/
void lockIO(){
asm volatile ("mov #OSCCON,w1 \n"
"mov #0x46, w2 \n"
"mov #0x57, w3 \n"
"mov.b w2,[w1] \n"
"mov.b w3,[w1] \n"
"bset OSCCON, #6");
}

********************************
* Function: unlockIO
* Preconditions: None.
* Overview: This executes the necessary process to clear the IOLOCK
* bit to allow I/O mapping to be modified.
* Input: None.
* Output: None.
********************************/
void unlockIO(){
asm volatile ("mov #OSCCON,w1 \n"
"mov #0x46, w2 \n"
"mov #0x57, w3 \n"
"mov.b w2,[w1] \n"
"mov.b w3,[w1] \n"
"bclr OSCCON, #6");
}

Thanks again in advance,

Adrian
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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