|
|
View previous topic :: View next topic |
Author |
Message |
starfire151
Joined: 01 Apr 2007 Posts: 195
|
PIC24FV32KA301 start-up issues |
Posted: Tue Feb 11, 2014 5:32 pm |
|
|
I'm using PCWHD version 4.137. I've been using the PIC18F family of processors but want to migrate into the PIC24FV family. I created a small program (below) to test the functionality.
With the #use delay(clock=32000000) line and the #use rs232(baud=38400, parity=N, xmit=PIN_A2, rcv=PIN_B2, bits=8) line, I see the output com at 19200 baud (half the rate I expected).
I am also not seeing the LED connected to pin 9 (bit RB4) toggle.
Have I got all the fuses set correctly? I think I specified the internal clock using the *4 PLL for an internal rate of 32MHz? I also specified that the OSCIO pins should be used for general I/O?
It appears the timer ISR is working correctly, though. I tried to set it up for the timer ISR to go off 10 times a second. Every 10th time, it toggles the LED and bumps a running count. The count printed does appear to be incrementing but two sometimes though (once from the background and once from the timer ISR). Again, I'm not seeing the LED toggle.
Any help would be appreciated. This looks to be a very powerful processor but I'm having start-up problems...
Code: |
#include <24FV32KA301.h>
#device adc=12
#fuses ICSP1 // select ICSP1 programming port
#fuses NOWDT
#fuses NOPROTECT
#fuses MCLR
#fuses PUT
#fuses NOBROWNOUT
#fuses FRC_PLL // PLL (osc * 4) High speed osc
#fuses OSCIO // oscillator pins used as general purpose I/O
#use delay(clock=32000000)
#use rs232(baud=38400, parity=N, xmit=PIN_A2, rcv=PIN_B2, bits=8)
#define INTS_PER_SEC 10 // (32,000,000 / (2 * 256)) / 6250
// ---- define I/O default port data and TRIS parameters ----
#define PA_DEF 0b1111111111111111
#define PA_TRIS 0b1111111111111011
// 15 I: NA on 20-pin PIC
// 14 I: NA on 20-pin PIC
// 13 I: NA on 20-pin PIC
// 12 I: NA on 20-pin PIC
// 11 I: NA on 20-pin PIC
// 10 I: NA on 20-pin PIC
// 9 I: NA on 20-pin PIC
// 8 I: NA on 20-pin PIC
// 7 I: NA on 20-pin PIC
// 6 I: VCap on FV part
// 5 I: Pin 1 : MCLR
// 4 I: Pin 10 : unused
// 3 I: Pin 8 : unused
// 2 O: Pin 7 : Tx output to terminal
// 1 I: Pin 3 : unused
// 0 I: Pin 2 : unused
#define PB_DEF 0b1111111111101111
#define PB_TRIS 0b0100111111101111
// 15 O: Pin 18 : unused
// 14 I: Pin 17 : unused
// 13 O: Pin 16 : unused
// 12 O: Pin 15 : unused
// 11 I: NA on 20-pin PIC
// 10 I: NA on 20-pin PIC
// 9 I: Pin 13 : unused
// 8 I: Pin 12 : unused
// 7 I: Pin 11 : unused
// 6 I: NA on 20-pin PIC
// 5 I: NA on 20-pin PIC
// 4 O: Pin 9 : heartbeat
// 3 I: NA on 20-pin PIC
// 2 I: Pin 6 : Rx input from terminal
// 1 I: Pin 5 : PGEC1 prog clock
// 0 I: Pin 4 : PGED1 prog data
#define HEARTBEAT PIN_B4 // 1-second heartbeat toggle
// ---- variable definitions ----
int16 intCount; // interrupt counter
int32 secondsTotal; // total count of running seconds
// ---- initialize the system routine ----
void InitSys(void)
{
output_a(PA_DEF);
output_b(PB_DEF);
intCount = INTS_PER_SEC;
secondsTotal = 0;
}
// ---- real time clock interrupt routine ----
#INT_TIMER1
void ClockISR(void)
{
intCount--;
if(intCount == 0)
{
intCount = INTS_PER_SEC; // reinit timer ints per msec cntr
output_toggle(PIN_B4); // toggle heartbeat output pin
secondsTotal++; // increment local total seconds count
}
}
// ---- main program beginning ----
void main()
{
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_tris_a(PA_TRIS);
set_tris_b(PB_TRIS);
setup_timer1(TMR_INTERNAL | TMR_DIV_BY_256, 6250); // 0.1 sec interrupt
InitSys();
delay_ms(10);
printf("PIC24FV32KA301 Testbed\r\n");
printf("V1.0 Compiled: %s %s\r\n", __DATE__, __TIME__);
printf("\r\n");
delay_ms(100);
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
enable_interrupts(INTR_GLOBAL);
while(TRUE)
{
printf("while() loop %lu...\r\n", secondsTotal);
output_low(PIN_B4);
delay_ms(400);
output_high(PIN_B4);
delay_ms(400);
secondsTotal++;
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Wed Feb 12, 2014 2:33 am |
|
|
Make just two changes:
Get rid of the FRC_PLL fuse, and change the clock line to:
#use delay(internal=32000000).
Problem is that to setup the PLL, the CLKDIV register has to be set as well as the fuses. Because you are saying 'I have control' (setting the fuses, and telling the compiler what clock is being generated), the compiler leaves it to you to set this. However you are not doing it, so it wakes up at a default setting (looks like 4MHz*4).
By instead telling the compiler you want to use the internal oscillator at 32MHz, it changes to saying "right, I've got to set the CLKDIV register".
Select the fuse SOSC_DIGITAL to get RB4 to work.
Best Wishes |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Wed Feb 12, 2014 8:58 am |
|
|
Thanks very much for your help. |
|
|
|
|
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
|