Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 2nd July 2009, 02:58 PM   #31
Default

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)
Burt:
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)
3v0 is offline  
Old 2nd July 2009, 05:07 PM   #32
Default

Quote:
I would be glad to help you get it working if you are using the tutorial.
I just setting here making this up as I go LOl mine did the same thing his did
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
Attached Thumbnails
C18 Questions-test3.png  

Last edited by be80be; 2nd July 2009 at 05:43 PM.
be80be is offline  
Old 2nd July 2009, 08:21 PM   #33
Default

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
here for C18 where is it set I tried it in the main code didn't work it not set here
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>
You can see the #define for it but I can't fine where it was set
Code:
#define osccon_   OSCCONbits
fine that part and it will blink. where the
Code:
 OSCCON = 0x72;
the code running at snail speed LOL
If you build with BoostC it works fine

Last edited by be80be; 2nd July 2009 at 08:30 PM.
be80be is offline  
Old 2nd July 2009, 08:39 PM   #34
Default

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.
Triode is offline  
Old 2nd July 2009, 10:36 PM   #35
Default

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;
I have verified they are working by commenting them in and out to produce various clock speeds.

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)
3v0 is offline  
Old 2nd July 2009, 10:50 PM   #36
Default

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
Attached Thumbnails
C18 Questions-maybe.png   C18 Questions-maybe1.png  

Last edited by be80be; 2nd July 2009 at 10:57 PM.
be80be is offline  
Old 2nd July 2009, 10:59 PM   #37
Default

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)
3v0 is offline  
Old 2nd July 2009, 11:11 PM   #38
Default

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
And here the
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;
  }
}
be80be is offline  
Old 2nd July 2009, 11:15 PM   #39
Default

Quote:
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.
That may be it because it was saving back to the wrong file at first so i deleted it and put just one copy on C:\ the program is running at snail speed LOL got me

Last edited by be80be; 2nd July 2009 at 11:17 PM.
be80be is offline  
Old 2nd July 2009, 11:28 PM   #40
Default

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)
3v0 is offline  
Old 3rd July 2009, 04:08 AM   #41
Default

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.
be80be is offline  
Old 3rd July 2009, 01:19 PM   #42
Default

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)
3v0 is offline  
Old 3rd July 2009, 03:31 PM   #43
Default

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
Attached Files
File Type: zip test1.zip (6.1 KB, 3 views)
be80be is offline  
Old 3rd July 2009, 03:46 PM   #44
Default

I ziped the whole folder here is it is
Attached Files
File Type: zip wholething.zip (16.7 KB, 3 views)
be80be is offline  
Old 3rd July 2009, 06:01 PM   #45
Default

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)
3v0 is offline  
Reply

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



All times are GMT. The time now is 05:38 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker