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

Digital output voltage is too low

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rnome



Joined: 18 Dec 2006
Posts: 20
Location: europe (Turkey)

View user's profile Send private message

Digital output voltage is too low
PostPosted: Wed May 11, 2016 2:44 pm     Reply with quote

Hi all,

I'm developing a led driving unit with 4 different modes (on,off,async,sync). I prepared both software and hardware but it seems there is something wrong in the code. I suspect the software because real time test and simulation gives the same failure output.

at first here is the code
Code:

#include <16F628A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fast_io(A)
#use fast_io(B)

boolean pressed=false;
boolean toggle=false;
int mode=0;
int counter=0;

#int_TIMER2
void TIMER2_isr(){
   
   ++counter;

   if(counter==50){         //250ms
      counter=0;
      switch(mode){
         case 0:         //all off
              output_low(PIN_B1);
              output_low(PIN_B2);
              output_a(1);
              break;
         case 1:         //all on
              output_high(PIN_B1);
              output_high(PIN_B2);
              output_a(2);
              break;
         case 2:         //flash syncron
              output_toggle(PIN_B1);
              output_toggle(PIN_B2);
              output_a(4);
              break;
         case 3:         //flash asyncron
              output_bit(PIN_B1,toggle);
              if(toggle)
                   toggle=false;
              else
                   toggle=true;
              output_bit(PIN_B2,toggle);
              output_a(8);
              break;
        }
   }
}

void main(){
   output_b(0x00);
   output_a(0x00);
   set_tris_b(0x01);
   set_tris_a(0x00);

   setup_timer_2(T2_DIV_BY_16,0x82,12);     //4*16*130*12/20Mhz=4.99ms
   
   enable_interrupts(int_TIMER2);
   enable_interrupts(GLOBAL);
   
   for(;;){
      if(input(pin_b0)==1){
         if(!pressed){
            pressed=true;
            mode++;
            if(mode==4)
               mode=0;
         }
      }
      else{
         pressed=false;
      }
   }
}


There are 2 LEDs connected PortB_1 and PortB_2 and each time I press a button which is connected to PortB_0, light mode of the 2 leds will change. Modes are : both LEDs off, both LEDs on, LEDs flicker synchronously, LEDs flicker asynchronously.

No matter what I do, LED1 is always off and LED2 starts working only on last mode but voltage output of the PortB_2 is around 1v which is quite odd. I suspect of fuse selections but there are the ones that I use before.

So anyone has an idea, is extremely welcome Smile
_________________
live fast, never rest and do your best
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 11, 2016 4:02 pm     Reply with quote

Post your schematic.

How to post an image on the CCS forum:
Go to this website: http://postimage.org/
Upload your image. Select family safe. Then click the first button for
"Hotlink to Forum" to get a link to the image.
Then go to the CCS forum and type Ctrl-V to paste the link into a post.

If postimage.org doesn't work in your country, then use Google to find
another free image hosting site for forums.
rnome



Joined: 18 Dec 2006
Posts: 20
Location: europe (Turkey)

View user's profile Send private message

PostPosted: Thu May 12, 2016 12:45 pm     Reply with quote

Hi PCM programmer,

you can find my schematic as below.



Those 4 set of LEDs which connected at port A are used as mode indicator.
ps: I used pull-up resistor at MCLR on my real circuit.
_________________
live fast, never rest and do your best


Last edited by rnome on Thu May 12, 2016 1:22 pm; edited 1 time in total
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu May 12, 2016 1:20 pm     Reply with quote

Hi,

Well, for such a simple circuit, you've made just about every mistake that can be made Shocked

To wit:

1. You need current limiting resistors in series with the base of each transistor. Something like 10K should be fine.

2. Your current limiting resistors in series with LED1 and LED2 are too large. Something like 500 ohms is OK.

3. You have no current limiting resistors in series with LED3, LED4, LED5, and LED6. Again, 500 ohms is OK.

4. You have no pull-up on MCLR. A 10K resistor is probably good here.

5. It's much more common to put a 10K pull-up on your switch input, and connect the free end of the switch to Gnd. Thus, pushing the switch pulls the switch input to Gnd, while releasing it causes the input to go high via the pull-up.

I suspect that there is no hardware here at all, right? IOW, this is a pure simulation?
_________________
John

If it's worth doing, it's worth doing in real hardware!


Last edited by ezflyr on Fri May 13, 2016 6:28 am; edited 1 time in total
rnome



Joined: 18 Dec 2006
Posts: 20
Location: europe (Turkey)

View user's profile Send private message

PostPosted: Thu May 12, 2016 1:31 pm     Reply with quote

Hi ezflyr,

Thanks for your input. You are right this one is just for simulation so I didnt deal with current limiting resistors on LEDs and NPN base but in real circuit they exist with reasonable values ;)

So I think my chip might be a defective one. I will try with another one and share the outputs.
_________________
live fast, never rest and do your best
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu May 12, 2016 1:54 pm     Reply with quote

re: LEDs

I'm curious as to why you decided to 'direct drive' 4 of the LEDs and not the other 2 ? The PIC is 'happy' driving LEDs, just use a 500r in series as posted above, there is no need for the NPN transistors and base resistors.

Also if you can live with a 4MHz clock, use the internal one...saves 3 components, some wiring and is reasonably accurate.

Jay
rnome



Joined: 18 Dec 2006
Posts: 20
Location: europe (Turkey)

View user's profile Send private message

PostPosted: Thu May 12, 2016 2:06 pm     Reply with quote

Those 2 individual LEDs will be driven by higher voltage (around 12v) thats why I separated them.

Yeah you are right, maybe I can use internal clock. 4Mhz is good enough if I can get 5ms timer interrupts. I will check timer parameters.
_________________
live fast, never rest and do your best
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu May 12, 2016 2:15 pm     Reply with quote

Funnily enough this is a case where the simulation 'knows' that LED's have a Vf, and is doing the correct thing, and stopping the PIC working when it is massively overloaded....

Also the two outputs driving the transistor bases are being clamped to just over 0.6v. A real PIC might well start releasing magic smoke at this point.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 12, 2016 4:18 pm     Reply with quote

Here's a page that discusses the transistor base resistor size in a fair
amount of detail. It's a good tutorial page:
http://www.ermicro.com/blog/?p=423
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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