Page 1 of 1
Active low switch and storing a high bit variable
Posted: Wed Jul 25, 2012 7:51 pm
by markus747
I am using pic 16f877 for controlling a cable reel and can't seem to get a variable to be stored high when switch is active low.
I am a newbie and have got some advice from successful C programmer tried to add a tilde in front or behind port to invert but it didn't work.
There must be a simple way to store a high from a active low switch.
On the other hand I don't want Variable modified when switch is high, and not being pressed. another active low input will be used for off PORT B0 which should be interrupt driven by Interrupt on Change falling edge.For Off
Please any suggestions greatly appreciated
Re: Active low switch and storing a high bit variable
Posted: Thu Jul 26, 2012 2:08 am
by Enamul
Hi,
Here is a basic program using active low input to set high in one variable which will not changed if input goes high or not pressed..RB0 falling edge INT is used to clear that register by another switch...
Hope that will help
Enamul
Re: Active low switch and storing a high bit variable
Posted: Thu Jul 26, 2012 7:34 am
by medelec35
I have moved topic to Flowcode V5 Free Edition because it is more relevant there.
Tips section is for posting tips and not for starting off with a question.
MOTOR CONTROL PROGRAM SIMULATES BUT WON'T RUN IN IN 16F877A
Posted: Tue Jul 31, 2012 3:01 am
by markus747
Newbie with free version 5. think this program is the AWESOME. or it sure looks simple. Anyway I created this program with 2 control stations to control a motor from, and it simulates great!!
But I can't seem to get it to run in my pic16f877A. It warns only 4 lines of C code will be compiled not sure if this is my issue.
I have used all, the max allowed Icons in the demo version allows 16 icons each in 4 macros.
As you will see only station 2 is complete needed a couple more icons. before I buy got to see a working compiled program.
so when station 2 ON switch is pressed Led comes on and PWM is running from ADC (knob) input Great!!.
A decision is used USING variable "RUN_REEL_2"(station 2) seems to work turning on outputs reading analog to digital converter
BUT when i program chip with PICKIT2 only the on/off of the relay and the led's seems to function.

Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 10:18 am
by Enamul
Hi,
You are not controlling PWM in station1? I am trying to check the program in free version..
Bcz in my version it compiles without any warnings...
Enamul
Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 11:51 am
by medelec35
Hi markus747,
The warning I got was:
Code: Select all
Serious Warning: Possible sw stack corruption, function 'FCD_PWM0_SetDutyCycle' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
This is because you are calling the same component macro (PWM) in main and in your interrupt, which will lead to corruption.
Not sure the purpose of pot connected to an1, as it does not appear to be controlling anything?
Try attached flowchart, and would you mind leting me know if it works or not please.
Martin
Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 12:39 pm
by Enamul
Hi,
Looking at the Panel you have made it seems to me that you are not upto what is your goal..I have made couple of changes to the flowcode...
1.
Code: Select all
trise = trise | 0x02;
FCV_SW = ((porte & 0x02) == 0x01);
What are you trying to do here...when PORTE<1> pin goes high, you want to put 0x01 in SW variable...??
The default sense is...
Code: Select all
trise = trise | 0x02;
FCV_SW = ((porte & 0x02) == 0x02);
Flowcode doesn't simulate c code yet..
2. You don't have any link with PWM and ADC in station1..I guess you want to control PWM when RD2 is pressed low and adc will change duty cycle...I have added that.
3. I guess you don't want to see Station1 LED is running when actually Station2 is working..I have changed that..
4. You shouldn't enable PWM when no station is running i.e., idle mode at the beginning of program..I have changed that by moving PWM enable when any of the button pressed..
5. At the start of code your station LED should be off..I have changed that.
6. As far I understand Master control is like full stop...so clear variable, turn off all LEDs and disable PWM..you don't need to send 0 duty cycle..
Hope that I am in right track and guiding you same...
Enamul
Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 12:50 pm
by Enamul
Hi,
I forget to tell that I have tested the attached program in Real PIC simulator and it works excellent..So it will work in hardware..
Here is the attached pic..
Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 6:08 pm
by markus747
medelec35 wrote:Hi markus747,
The warning I got was:
Code: Select all
Serious Warning: Possible sw stack corruption, function 'FCD_PWM0_SetDutyCycle' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
This is because you are calling the same component macro (PWM) in main and in your interrupt, which will lead to corruption.
Not sure the purpose of pot connected to an1, as it does not appear to be controlling anything?
Try attached flowchart, and would you mind leting me know if it works or not please.
Martin
It works thanks!!!! yes I want to have station 1 also control same same pwm but ran out of icons
Your Awesome!!

Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 6:41 pm
by markus747
Enamul wrote:Hi,
I forget to tell that I have tested the attached program in Real PIC simulator and it works excellent..So it will work in hardware..
Here is the attached pic..
I am sorry to say active_low6 works but not active_low7 although it sure looks right.
active_low7 controls led and relay from station 2 but no response from PWM or station 1 controls
I appreciate you great response to my requests for help, never got this kind of assistance from other forums.
I think its time to buy this sweet programmer Thanks again!!
Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 7:37 pm
by Enamul
HI,
active_low7 controls led and relay from station 2 but no response from PWM or station 1 controls.
I am still unclear why it will not work...Are you using two different Pot to control same PWM? I m testing now this in hardware..I want to be certain what's the problem.
Enamul
Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 10:28 pm
by markus747
I tried it from both station 1 and station 2 when running from station2 I measured variable voltage on pin 3 an2 but no out put on pin 17 ccp1, also tried to compile for pic16f887 with the same result. is there something I could send that would be helpful compiler messages? maybe because I am using demo version? just ordered professional version from
http://microcontrollershop.com/product_ ... ts_id=4137 which for 310.00 usd they are throwing in a programmer board.
Re: Active low switch and storing a high bit variable
Posted: Tue Jul 31, 2012 10:51 pm
by markus747
Enamul wrote:HI,
active_low7 controls led and relay from station 2 but no response from PWM or station 1 controls.
I am still unclear why it will not work...Are you using two different Pot to control same PWM? I m testing now this in hardware..I want to be certain what's the problem.
Enamul
Yes that is the goal, but I couldn't write enough code to enable 1 pot for each station. And only 1 at a time, AN0 for station 1,and AN1 for station 2 either would connect to CCP1 depending on which was last turned on.
Flow code you wrote looks better than what I had wrote and simulates better but i even tried to disable a few icons like disable PWM to see if that was corrupting code but no luck.
Re: Active low switch and storing a high bit variable
Posted: Wed Aug 01, 2012 5:01 pm
by Enamul
Hi,
From last evening I am extremely sick and can't even sit for computer...whenever I feel a bit better..I will test the pg and send hex to you..so that you can test performance of professional version as well.
Enamul
Re: Active low switch and storing a high bit variable
Posted: Thu Aug 02, 2012 5:53 pm
by Enamul
Hi,
I have modified the program..just for testing..removed ADC..speed and speed2 are pre-assigned to 60 and 200. To test whether the switching between stations work with PWM or not..If it works then I will post program with ADC..
Enamul
READING ANO GIVES DATA FROM AN1 What the heck?
Posted: Thu Aug 02, 2012 6:47 pm
by markus747
Using AN0 to set variable speed1 is not working correctly keeps getting value from AN1.
Unless I don't understand ADC(0) should be AN0 correct? and ADC(1) should be AN1 I put a breakpoint just before read ADC(0) please tell me what I am doing wrong.
Checked connections on both knobs (analog inputs) Simulates the same way that it runs.
Re: Active low switch and storing a high bit variable
Posted: Thu Aug 02, 2012 7:09 pm
by Enamul
Hi,
Have you tried the hex I have posted last time..it doesn't have adc...there might be an issue in adc..as I have swapped those in my program.
I have removed the adc in last one..now I have added it in right station..so it should work..Can you please let me know is that works or not?
Thanks,
Enamul
Re: Active low switch and storing a high bit variable
Posted: Thu Aug 02, 2012 7:25 pm
by markus747
Enamul wrote:Have you tried the hex I have posted last time..it doesn't have adc...there might be an issue in adc..as I have swapped those in my program.
YES THAT WORKS the station 2 runs with speed2 set at 200 but station 1 doesn't move with speed value set to 60
Re: Active low switch and storing a high bit variable
Posted: Thu Aug 02, 2012 8:04 pm
by Enamul
Hi,
I have just tested the program in hardware. The program works absolutely fine..So in your case it seems any hardware issue..
Enamul
Re: Active low switch and storing a high bit variable
Posted: Thu Aug 02, 2012 11:00 pm
by markus747
Enamul wrote:Hi,
Have you tried the hex I have posted last time..it doesn't have adc...there might be an issue in adc..as I have swapped those in my program.
I have removed the adc in last one..now I have added it in right station..so it should work..Can you please let me know is that works or not?
Thanks,
Enamul
THE hex file didn't work for me but I compiled to chip with the fcf and it worked,both stations and pwm varied the speed. just found 1 output 0>C3 which I changed to 1>C3 and then main relay worked
Re: Active low switch and storing a high bit variable
Posted: Thu Aug 02, 2012 11:22 pm
by Enamul
Hi,
Glad to know that it worked. I was wondering about the performance of Real PIC Simulator bcz not a single time it produces wrong result..I am using 30 days evaluation version and now thinking to buy one. It's handy in answering problem in forum.
By the way which programmer you are using? I guess you didn't get the Multiprogrammer board of MM. Hex should be fine..I have tested both in hardware.
Enamul