![]() | ![]() | ![]() |
| | #31 |
|
Triode: The only thing odd that I could find is that the PICkit2 software said the HEX had LVP enabled when the C source code has it disabled. The code is about a year old and this is the first time I have had anyone report this problem. I am not saying I write perfect code, the problem is where it is. Regardless of the cause I would be happy to help you. The code can be run under the Junebug debugger or with MPLAB SIM. To halt execution on each state change you can set a breakpoint inside each task on the switch statment Code: switch (seq) We can also look at the fuse settings in MPLAB. There is not much point in running the code using the PICkit2 software because the code interaction is best seen with a debugger. I would be glad to help you get it working if you are using the tutorial. 3v0
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #32 | |
| Quote:
I tried the Hex from the down load and it works fine. But I'm done with this 3v0 I read your tutorial set it like you showed I no it worked for you and it will for me there some reason it's not setting the chip up right it may be that I'm using mplab 8.33 now only reason I use the pickit2 is I like the way it works I no you can use mplab to I just like the pickit2 to look at the hex the one that came with the down load is not the same as whats being built. How this for output It no biggie I'll get it to work when I have more time thanks 3v0 Last edited by be80be; 2nd July 2009 at 05:43 PM. | ||
| |
| | #33 |
|
Triode you have one led come on ans stay on that's whats happen with me I'm using 8.33 and I can tell you this for sure the osc is not set to run at full speed if you try the hex that was in the down load it works when I build it my self it doesn't set the osc now if you look at the red part it's set for boostC you can see it is set for 8 mhz Code: #ifdef _BOOSTC #define FOUND_COMPILER #define lata_ lata #define trisa_ trisa #define porta_ porta #define latb_ latb #define trisb_ trisb #define portb_ portb #define intcon_ intcon #define intcon2_ intcon2 #define osccon_ osccon #define t0con_ t0con #define t0con__ t0con #define adcon1_ adcon1 #include <system.h> #pragma CLOCK_FREQ 8000000 #pragma DATA _CONFIG1H, _INTIO2_OSC_1H #pragma DATA _CONFIG2H, _WDT_OFF_2H #pragma DATA _CONFIG3H, _MCLRE_ON_3H #pragma DATA _CONFIG4L, _LVP_OFF_4L #endif it's pointing some where else Code: #ifdef __18CXX #define FOUND_COMPILER #define lata_ LATA #define trisa_ TRISA #define porta_ PORTA #define latb_ LATB #define trisb_ TRISB #define portb_ PORTB #define intcon_ INTCONbits #define intcon2_ INTCON2bits #define osccon_ OSCCONbits #define t0con__ T0CONbits #define t0con_ T0CON #define adcon1_ ADCON1 #pragma config OSC = INTIO2, FSCM = OFF, WDT = OFF, LVP = OFF #include <p18f1320.h> Code: #define osccon_ OSCCONbits Code: OSCCON = 0x72; If you build with BoostC it works fine Last edited by be80be; 2nd July 2009 at 08:30 PM. | |
| |
| | #34 |
|
haha, well I still haven't been able to try any of this since my first post about this code last night, I'm still at work. But I'm sure in a few hours once I give it a try we can get this working. I never have gotten timers figured out, so thats really what I'm working on here. The multitasking method makes perfect sense to me.
| |
| |
| | #35 |
|
Burt, The internal clock speed is set by these lines Code: // speed up the clock to 8MHz, 18F1320
osccon_.IRCF0=1;
osccon_.IRCF1=1;
osccon_.IRCF2=1;
Perhaps you are building with the " Configuration bits set in code" box unchecked. It can be found under Configuration>Configuration_Bits If that is the case you are over riding the fuse settings in the code. Code: #pragma config OSC = INTIO2, WDT = OFF, LVP = OFF
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #36 |
|
I didn't change any thing at all till the led didn't flash and I put that back like it was but maybe this is It also said my compiler is not the same as what was use for this project
Last edited by be80be; 2nd July 2009 at 10:57 PM. | |
| |
| | #37 |
|
MPLAB is not the most stable IDE in the world. Check to see if you are using the fuses from the program or from the IDE. It may not be saving or reading that as part of the project. If using the fuses from the program fixes it we have found the problem. EDIT: Be sure to do a build all.
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #38 |
|
3v0 look at this and see if it the same as you have it the multiCompiler.h this is what I'm using Code: /*
* Junebug Demo
* Purpose: Demonstrate cooporative multitasking
*
* File: multiCompiler.h
* Software: BoostC or Microchip C18 compilers
* Hardware: Junebug (or other debugger + breadboarded circuit)
*
* These defiles allow the use of more then one compiler.
* Register names ending with a single _ are byte referances.
* Register names ending with a dual __ are bit referances.
*
* by Daniel Johnson
* July 2008
*/
#ifdef _BOOSTC
#define FOUND_COMPILER
#define lata_ lata
#define trisa_ trisa
#define porta_ porta
#define latb_ latb
#define trisb_ trisb
#define portb_ portb
#define intcon_ intcon
#define intcon2_ intcon2
#define osccon_ osccon
#define t0con_ t0con
#define t0con__ t0con
#define adcon1_ adcon1
#include <system.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA _CONFIG1H, _INTIO2_OSC_1H
#pragma DATA _CONFIG2H, _WDT_OFF_2H
#pragma DATA _CONFIG3H, _MCLRE_ON_3H
#pragma DATA _CONFIG4L, _LVP_OFF_4L
#endif
// MCC18
#ifdef __18CXX
#define FOUND_COMPILER
#define lata_ LATA
#define trisa_ TRISA
#define porta_ PORTA
#define latb_ LATB
#define trisb_ TRISB
#define portb_ PORTB
#define intcon_ INTCONbits
#define intcon2_ INTCON2bits
#define osccon_ OSCCONbits
#define t0con__ T0CONbits
#define t0con_ T0CON
#define adcon1_ ADCON1
#pragma config OSC = INTIO2, WDT = OFF, LVP = OFF
#include <p18f1320.h>
// code to make C18 interrupt look like BoostC's
void interrupt(void);
#pragma code low_vector=0x18
void low_interrupt (void)
{
_asm GOTO interrupt _endasm
}
#pragma code
#pragma interruptlow interrupt
#endif
#ifndef FOUND_COMPILER
error: unknown compiler
#endif
Code: /*
* Junebug Demo
* Purpose: Demonstrate cooporative multitasking
* using 1 Junebug LED + AC coupled speaker on RB1
*
* File: DJ_coop2.c
* Software: BoostC or Microchip C18 compilers
* Hardware: Junebug (or other debugger + breadboarded circuit)
*
* by Daniel Johnson
* July 2008
*/
#include "multiCompiler.h"
//
// defines & macros
//
#define TRUE !0
#define FALSE 0
#define byte unsigned char
#define uInt unsigned int
#define state case
#define KMAX 3
#define BLINK 0
#define BEEP 1
#define DUR 2
#define TASK_BLOCKED 0xFFFF
#define LED_BIT_HI porta_=0b00000001
#define LED_BIT_LO porta_=0b00000000
#define SPEAKER_BIT_HI portb_=0b00000010
#define SPEAKER_BIT_LO portb_=0b00000000
// allocate KMAX kTimers
uInt kTimer[KMAX];
byte waitForTimer;
void interrupt(void)
{
byte k;
// clear the IF
intcon_.TMR0IF = 0;
for (k=0;k<KMAX;k++)
{
// hold at 0
if((kTimer[k]) && // stop at zero
(kTimer[k]!=TASK_BLOCKED)) // task is blocked
{
kTimer[k]--;
}
}
waitForTimer = FALSE;
}
void taskBlink(void)
{
static byte seq=0;
switch (seq)
{
state 0:
LED_BIT_HI;
seq=1;
break;
state 1:
LED_BIT_LO;
seq=0;
}
// set when to run again
kTimer[BLINK]=1953;
return;
}
void taskBeep(void)
{
static byte seq=0;
switch (seq)
{
state 0: // state INIT
kTimer[DUR]=750;
seq=1;
break;
state 1: // state ON
SPEAKER_BIT_HI;
kTimer[BEEP]=2; // 1000 Hz
seq=2;
break;
state 2: // state OFF
SPEAKER_BIT_LO;;
if(kTimer[DUR]) // another pulse
{
kTimer[BEEP]=2;
seq=1;
}
else // generate a rest
{
kTimer[BEEP]=750;
seq=0;
}
}
}
//
// --- main ---
//
void main (void)
{
byte i;
// setup
{
// speed up the clock to 8MHz, 18F1320
osccon_.IRCF0=1;
osccon_.IRCF1=1;
osccon_.IRCF2=1;
// configure ports
adcon1_ = 0xFF; // all digital
// Switches on RB0 RB2 and RB5
//intcon2_.RBPU = 0; // PORTB weak pullups for switches
trisb_ = 0xFD; // speaker on RB1
lata_ = 0;
trisa_ = 0xBE; // RA0 and RA6 ouputs 0b1011 1110;
// configure Timer0
t0con_ = 0xD0;
intcon_.TMR0IF = 0; // clear the IF
intcon_.TMR0IE = 1; // enable TMR0 overflow interrupt
t0con__.TMR0ON = 1; // turn on TMR0
intcon_.GIE = 1; // enable global interrupts
// zero out the counters
for (i=0; i<KMAX;i++)
{
kTimer[i] = 0;
}
}
// kTimer[BEEP] = TASK_BLOCKED; // disable taskBeep
while(1) // main loop
{
if (!kTimer[BLINK])
{
taskBlink();
}
if (!kTimer[BEEP])
{
taskBeep();
}
while(waitForTimer);
waitForTimer = TRUE;
}
}
| |
| |
| | #39 | |
| Quote:
Last edited by be80be; 2nd July 2009 at 11:17 PM. | ||
| |
| | #40 |
|
To test for this problem I downloaded the .zip file from my site, uncompressed it and loaded the project in MPLAB. We should have the same bits. I replaced my files with the code you just posted and it works also. At this point I am 90% sure the problem is not with the code. For me that is a fairly high degree of confidence. Given that the HEX bits I included work and the ones you build do not the problem has to be in your build environment. Maybe one of the other members who use C18 and MPLAB could give it a go. 3v0
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #41 |
|
3v0 I can build with BoostC and it works fine I even reinstalled mplab and C18 and build any program but this one with it and it works fine.
| |
| |
| | #42 |
|
I need to debug the compiled nonworking code. Please make a zip of your MPLAB project file and attach it. 3v0
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #43 |
|
Here the whole thing I looked at the zip it should have all the file that was used It don't look right the zip is what mplab makes I'll zip the whole folder and post it after you look at what mplab ziped
| |
| |
| | #44 |
|
I ziped the whole folder here is it is
| |
| |
| | #45 |
|
You changed the linker script from 18F1320i.lkr to 18F1320_g.lkr from the asm toolchain. If you build your project with either 18F1320i.lkr or 18F1320.lkr it will work.
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
|
| Tags |
| c18, questions |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| A few questions | erosennin | Feedback/Comments | 24 | 29th November 2007 12:08 AM |
| 2 questions | juan123 | Electronic Projects Design/Ideas/Reviews | 5 | 27th September 2007 03:46 AM |
| A few questions. | Marks256 | General Electronics Chat | 55 | 5th August 2006 11:49 PM |
| few questions | Victor Frankenstein | General Electronics Chat | 13 | 5th July 2005 07:29 PM |
| Questions? | Philipc | Electronic Projects Design/Ideas/Reviews | 4 | 7th August 2003 07:18 PM |