Jump to content
medelec35

Sourceboost Ide & Timing With Stopwatch Plugin

Recommended Posts

I have an issue with my first sourceboost C code:

#include <pic16f877a.h>
#include <system.h>


#pragma CLOCK_FREQ 4000000 //Set clock frequency


#pragma DATA _CONFIG, _PWRTE_OFF & _WDT_OFF & _HS_OSC & _CP_OFF //Target PIC16F877A configuration word




void main()
{
 trisb=0;
 while(1) 
 {
portb.0=1;
delay_ms(500);
portb=0x0;
delay_ms(500);
 }
}

The issues are.

The timing are suppose to be 500ms but stop watch and a different simulator are both showing the delay as 244ms:post-5144-0-69551300-1398893210_thumb.png

Also the green simulation step line is going below the last brace for some reason?

 

Since this since my first attempt, it's more than likely I'm doing something daft.

I'm grateful for any advice with what is going wrong please.

 

Thank you.

 

 

 

Share this post


Link to post
Share on other sites

You cannot have a any timer argument greater than 255.

The timer functions take a char value (8 bits).

 

Turn on "All Warnings" and the compiler will say something about it.

 

Enjoy SourceBoost.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Thanks for your reply Reynard, much appreciated.

​I did not realise delays are char only since I was using a tutorial called WINK LED.

one of the lines stated:

delay_ms(500) // pause 0.5 seconds  

Since it's my first bit of coding was following it to the letter & blindly as the author new much more than I do.

Shame delays can be initialised as unsigned int.

 

All the best.

Share this post


Link to post
Share on other sites

Forgot to mention:

The tutorial is from these forums:

it was from a tutorial called 'pic Micro Programming In Boostc For Beginners'

Apart for that, it's a great tutorial and I plan to finish it.

So my thanks goes out to the author :)

I have corrected the tutorial code to produce correct delays.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Thanks Pavel.

This would also apply to:

if(duration==1000)       // if duration equals 1000ms,
   {
   duration=990;            // make it 990ms.
   }                        // this will limit the max delay.
     }
 if(button3)                // if button3 is pressed, execute
 {                          // the following statements.
   duration-=10;            // reduce delay by 10ms.
   if(duration==10)         // if delay equals 10ms,
   {
   duration=20;             // make it 20ms.
   }                        // this will limit the min delay.
     }
 if(button1==0)             // if button1 pin is not pressed,
 {                          // execute the statements below 
 check1();                  // call routine check1.
 portb <<= 1;          // shift bits in portb to its left, ones.
 delay_ms(duration);        // pause for the value of duration.

Further down.

Unless it does not apply to this since:

int duration; 

so ms is no longer a char but integer?

But if :

Reynard, on 01 May 2014 - 10:15 AM, said:

You cannot have a any timer argument greater than 255.

The timer functions take a char value (8 bits).

 

 

Then I can't see it being the case.

Edited by medelec35

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...