Active low switch and storing a high bit variable
Moderator: Benj
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Active low switch and storing a high bit variable
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
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
- Attachments
-
- MLCR_01.fcf
- Here is the file inside first decision I attempt to store a high bit Variable RUN_REEL by using input for E2 with a not
- (13.84 KiB) Downloaded 276 times
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
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
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
- Attachments
-
- Active_Low.fcf
- (11.5 KiB) Downloaded 264 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Active low switch and storing a high bit variable
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.
Tips section is for posting tips and not for starting off with a question.
Martin
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
MOTOR CONTROL PROGRAM SIMULATES BUT WON'T RUN IN IN 16F877A
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.
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.
- Attachments
-
- Active_Low 5.fcf
- THIS PROGRAM WOULD BE COOL FOR OTHER NEWBIES TO SEE FUNCTIONALITY OF SOME COMMON INPUT OUTPUT TOOLS, LIKE ON OFF SWITCHES,
PULSE WIDTH MODULATORS(PWM) ANALOG TO DIGITAL CONVERTERS(ADC) AND THE USE OF THE ICONS - (20.28 KiB) Downloaded 263 times
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
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
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
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Active low switch and storing a high bit variable
Hi markus747,
The warning I got was:
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
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)
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
- Attachments
-
- Active_Low 6.fcf
- (20.29 KiB) Downloaded 255 times
Martin
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
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.
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...
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
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);
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
- Attachments
-
- Active_Low 7.fcf
- (22.57 KiB) Downloaded 262 times
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
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 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..
- Attachments
-
- 877a.JPG (75.86 KiB) Viewed 12646 times
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: Active low switch and storing a high bit variable
It works thanks!!!! yes I want to have station 1 also control same same pwm but ran out of iconsmedelec35 wrote:Hi markus747,
The warning I got was:This is because you are calling the same component macro (PWM) in main and in your interrupt, which will lead to corruption.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)
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
Your Awesome!!
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: Active low switch and storing a high bit variable
I am sorry to say active_low6 works but not active_low7 although it sure looks right.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..
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!!
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
HI,
Enamul
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.active_low7 controls led and relay from station 2 but no response from PWM or station 1 controls.
Enamul
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: Active low switch and storing a high bit variable
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.
- Attachments
-
- compiler message active_low 7.txt
- (6.72 KiB) Downloaded 216 times
-
- circuit board.jpg
- (253.24 KiB) Downloaded 2343 times
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: Active low switch and storing a high bit variable
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.Enamul wrote:HI,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.active_low7 controls led and relay from station 2 but no response from PWM or station 1 controls.
Enamul
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.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
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
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
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
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
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
- Attachments
-
- Active_Low 7.hex
- (1.94 KiB) Downloaded 171 times
-
- Active_Low 7.fcf
- (20.9 KiB) Downloaded 184 times
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
READING ANO GIVES DATA FROM AN1 What the heck?
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.
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.
- Attachments
-
- Active_Low 9.fcf
- (49.17 KiB) Downloaded 168 times
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
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
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
- Attachments
-
- Active_Low 10.hex
- (3.16 KiB) Downloaded 156 times
-
- Active_Low 10.fcf
- (22.66 KiB) Downloaded 179 times
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: Active low switch and storing a high bit variable
YES THAT WORKS the station 2 runs with speed2 set at 200 but station 1 doesn't move with speed value set to 60Enamul 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.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
Hi,
I have just tested the program in hardware. The program works absolutely fine..So in your case it seems any hardware issue..
Enamul
I have just tested the program in hardware. The program works absolutely fine..So in your case it seems any hardware issue..
Enamul
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: Active low switch and storing a high bit variable
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 workedEnamul 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
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Active low switch and storing a high bit variable
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
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