CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Simulation code works, however when I download ... boom
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
link555



Joined: 29 Jul 2010
Posts: 14
Location: North Vancouver

View user's profile Send private message

Simulation code works, however when I download ... boom
PostPosted: Thu Jul 29, 2010 10:08 am     Reply with quote

So here is some ultra simple code that reads four switches on the Analog DSP eval kit board...
all I am doing is reading the 4 pb switches and outputing a LCD message.

In the CCS sim, I can run the program push any button and the message apears, and stays until the next button is pressed.

However when I download the code into the chip the push button B3 code automatically comes up, like the button was being held down, yet its not.
Code:

void main()
 {
 int pressed=0;
 int  written_flag = 0;
 
 SET_TRIS_B( GET_TRIS_B() | 0x1E );

 lcd_init();
 
 while(TRUE)
  {
  if(!input(PUSH_BUTTON_2))
   {
   pressed = 2;
   }
 
  else if(!input(PUSH_BUTTON_3))
   {
   pressed= 3;
   }
 
  else if(!input(PUSH_BUTTON_4))
   {
   pressed= 4;
   }
 
  else if(!input(PUSH_BUTTON_5))
   {
   pressed= 5;
   }
  else
   {
   pressed = 0;
   }
 

if(pressed == 0)
 {
 if( written_flag != 0)
  {
  //do nothing
  written_flag = 0;
  }
 }
 
 if(pressed == 2)
 {
 if( written_flag != 2)
  {
  printf(LCD_PUTC, "\fWhat are you ?");
  written_flag = 2;
  }
 } 
 
 if(pressed == 3)
 {
 if( written_flag != 3)
  {
  printf(LCD_PUTC, "\i'M mELTiNg ?");
  written_flag = 3;
  }
 } 
 
 if(pressed == 4)
 {
 if( written_flag != 4)
  {
  printf(LCD_PUTC, "\fOh Man... ?");
  written_flag = 4;
  }
 }
 
 if(pressed == 5)
 {
 if( written_flag != 5)
  {
  printf(LCD_PUTC, "\fYou bugs me..");
  written_flag = 5;
  }
 }
  }
 
 }

Its not clean but its simple to follow....
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 10:33 am     Reply with quote

Welcome to the 'real world', simulations are not REAL.

I can see (actually NOT see) areas of concern.
need more info...
like processor type..
version of PCM (PCH,PC???)

Port/pin assignments for the 'push_button_s' (defines ?)
Setup routines (disabling onboard peripherals that conflict with I/O pins)
Code for functions you created..
jes trying to help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 10:57 am     Reply with quote

Post your #fuses. It's very common for a simulator to ignore the
effects of certain fuses that are critical in real hardware (LVP/NOLVP for
example).

And what is the "CCS simulator" ? I'm not aware that they have one.
There's MPLAB simulator. There's Proteus. And maybe some others.

Also, I don't see any debounce code for your pushbuttons. I suggest
that you use the 'button' code here. It does debouncing:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837
link555



Joined: 29 Jul 2010
Posts: 14
Location: North Vancouver

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 2:32 pm     Reply with quote

Thanks guys!

here is the code with headers, I am using the CCS debug mode and it runs.

Code:

#include <33fj128gp706.h>
#device ICD=TRUE

#fuses HS,NOWDT,NOCOE,PR
#use delay(clock=12M)


#define GREEN_LED       PIN_C14
#define YELLOW_LED      PIN_G9
#define RED_LED         PIN_C2


#define LCD_RS_PIN      PIN_D1
#define LCD_RW_PIN      PIN_D2
#define LCD_ENABLE_PIN  PIN_D3
#define PUSH_BUTTON_2   PIN_B2
#define PUSH_BUTTON_3   PIN_B3
#define PUSH_BUTTON_4   PIN_B4
#define PUSH_BUTTON_5   PIN_B5

#include <lcd.c>


#define BOTTOM_POT_PORT sAN9
#define BOTTOM_POT_CHANNEL 9

#define TOP_POT_PORT sAN8
#define TOP_POT_CHANNEL 8

typedef enum{GREEN =0, YELLOW, RED}colors;

//---------------------------------------

#include <protoalone.h>
#include <TLV320AIC23B.c>
#INCLUDE <stdlib.h>

//-------------------------------------------------------------------------

 //-------------------------------------------------------------------------

void main()
 {
 int pressed=0;
 int  written_flag = 0;
 
 SET_TRIS_B( GET_TRIS_B() | 0x1E );

 lcd_init();
 
 while(TRUE)
  {
  if(!input(PUSH_BUTTON_2))
   {
   pressed = 2;
   }
 
  else if(!input(PUSH_BUTTON_3))
   {
   pressed= 3;
   }
 
  else if(!input(PUSH_BUTTON_4))
   {
   pressed= 4;
   }
 
  else if(!input(PUSH_BUTTON_5))
   {
   pressed= 5;
   }
  else
   {
   pressed = 0;
   }
 

if(pressed == 0)
 {
 if( written_flag != 0)
  {
  //not done yet
  written_flag = 0;
  }
 }
 
 if(pressed == 2)
 {
 if( written_flag != 2)
  {
  printf(LCD_PUTC, "\fWhat are you ?");
  written_flag = 2;
  }
 } 
 
 if(pressed == 3)
 {
 if( written_flag != 3)
  {
  printf(LCD_PUTC, "\i'M mELTiNg ?");
  written_flag = 3;
  }
 } 
 
 if(pressed == 4)
 {
 if( written_flag != 4)
  {
  printf(LCD_PUTC, "\fOh Man... ?");
  written_flag = 4;
  }
 }
 
 if(pressed == 5)
 {
 if( written_flag != 5)
  {
  printf(LCD_PUTC, "\fYou bugs me..");
  written_flag = 5;
  }
 }
  }
 
 }
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 3:59 pm     Reply with quote

I see that ICD=TRUE..so...

any chance that the ICD is clobbering you ?
link555



Joined: 29 Jul 2010
Posts: 14
Location: North Vancouver

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 4:26 pm     Reply with quote

I comment that out when I download to the chip, thanks!
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jul 29, 2010 7:16 pm     Reply with quote

If you are setting TRIS manually the you need to include

#use FAST_IO(B)
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 5:43 am     Reply with quote

With the default IO setting, #USE_STANDARD_IO, the compiler takes care of the TRIS registers automatically and will ignore your SET_TRIS_B. If you really need to handle the TRIS differently then you need to use fast IO, #USE_FAST_IO for your SET_TRIS_B to have any effect.

Most applications stay with the default and let the compiler handle the TRIS itself.
_________________
The search for better is endless. Instead simply find very good and get the job done.
link555



Joined: 29 Jul 2010
Posts: 14
Location: North Vancouver

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 6:44 am     Reply with quote

Thanks so much guys, I will delete that set the tris bit line. But unfortunately this does not solve the original problem.

I finally broke out the multimeter- I know... should have done a while ago....

So that push button of the CCS eval board has a 4.7k resistor connected to 3.3VDC the other side is tied to digital common. All other push button show close to the 3.3V when not pushed, this on PB3, shows 0.47VDC. the resistor is connected and tested ok with the omhmeter. The push button tested ok too.

But my real question now is why would the debug mode work at all with push button?


Last edited by link555 on Fri Jul 30, 2010 7:22 am; edited 1 time in total
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 7:08 am     Reply with quote

From the Analog DSP Dev Kit PCB layout, I don't see any pull-up resistors for the push-button inputs. (I don't have a schematic). In this case, you need to enable the internal dsPIC pull-up resistors.
link555



Joined: 29 Jul 2010
Posts: 14
Location: North Vancouver

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 7:24 am     Reply with quote

Sorry FvM just saw your post yes it has 4.7K pull up resistors to 3.3Vdc.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 9:33 am     Reply with quote

Did you check that the MCU is running? I mean, did you do a basic test: a Led attached to PIN_xx and watch if it
blink at the expected rate.
Code:

do
   { output_toggle(PIN_xx);
     delay_ms(1000);
   } while(1); 

Also, be aware that all the pins that is shared with an analog input, after reset is configured as an analog input in
this device and in all that have 2 AD modules.

Humberto


Last edited by Humberto on Fri Jul 30, 2010 10:01 am; edited 1 time in total
link555



Joined: 29 Jul 2010
Posts: 14
Location: North Vancouver

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 10:01 am     Reply with quote

Thanks yes the LCD works for PB2 and PB3 however anything after PB3 does not. I now believe the push button 3 hardware has a issue as the' not depressed' voltage is 0.47Vdc not 3.3Vdc
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 10:02 am     Reply with quote

Quote:
Did you check that the MCU is running?

Well, a working LCD display suggests it's running, isnt it?

Are you sure, that the code not shown in your post (e.g. lcd.c) doesn't modify the settings of the push-button pins? Generally, I would trace the code execution with a debugger and check the state before the push-button test.

P.S.: I assume, you checked for conflicting hardware connections of PIN_B3 in the Dev-Kit schematic.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 10:34 am     Reply with quote

Quote:

Well, a working LCD display suggests it's running, isnt it?

NOP. He did not mention that the LCD is running in the real world, he mentioned an CCS sim that do
not exist, at least we are not updated that CCS released such development tool.

Humberto
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group