Author Topic: Help Again! My First PIC18F25K22 project should..but it doesn't blink a LED.  (Read 8310 times)

0 Members and 1 Guest are viewing this topic.

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Thanks for your comments, Bruce Abbot,

The difference between the 0x0d and 0x80 is due to a minor modification that revised the .hex file slightly.
I made his change to make sure that TMR1 had fewer counts to count since I was worried the time allotted to TMR1 by the SW only loop might expire before TMR1. I apologize for not updating my original post while posting a slightly changed .hex file.

I thought this change was insignificant and not affecting the greater problem of having no blink and no low-priority ISR working.

Thanks picandmix, especially for your generosity for offering me a chip. Although this programmer may still be a work in progress, I am very satisfied with what I have created and I truly enjoy the fact that I can modify my HW/SW to fit my fancy at anytime.

To me this is priceless.

I also know that future modifications required  for other chips will be rather trivial.

I think my programmer is working properly, but now I realize that I must also RTFM to know how a chip works to create a test program clever enough to test my programmer.

Please, someone send me a .hex file for a simple program known to work properly, one that will test the operation of priority interrupts with the 18Fx5K22 or similar.

« Last Edit: June 18, 2015, 11:56:33 am by SuzyC »
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Thanks Lewis, for allowing me to find a way to spend almost $500 um...more like $100 USD on something I can build myself..as you can see.

This link is just another link to the poorhouse.
« Last Edit: June 18, 2015, 04:12:54 pm by SuzyC »
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Thanks picandmix, I ebayed the Pickit2 and see it is currently available from Hong Kong. 

I've tried, but Ijust can't get used to the up to 2-month delay in delivery due to snail mail by boat and customs, etc. In this period of time I could build my own! The site says delivery between Jun. 30 and Fri. Jul. 17

There are other issues at stake here, the low price may mean that the device may be poorly constructed, or not actually work or it is a scam. If I find that this device is being sold by a reputable ebay store, I could probably return it for a full refund, just have to wait a month for it to get back to Hong Kong (by boat, and maybe by this time election issue riots have caused China's hard hand policy to just nuke the whole area), I could then wait another month or so for a replacement to arrive.
I recently purchased a set of different tweezers for SMD work, seemed to be bargain price, and they never, ever arrived, just a <$20 deal, but money lost all the same.

In any case, if I had a pickit2 or 3 or whatever, if my dog decided the plastic thing was tasty or if I somehow managed to blow its #@#7@! brains out I wouldn't be able to fix it myself and would have to wait another 1 to 2 months for another or pay a king's ransom to buy one locally.
« Last Edit: June 18, 2015, 12:47:30 pm by SuzyC »
 

Offline senso

  • Frequent Contributor
  • **
  • Posts: 951
  • Country: pt
    • My AVR tutorials
Thanks Lewis, for allowing me to find a way to spend almost $500 USD on something I can build myself..as you can see.

This link is just another link to the poorhouse.

500$ where???
An original PicKit3 costs less than 50$  :-//
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Yes, Ebay China can be gamble, though I only order lo value items to avoid import duties and taxes.
Normally only takes 10 -14 days from China.

Quote
Please, someone send me a .hex file for a simple program known to work properly, one that will test the operation of priority interrupts with the 18Fx5K22 or similar.


Am sure the K22 will do such functions like all the other chips, but cannot see how that will help you with your programmer problem.

If no one comes up with such code for you, then I will do some for you later tonight

In the mean time, surely the best way would be to do a most basic program using a basic 4 or 8 mhz internal osc and just turn one ports outputs to high and another ports outputs to low; and nothing more.
That should work on your chip /progammer.

If it does not, then send your .hex code for me to test on my k22 dev board.
 

Offline lewis

  • Frequent Contributor
  • **
  • Posts: 702
  • Country: gb
  • Nullius in verba
Thanks Lewis, for allowing me to find a way to spend almost $500 USD on something I can build myself..as you can see.

This link is just another link to the poorhouse.

Not sure where you got 500 bucks from. Pickit3 is even cheaper and more current.
I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Senso, I just clicked on the link posted about this bargain.

 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Re: Help Again! My First PIC18F25K22 project is blink'n (Solved)
« Reply #32 on: June 18, 2015, 03:31:41 pm »
Thanks again, picandmix, you are a nice guy to help so much.

I realized that I was creating my own troubles by making my test program overly complicated, so I thought more carefully and tried to write some code that was short and to the point.

The result is:
1) The chip now blinks the LEDS and has proved it can work correctly with in Priority Interrupt Mode and Hi-Tech 9.80 works.
     This is the short test and uses minimal code to do the job
2) I tested the program also by editing in the short version I just created into a monster c-source file that I does math and  has so much nonsense code that it uses 98.6% of available code space. Compiles and  works perfect as well.
//=============================== This One Works! ========================================
/* Test for PIC18F25K22 that works

   My Second PIC18F25K22 Program:

   Program only slowly blinks LEDs and shows operation of priority mode interrupts
*/
#include <htc.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <P18f25k22.h>

/*
#pragma config FOSC=0x8;   //By itself also sets PRICLKEN=1 bit5 of CONFIG1H
#pragma config PRICLKEN=1; //Primary Clock is always enabled
#pragma config FOSC=0x5;   //Coofig1H Default 0x2500    0001=0x25

#pragma config BORV=0;     //Config2L Vdd level for BOREN to reset at                 
#pragma config BOREN=0;    //BOREN Disabled
#pragma config PWRTEN=1;   //                           0002=0x1F
#pragma config WDTPS=0;    //Ratio of Number of Clocks/WDTimerTic
#pragma config WDTEN=0;    //WatchDog Enable Disabled   0003=0x3F ater erase

#pragma config MCLRE=1;  //Pin 1 is *MCLR reset, not I/O pin
#pragma config PBADEN=0; //PORTB<0:5>are I/O pins not A2d inputs after reset
#pragma config T3CMX=1;  //HFINTOSC is not delayed at startup
#pragma config CCP2MX=1; //CCP2 in/out is Mtplxd with RC2
#pragma config DEBUG=1;  //Background Debugger is disabled
#pragma config XINST=0;  //Extended instruction set DISABLED
#pragma config LVP=0;    //LV programming disabled
#pragma config STVREN=1; //Reset on Stack Overflow or Underflow Enabled
*/                       //Allow internal/external clock swithover in OSCCON
#pragma config IESO=1;   //Needs to be=1 for SCS to work to set clk source
#pragma config PBADEN=0;             
#pragma config WDTEN=0;    //WatchDog Enable Disabled   0003=0x3F ater erase
               //Bit   7      6          5        4       3210
               //    IESO   FCMEM     PRICLKEN  PLLCFG    OSC SELECT
               // Int-Ext   FailSafe            no effect 0010 Xtal
               // ClkSwEn   Clock Mon           HFINTOSC  1000 INTHFOSC
               //    1=En     0=off   1=En        x       1000
               //OSCCON SCS=0 to select above or else no 64MHz operation
__PROG_CONFIG(1,0x8800); //Internal Osc Block at 16MHz x 4 with PLL
__PROG_CONFIG(2,0x0);    //BOREN and WDTEN both disabled
__PROG_CONFIG(3,0xBD00); //PBADEN disabled PORTB<5:0>are I/O not A2d at reset
__PROG_CONFIG(4,0x85);
__PROG_CONFIG(5,0xC00F); //CONFIG4 to CONFIG7 set Read and Write protects
__PROG_CONFIG(6,0xE00F);
__PROG_CONFIG(7,0x400F);


#define Off           0
#define OFF           0
#define off           0
#define On            1
#define ON            1
#define on            1
#define None          0


                               //Break the ports down to their bits
#define PB(port,bit)  ((unsigned) & (port)*8 + (bit))
static bit abit0 @ PB(PORTA,0);
static bit abit1 @ PB(PORTA,1);
static bit abit2 @ PB(PORTA,2);
static bit abit3 @ PB(PORTA,3);
static bit abit4 @ PB(PORTA,4);
static bit abit5 @ PB(PORTA,5);
static bit abit6 @ PB(PORTA,6);
static bit abit7 @ PB(PORTA,7);

static bit bbit0 @ PB(PORTB,0);
static bit bbit1 @ PB(PORTB,1);
static bit bbit2 @ PB(PORTB,2);
static bit bbit3 @ PB(PORTB,3);
static bit bbit4 @ PB(PORTB,4);
static bit bbit5 @ PB(PORTB,5);
static bit bbit6 @ PB(PORTB,6);
static bit bbit7 @ PB(PORTB,7);

static bit cbit0 @ PB(PORTC,0);
static bit cbit1 @ PB(PORTC,1);
static bit cbit2 @ PB(PORTC,2);
static bit cbit3 @ PB(PORTC,3);
static bit cbit4 @ PB(PORTC,4);
static bit cbit5 @ PB(PORTC,5);
static bit cbit6 @ PB(PORTC,6);
static bit cbit7 @ PB(PORTC,7);

static double        ttemp=0;


void interrupt high_priority(void)
{
  if (INT0IF)      //When INT0IE is enabled, bbit1 lights and stays on when INTI0 is triggered falling edge
   { INT0IF = 0;   
     bbit1=1;
   }
  if (TMR1IF)
   {  TMR1IF=0;    //During the time INTI0 is enabled TMR1IF is manually set and bbit3 toggles with Sw press
      if(bbit3==0)   //In this case,  if TMR1IP=1, it is hi-priority, INT0 is always hi-priority
       { bbit3=1;
       }
      else bbit3=0;
   }
}//end of high-priority interrupt

void interrupt low_priority lp(void)
{
  if(INT0IF)       //During the time INT0IE=0 and TMR1IP = 0, lo-priority, INTIOF will be set in any case
   { INT0IF=0;     //by a swith press
     bbit1=0;      //I can tell I am in this mode also because bbit1 LED is not lit
   }
  if (TMR1IF)      //If TMR1IF is triggered by a Sw. press, bbit4 will toggle
   { TMR1IF=0;
     if(bbit4==0)
      { bbit4=1;
      }
     else bbit4=0;
   }
}// end of low priority interrupt


//____________________________ MAIN ___________________________________
void main(void)
{
Reset:

  OSCCON=0x70;  //Selects Int Osc Block Clk as internal clock source
  OSCTUNE=0x5F; //Highest Internal OSC Freq OSCTUNE<0:5> set freq. PLLEN=bit6
                //OSCTUNE<6:0>set freq 011111 =16MHz
  PLLEN=1;      //Enables PLL Fosc=Fosc*4 = 64MHz with Internal 16MHz osc.
//PLLRDY        //Status Bit 1=PLL ON


  INTEDG0=0;    //interrupt on falling edge
  PORTB=1;
  TRISB = 0x1;  //INTO pin set for digital input
  INT0IE = 1;   //Enable INT0 interrupt
  INT0IF = 0;   //needs to be reset in either ISR
  TMR1IE=1;    //TMR1IF is manually set along with INT0IF in this test program

  IPEN=1;        //Interrupt Priority Mode enabled
/* NOT NEEDED
  PEIE=1;
  PIE1=1;
  PIE2=1;
*/
  GIEL=1; //enables lo-priority IRQs
  GIEH=1; //enables Lo and Hi priority IRQs, if off, all IRQ's are disabled
//----------------------------------------------------------------------
  Start:
  for(ttemp=0;ttemp<120000;ttemp++)//An approx  several seconds timed loop at 16MHz x 4
   { bbit7=1;         
                      //There is a a 1K resistor connected to each LED to Vss, bbit7 LED is just a heartbeat             
     INT0IE=1;
     TMR1IP=1; //For this timed interval TMR1 is hi-priority
     if(bbit0==0)TMR1IF=1; //Manual sets both IRQ flags with a sw.
                                         //During this interval, only bbit3 should toggle with a debounced sw. press
   }
  for(ttemp=0;ttemp<120000;ttemp++) //Takes about  several seconds at 16MHz x 4
   {
     bbit7=0;  //during this timed interval bbit4 should toggle with each clean sw press

     INT0IE=0;
     TMR1IP=0; //During the SW timed interval, TMR1IF is low-priority
     if(bbit0==0)TMR1IF=1;  //This still triggers INT0IF even if it's interrupt is disabled
   }
  goto Start;
}
//========================   END of MAIN   ==================================
« Last Edit: June 18, 2015, 05:42:21 pm by SuzyC »
 

Offline senso

  • Frequent Contributor
  • **
  • Posts: 951
  • Country: pt
    • My AVR tutorials
Senso, I just clicked on the link posted about this bargain.
The link shows:
Price: £43.57

Still far away from 500$
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
More like $USD 64.40 + shipping+customs+tax, still looks like a $100 deal, and that will fill a lot of diapers for my baby, and shipping adds  a wait as well

 I made a very bad guess about the exchange rates.
« Last Edit: June 18, 2015, 05:39:18 pm by SuzyC »
 

Offline Skimask

  • Super Contributor
  • ***
  • Posts: 1425
  • Country: us
In any case, if I had a pickit2 or 3 or whatever, if my dog decided the plastic thing was tasty or if I somehow managed to blow its #@#7@! brains out I wouldn't be able to fix it myself and would have to wait another 1 to 2 months for another or pay a king's ransom to buy one locally.
Except that Microchip has all of the schematics, code, etc. all posted in the manual PDF.
And how long have you spent on this anyways? A month?  Two months?  A year?
Is your hours and hours of messing around trying to get a homemade thing to work worth that little that a ~$50 programmer isn't worth it?
2 months for shipping?  Surely you haven't looked around hard enough to find a PICKIT2/3 clone.  I've got 4 on the bench next to me, one each authentic Microchip PICKIT2 and PICKIT3, and one each knockoff clone PICKIT2 and PICKIT3.  Both of the knockoffs had to get code updates.  No problems there.
Just buy one that works and get on with it...
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline senso

  • Frequent Contributor
  • **
  • Posts: 951
  • Country: pt
    • My AVR tutorials
More like $USD 64.40 + shipping, still looks like a $100 deal, and that will fill a lot of diapers for my baby, and shipping adds  a wait as well

 I made a very bad guess about the exchange rates.

Mouser as PicKit's, as does Digikey, and in the USA you get free or next to free shipping!
48$:
http://www.digikey.com/product-detail/en/PG164130/PG164130-ND/2171224

51$:
http://www2.mouser.com/ProductDetail/Microchip-Technology/PG164130/?qs=sGAEpiMZZMtqy0n2JbDgYFNAcWahhP9A

If your Pickit3 breaks(and it wasn't a massive short caused by user), you open a ticket and Microchip sends you a new one and a pre-paid letter to send them the broken one.
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
It was worth every second.

I learned a lot about programming, troubleshooting, RTFM, PIC18FxK22 chips, and I have something that is truly my own creation, with some many thanks of course, to all those who were so kind to give me a hint now and then.

Now I can edit, compile, program, verify, set fuses, all with one mouse click.

And if it needs repair, I know it is so easy to fix, only need to keep a few LSTTL gates around for spares.

If I don't like the way it works, I can change it anytime I want.

No money spent, no unreliable USB connections, no begging Microchip for updates..no waiting for a slow boat to and from China.

PRICELESS!
« Last Edit: June 18, 2015, 05:40:13 pm by SuzyC »
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 616
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
I think my programmer is working properly,
Yes. I simulated your hex on MPLAB and it misbehaved as you described, indicating a coding error.

So it appears that your programmer is actually working fine. Are you willing to share your final VB code with us? I would like to try making a programmer using your code, for a computer that is not PC compatible but can run programs written in BASIC.
     



 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Full marks for your DIY  programmer . most like me , go the easy way.....
 
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Abbot, if you don't have PC that is very PC compatible, get one first. In most areas of the developed economy world, most people will pay you to take their older 486, AMD ATHLON 64 or even a socket 775 processor-based machine off their hands. On my workbench, I am using a 486 2.8GHz 1-meg fastcache, 1GB DDRAM supported single core processor small-profile HP desktop that was discarded and it works great and it was free and programs a chip as fast as PICKIT3.
« Last Edit: June 19, 2015, 03:00:23 pm by SuzyC »
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Hey thanks again for the complement, 22swg,

To each their own, people climb a mountain not because it is necessary, not to play bridge at the top, but to enjoy the climb, the challenge that somehow they've might get there, despite the mountain, and with the profound discouragements of friends, employers and family, they somehow managed to get to the top.
 
Perhaps Kennedy could have said in the thick of the space race with the USSR, "We will go to the moon, not because it is easy, but because it is hard!..Therefore I have decided we will hire the Chinese to do it for us and I will save our country trillions of dollars!"

BTW, you recommended that I chose a chip on a stick approach, do you think that would have been a better faster MCU choice than the PIC18 I decided was more compatible with working the way I liked?
« Last Edit: June 19, 2015, 03:14:20 pm by SuzyC »
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Hi, Suzy ..each to his own I guess , It was just that you seem to like to type code like its going out of fashion , not looked at PIC18 much ,thinking you will hit a wall . Is this still the robotics ?     
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Full marks for your DIY  programmer . most like me , go the easy way.....
 

Yes, +1 on that, well done.

However , without being negative,  I feel your efforts may not hold long term when you want to move to other ranges of chips from MC.
Also the parallel port will probably soon be obselete even on desktops.

A real downside you may not yet appreciate is that your programmer cannot perform any hardware debugging;  that can be an extremely useful function.

Am sure you feel happy with your 486, and I have often been accused of being a luddite in respect of PCs , but feel you really are missing out on some of the better aspects , like improved secuirty, ability to run some of the very good free modern programs like Studio8 etc.

XP does sometimes have USB problems, but since I moved from XP to W8 I've never had any such trouble and am using many different usb devices.

If you can find a Pentium based base unit, does not have to be an i Core even a lowly Core 2 Ennnn will do, with W7 or W8 for free or very little , then you will see a dramatic improvment over the 486, not just in speed but in what new work you can do on it.


 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Thanks for your concern, picandmix.

I can only work with one or two different MCU's at a time, and I don't see a problem modifying my programmer's code to adapt to any new candidates to play with, now that I know how to do this easily.

I would as soon give up PC's altogether than submit to  using Win8, pure garbage, and I am just one of millions of others that agree to that, turns a powerful PC workstation into a toy smartphone that has a most obnoxious, clumsy  user interface that makes it so damn hard to anything other than  email, Twits,  Facebook and download XXX. For doing anything serious with a computer, Windows XP or Win7 is still  the best. I don't do Studio 8  video or Fruitloops or Flash with Macromedia, I do flash code. I have the bench PC networked so I can program on my fast PC and my compiler just copies the .hex file to the 486 to program the chip at my work bench. I make my music on my guitar or piano.

The 486 PC is just a handy tool on my workbench, I have made a Parallel port debugging tool that works so well with it. It is plenty fast enough for what I ask it to do and I have a super fast desktop for code generation and other tasks.

I am not at all worried about the parallel port being becoming obsolete, there are many add-on cards to offer even faster Parallel Port performance on a PCI express or PCI addon card. The Parallel Port is so simple an outside world interface, absolutely stable and my programming .exe can be invoked and programming within microseconds, it is fast and crash-free and I love it for that.

Don't get me wrong, I not a USB hating Ludite,  I have USB headphones, USB mouse, USB laser printer, USB this and USB that, its plenty good enough for toy tasks.
« Last Edit: June 19, 2015, 10:16:19 pm by SuzyC »
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 616
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Abbot, if you don't have PC that is very PC compatible, get one first.
I have four PCs and a PICKIT2, so I don't need another programmer. However I also have an NEC PC8201A (http://www.hembrow.eu/personal/necpc8201a.html) which I use on the workbench. For this purpose it has several advantages over a modern PC - TTL level serial and parallel ports, BASIC and TELCOM in ROM (boots instantly!), and a four cell AA battery which runs it for 8 hours and keeps the current session in RAM for up to 3 months on standby.

25 years ago I used a PC8201A for programming PABX systems. Today retro computing is my hobby, and I want see what I can get these old machines to do with the aid of cheap new hardware (stuff that would have cost an arm and a leg 20 years ago). I like using BASIC for interacting with projects via the parallel port. No waiting several minutes for the PC to boot up and load a bloated IDE. No need to compile and download firmware. No overly-protective operating system getting in the way. Just type 'OUT port, number' and get instant results!
               
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 546
Good Show, Abbott.

My program is written in VB6 which is its own way is simulating a C-language appropriate task, but in any case, when dealing with VB, you need a PC with XP to do the job. You can take a look at my other earlier postings here that show most of my programming code written in VB6, but an attempt to program a 32K or 64K flash mem of a MCU in BASIC would be painfully slow, if it at all could handle a 32K to 64K array that cache the converted .hex file bytes for programming and verification, memory dumps, etc.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf