Hopefully an easy problem

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time

Hopefully an easy problem

Post by gggwww »

Simple program in V4 using PIC16F88 with Internal Oscillator
2 delays / 2 LED macros to flash LED 0 on and off at 1 second intervals determined by delays
When building Hex get the following message:

Caution: Delay inaccurrate: 'delay_ms', Delay overhead:0ms, Unit delay:1.00016ms, Delay resolution:1 units

And on download to the PIC

Caution: Delay inaccurrate: 'delay_ms', Delay overhead:0ms, Unit delay:1.00016ms, Delay resolution:1 units

PIC does nothing - thanks for any help

C Code follows from Flowcode:

//************************************************************************************
//**
//** File name: C:\Documents and Settings\waldreng\My Documents\manuals\flowcode\Delaytest.c
//** Generated by: Flowcode v4.0.0.53
//** Date: Wednesday, September 09, 2009 22:15:56
//** Licence: Demo
//**
//** ***DEMO VERSION***
//**
//**
//** NOT FOR COMMERCIAL USE
//**
//** http://www.matrixmultimedia.com
//************************************************************************************


#define MX_PIC

//Defines for microcontroller
#define P16F88
#define MX_EE
#define MX_EE_TYPE2
#define MX_EE_SIZE 256
#define MX_SPI
#define MX_SPI_B
#define MX_SPI_SDI 1
#define MX_SPI_SDO 2
#define MX_SPI_SCK 4
#define MX_UART
#define MX_UART_B
#define MX_UART_TX 5
#define MX_UART_RX 2
#define MX_I2C
#define MX_I2C_B
#define MX_I2C_SDA 1
#define MX_I2C_SCL 4
#define MX_PWM
#define MX_PWM_CNT 1
#define MX_PWM_TRIS1 trisb
#define MX_PWM_1 0
#define MX_PWM_TRIS1a trisb
#define MX_PWM_1a 3

//Functions
#include <system.h>
#pragma CLOCK_FREQ 19660800

//Configuration data
#pragma DATA 0x2007, 0x3f38
#pragma DATA 0x2008, 0x3ffc

//Internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h"

//Macro function declarations


//Variable declarations
char FCV_WHICHLED;


//Defines:

/**** Macro Substitutions ****
porta = LED Port Register
trisa = LED Data Direction Register
7 = Number of LEDs
1 = LED Pin 0
2 = LED Pin 1
4 = LED Pin 2
8 = LED Pin 3
16 = LED Pin 4
32 = LED Pin 5
64 = LED Pin 6
128 = LED Pin 7
******************************/




//LEDarray0: //Macro function declarations

void FCD_LEDarray0_LEDOn(char WhichLED);
void FCD_LEDarray0_LEDOff(char WhichLED);



//LEDarray0: //Macro implementations


void FCD_LEDarray0_LEDOn(char WhichLED)
{
char LEDMask;

if (WhichLED > 7)
{
LEDMask = 0;
}
else
{
switch (WhichLED)
{
case 0:
LEDMask = 1;
break;
case 1:
LEDMask = 2;
break;
case 2:
LEDMask = 4;
break;
case 3:
LEDMask = 8;
break;
case 4:
LEDMask = 16;
break;
case 5:
LEDMask = 32;
break;
case 6:
LEDMask = 64;
break;
case 7:
LEDMask = 128;
break;
}
}
trisa = trisa & ~LEDMask;
porta = porta | LEDMask;
}

void FCD_LEDarray0_LEDOff(char WhichLED)
{
char LEDMask;

if (WhichLED > 7)
{
LEDMask = 0;
}
else
{
switch (WhichLED)
{
case 0:
LEDMask = 1;
break;
case 1:
LEDMask = 2;
break;
case 2:
LEDMask = 4;
break;
case 3:
LEDMask = 8;
break;
case 4:
LEDMask = 16;
break;
case 5:
LEDMask = 32;
break;
case 6:
LEDMask = 64;
break;
case 7:
LEDMask = 128;
break;
}
}
trisa = trisa & ~LEDMask;
porta = porta & ~LEDMask;
}

//Macro implementations

void main()
{

//Initialisation
ansel = 0;
cmcon = 0x07;


//Interrupt initialisation code
option_reg = 0xC0;


//Calculation
//Calculation:
// WhichLED = 0
FCV_WHICHLED = 0;


//Loop
//Loop: While 1
while (1)
{
//Call Component Macro
//Call Component Macro: LEDarray(0)::LEDOff(WhichLED)
FCD_LEDarray0_LEDOff(FCV_WHICHLED);


//dumb
//Delay: 1 s
delay_s(1);


//Call Component Macro
//Call Component Macro: LEDarray(0)::LEDOn(WhichLED)
FCD_LEDarray0_LEDOn(FCV_WHICHLED);


//Delay
//Delay: 1 s
delay_s(1);


}


mainendloop: goto mainendloop;
}

void interrupt(void)
{
}

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Hopefully an easy problem

Post by Benj »

Hello

Ok I can see a few fundemental problems. Internal oscillator devices startup at 31.25KHz by default. This combined with the clock speed of 19.6608MHz you have specified means that the 1 second delays in your program will probably take hours to complete.

1) If you are using the internal oscillator then you need to first configure the internal clock speed. This is done by adding a C code block to the very start of your program with one of the following lines depending on your desired clock speed.

osccon = 0x00; //31.25KHz
osccon = 0x10; //125KHz
osccon = 0x20; //250KHz
osccon = 0x30; //500KHz
osccon = 0x40; //1MHz
osccon = 0x50; //2MHz
osccon = 0x60; //4MHz
osccon = 0x70; //8MHz

2) Next click on Edit -> Project options and ensure that the clock speed specified here matches your above setting.

3) Finally click on Chip -> Configure and ensure the setting is set to Internal and click OK.

Now recompile to your device and you should be up and running correctly.

gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time

Re: Hopefully an easy problem

Post by gggwww »

Thanks !!! - that did the trick

Anonther question - the PIC16F88 runs my program fine ( sequencing 8 LED's on PORT B) when the PICkit2 Programmer is connected to the USB port on the PC. When I disconnect the programmer from the PC USB port the program on the PIC stops execution. When I reconnect the programmer to the PC USB port then the program runs.

Thoughts??

Thanks!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Hopefully an easy problem

Post by Benj »

Hello

It sounds like the PICkit is either supplying your VDD (5V) supply or is supplying the MCLR (reset) whereas your normal circuit is not. Make sure you have connected the MCLR pin to VDD via a 1K - 10K resistor and that the VDD is a stable 5V.

gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time

Re: Hopefully an easy problem

Post by gggwww »

Ben,

Thanks for help on both the Delay question and the MCLR question. 10K pull up to VDD on MCLR did the trick.

Best Regards,
George

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Hopefully an easy problem

Post by Benj »

Hi George

Thats great thanks for letting me know :mrgreen:

Post Reply