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

RTOS for multiplexing

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



Joined: 07 Oct 2011
Posts: 2

View user's profile Send private message Send e-mail

RTOS for multiplexing
PostPosted: Fri Oct 07, 2011 6:38 am     Reply with quote

Hi

I am trying to multiplex a 7 segment led display(2 digit) using RTOS.
MCU - PIC16f628a
A2 and A3 are driving the common cathode of the display. A0 is connected to a button which output the variable "count" to portb when pressed.
portb is connected to segments
Problem is when i power up the circuit sometime A2 and A3 blinks together
sometime A2-ON, A3-OFF (A2-OFF, A3-ON) which is okay for the application. Please someone advise me.

Code:
#include <16f628a.h>
#use delay (int=4000000)

#use rtos(timer=0, minor_cycle=1ms)

int count;
unsigned int var1=0;
//
#task(rate=200ms, max=1ms)
void live1()
{
output_toggle(PIN_A2); // Toggle RA2
}
//
#task(rate=200ms, max=1ms)
void live2()
{
output_toggle(PIN_A3); // Toggle RA3
}

// Declare TASK "Display" - called every 10ms
//
#task(rate=10ms, max=1ms,queue=1)
void Display()
{
if(rtos_msg_poll() > 0) // Is there a message ?
{
output_b(rtos_msg_read()); // Send to PORTB
}
}
//
// Declare TASK "Generator" - called every millisecond
//
#task(rate=1ms, max=1ms)
void Generator()
{
count++; // Increment count
if ((input(PIN_A0) == 1)&& (var1 ==0)) // Switch pressed ?
{                                                     
var1 =1;                                            //switch debounce
rtos_msg_send(Display,count); // send a message
}
else if ((input(PIN_A0)==0) && (var1 ==1))
var1 = 0;
}

void main()
{
set_tris_a(0x03); // A0 and A1 input
set_tris_b(0x00);    /portb is output
output_b(0x00);    //clear portb
output_a(0x04);    //to make sure A2 and A3 are not blink together
rtos_run();
}

asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Oct 07, 2011 8:26 am     Reply with quote

you should start by reading about the set_tris() function.

Since you did not declare any FAST_IO in your setup - this is
potentially one of your issues

Then - the button press detector makes no sense in the time domain , since just for starters - how do you know that the button press is 'clean' ??


** why is count a signed integer ??

** don't you believe in setting fuses??

** is this ACTUAL HARDWARE or a simulation ??

** why cant var1 be an int1 ??

** not knowing what actual display circuit you have ( schematic please??)
there is no way to predict what is going on with your
"" 7 segment led display(2 digit) ""

if you are switching commons on TWO LED 7 segments at 200 ms ( guessing here) - WHERE are you selecting the proper port_B() data to SHOW??

the LOGIC of what you are doing escapes me as you would ONLY send a single BYTE to port b of a SIGNED integer COUNT - IF the button press -
code actually worked.
you are in trouble conceptually and logically here.

lastly-
when the button IS pressed - how long will it take for count to increment by 1000?? ( with 'count' able to represent +/-127 ??? )

you are not thinking clearly in the time domain either !!!

RTOS won't fix that ;-))
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