Settting Clearing single bits on the output

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello Forum,
Controller=PIC16F610.
On port a I set bit 1 to high. Later in the program port a bit 2 is set to high. In the simulator all is running well. Now I program the pic. In that moment, when bit 2 is set, bit 1 is cleared!?! I suppose, that the output-box can set and cleared single bits (I tested the controller outside of the programer). Can anybody give me some tips to manage this simple things?

Jörg

medelec35
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: Settting Clearing single bits on the output

Post by medelec35 »

Hi Jörg ,
Sounds like you are selecting the whole port rather than the individual Bit.
If you want to set Bit A2 high without affecting the any other bits then simplest way is to select individual bit as in the pic below:
Individ bits.png
(43.06 KiB) Downloaded 8147 times
If you have already set the individual bit and still does not work, then if state which version of Flowcode your using, and post flowchart (if it's not commercially sensitive), we can take a look at it for you.


Martin
Martin

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hi Martin,
thanks for your answer. To set and clear a bit with the value 1 or 0 is running. I want to know, is there a bridge in the output-box vom a variable to any bit of an port.

See the attached fcd-file. The led toggles on and off in the simulator, but not in the chip. My aim is to toggle on bit2 from port c.
Attachments
Port a Problems_01.fcf
(6.5 KiB) Downloaded 339 times

medelec35
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: Settting Clearing single bits on the output

Post by medelec35 »

Hi Jörg,
You had the LED set on port C0, and the C0 output was being toggled. I have set the o/p C2 for toggling.

Not sure what you want the other out puts to do yet?

Martin
Attachments
Port a Problems_02.fcf
(5.5 KiB) Downloaded 301 times
Martin

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello!
Try this fcf "...03" in the attachment. You changed to port C bit 2. This is running. I put another output "portc bit 0" in the program ( timer 0 int).
In the simulation it is running. Not in the chip. When bit 0 is written, LED at bit 2 is off ???

A variable is setup to char (255) / read a bit from the port / save in the variable / bit to byte ??? / output the variable to bit 0 = OK / output the same variable to bit 1 clears the first output to bit1 !!!
The port is not written to 1 bit. He is written as a byte!

What I thought is the following:
01.) bit 0 read into a variable
02.) value variable = 0b0000000"1"
03.) write to bit 2 --> writes only the bit 2 not the whole port

Other Idea for flowcode:
01.) bit 0 read into a variable
02.) value variable = 0b 0000 000"1" --> 2 x bit shifting "<< 2" --> value variable = 0b 0000 0"1"00
03.) write to bit 2 --> writes only the bit 2 not the whole port

Or:
01.) read a bit from output into a variable, declared as a bit.


best regards
Jörg
Attachments
Port a Problems_03.fcf
(5.5 KiB) Downloaded 332 times

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello to anybody, who read this.
I´m now trying more than a week on a standard problem and no one has a idea for me ???????????

I try to explain my problem:
01.) I set bit 0 at port c
02.) I set bit 1 at port c
03.) On every bit is a led connected --> In the simulation both leds are on.

But now programmed to PIC16F610:
Led at bit 0 is off and led at bit 1 is on !?!?!?!?!

Measured with oscilloscope:
01.) After reset the Bit 0 have a very short spike
02.) After the spike bit 1 is on continuselly

Can anybody looks to the program whats wrong ???

Best regards
Jörg Güldner
Attachments
Port a Problems_001.fcf
(4.5 KiB) Downloaded 311 times

medelec35
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: Settting Clearing single bits on the output

Post by medelec35 »

The bits do work independently. It looks correct on the simulator but not on hardware because of the simulator is running much slower.
You have set the flowchart so when led_counter reaches 19 then RC0 is toggled.
When led_counter led_counter reaches 20 then RC2 is toggled.
Since they are toggle with the save value:
Your eyes won’t be able to tell the difference since there is only 16.38ms between RC2 and RC0 changing to the same status.
I have made an alteration so you can see that the bits of port are controlled independently.
When I get a chance I will look at your latest flowchart.
Martin
Attachments
Port a Problems_03.fcf
(7 KiB) Downloaded 324 times
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Settting Clearing single bits on the output

Post by Benj »

I´m now trying more than a week on a standard problem and no one has a idea for me ???????????
Martin has been helping you right through from your first post, please don't be so rude to him or he may choose not to help you next time and you will have to wait for us on the weekday 9 to 5 shift.

Also Sat through to Mon does not count as a week in my book.

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello Benj,
don`t misunderstood, that I posted a complete week to the forum. I was trying with the board more than a week for my himself. I think, that other users have not this problem like me.
If you don`t believe me, I can make a short filmsequence. In the moment I must find a end for a project. To shift around I decide to create a "temp_porta"-variable and set and clear the bits incide this one.
When the timer interrupt occurs, the port will be then written complete.

Best Regards

Jörg Güldner

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Settting Clearing single bits on the output

Post by Benj »

Hello Jörg,

No misunderstanding, just do not say no one is helping you when someone blatantly is.

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello Ben,
I´ve just made a little video. But the File was to large. I take a picture out and printed as pdf. Left down in the corner are 3 LED`s connected to port c from the programer board.
Bit 0 and 2 in the simulation is lightning, but at the programmer only bit 2.

Best regards

Jörg Güldner
Attachments
Port_test_01.pdf
(206.62 KiB) Downloaded 335 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Settting Clearing single bits on the output

Post by Benj »

Hello,

I have had a look at your program and the code is being generated correctly so I'm not too sure why the pins are not functioning correctly. It might be worth using a multimeter and checking the LED is correctly connected to the microcontroller pin this just rules out any breaks on the circuit board. It might also be worthwhile using the multimeter to check to see if the output pin is actually going high/low as the port or pin could potentially be damaged on the device.

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello Benj,
I´ve bought another controller PIC16F677 to test the simple program with the ports.
I write a little program and looks what happens to the PIC16F610 and PIC16F677. The program does not more as to set port c bit 0, wait 1ms, sets port c bit 1 in a loop. I made oscilloscope prints and bring them to an pdf. There you can see, thats the hardware is running well. The PIC16F677 works correctly. The other one switched off bit 0 in that moment, when bit 1 is set ???
The complete software and compiled files are also attached. Can it be, that there is a error in the fcd-file or so?

Best regards

Jörg Güldner
Attachments
Portproblem_16F610_01.zip
(118.67 KiB) Downloaded 227 times

dbasnett
Posts: 125
Joined: Mon Aug 15, 2011 1:54 pm
Has thanked: 8 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by dbasnett »

You will need to change the Chip Settings to match your chip.
Attachments
Flowcode1.fcf
(7 KiB) Downloaded 255 times

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello dbasnett,
thanks for an idea to my problem.
You wrote: "You will need to change the Chip Settings to match your chip."
This means, that in the Program the chip, in this case PIC16F610, was not correctly set. Please can you tell me the wrong point I´ve clicked to?
In your fcf-file you solve it in that way, that you spent a byte, where the bits will be manipulate and writes it complete as a byte to the port. This is although
my idea, I posted already.

Please have a further look to the oscilloscoped pictures and find a solution for that bit setting.

Best regards
Jörg Güldner

dbasnett
Posts: 125
Joined: Mon Aug 15, 2011 1:54 pm
Has thanked: 8 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by dbasnett »

I wasn't able to set the project to any of the chips you mentioned, so I used a different one. Since you are using them I thought you'd be able to just change the chip in the project and then try it.

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

The problem for me is, that with the PIC16F610 are a serie boards made for our customer and now the software is not running.
There gives a solution to shift around this bug, wherever he was. But it was really good, to found, why it`s not working.
So I want to know, what happens belonging to my oscilloscope pictures.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Settting Clearing single bits on the output

Post by Benj »

Hello,

I've had a look at the FCD file and there is no problem there. Have you tried another 16F610 to ensure the one you are testing with is not damaged. If you are still having problems then I will see if we have a 16F610 here and give it a quick test.

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello Benj,
I tried all the 4 chips I bought. They show the same error. When the program is ready, led bit 0 is off and led bit 2 is on. I´ve got today a replace chip for my customer, the PIC16F688 with 14 pins. For the program I need normal pin function, so I can replace the PIC16F610. The same program runs well in the PICF688. Both leds are on !!!. The original name from the PIC16F610 = PIC16F610 -I/P 1036MC9. So I think, that there are 2 ways, where the error can be. The first is, that the serie of the chip have problems or there must be a bug inside the flowcode. May be it`s possible to test at your own with hardware, to see what happens.

Best regards
Jörg Güldner

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Settting Clearing single bits on the output

Post by Spanish_dude »

Hi,

I had a quick look at your code. (Downloaded the zip and checked the .c file in the 'not working' folder).
The generated code is correct...

Code: Select all

void main()
{
	//Interrupt-Initialisierungs-Kode
	option_reg = 0xC0;

	//Output: 0 -> PORTC
	trisc = 0x00;
	portc = 0;
	delay_s(1);

	//Output: 1 -> C0
	trisc = trisc & 0xfe;
	if (1)
		portc = (portc & 0xfe) | 0x01;
	else
		portc = portc & 0xfe;
	delay_ms(1);

	while (1)
	{
		//Output: 1 -> C1
		trisc = trisc & 0xfd;
		if (1)
			portc = (portc & 0xfd) | 0x02;
		else
			portc = portc & 0xfd;
	}
	mainendloop: goto mainendloop;
}
Just to be sure I looked at the ASM code and everything looks fine ...
This is just the part where you set RC0 to 1. The part where you set RC1 is exactly the same except it's not 0xFE but 0xFD and not 0x01 but 0x02.

Code: Select all

	MOVLW 0xFE
	BSF STATUS, RP0
	ANDWF gbl_trisc, W
	MOVWF gbl_trisc
	MOVLW 0xFE
	BCF STATUS, RP0
	ANDWF gbl_portc, W
	MOVWF CompTempVar2201
	MOVLW 0x01
	IORWF CompTempVar2201, W
	MOVWF gbl_portc
This could be re-written as:
ACCU = 0xFE
ACCU = ACCU & TRISC
TRISC = ACCU
ACCU = 0xFE
ACCU = ACCU & PORTC
CompTempVar = ACCU
ACCU = 0x01
ACCU = ACCU | CompTempVar
PORTC = ACCU

Nicolas

Jörg Güldner
Posts: 77
Joined: Wed Jun 22, 2011 3:32 pm
Has thanked: 17 times
Been thanked: 11 times
Contact:

Re: Settting Clearing single bits on the output

Post by Jörg Güldner »

Hello to all, who read this,
The result of my problems is now collect to a list with cpus I tested.
The software flowcode is checked from differant persons and founded for OK.

I tried to set only 2 bits writing one after the other:
PIC16F610 = is not running
PIC16F616 = OK (This is the big brother of 16F610)
PIC16F688 = OK
PIC16F677 = OK

Best regards
Jörg Güldner

Post Reply