Jump to content

Recommended Posts

Hi,

I'm hoping someone with more knowledge and experience may be able to solve a riddle? I have discovered (the hard way!) a peculiar behaviour of this pic. Simply put, GPIO4 controls the operation of GPIO1. For example, if both are set high, when GPIO4 is then set low GPIO1 follows about 500ns ( 1 instruction time at 8MHz? ) later. I've looked at the code, SourceBoost C and the listing file and they are correct. I've scoured the Microchip documents and trawled the internet, but found nothing that I might have missed. At first I firmly believed it was the two chips I had that were just faulty, but two more from a different source behave exactly the same.

 

Any ideas, anyone?

 

 

Share this post


Link to post
Share on other sites

Hi,

Thanks for the response. The webinar is interesting, but doesn't really give any clues as to my problem. I apologise for getting the PIC wrong - it should, of course, be 12F683.

I've checked all the usual suspects, CONFIG, ANSEL, ADCON0 etc, but nothing changes the effect. I haven't looked to see if the effect is present on any other GPIO's; for my intended application these were the only two of interest.

 

In the meantime I've solved the 'problem' by changing to a 12F615 - very similar but I wanted to use the EEPROM in the '683.

Share this post


Link to post
Share on other sites

your problem description sounds exactly like a classic Read Modify Write issue.

did you try using a shadow GPIO register ?

 

post your code if you want some help

Share this post


Link to post
Share on other sites

I have a similar problem on PIC12F629.

 

Here is my code

volatile bit Green @ GPIO.GP1;
volatile bit Out1 @ GPIO.GP5;

.....
......




while (true) 
{
  Green = 1;
  Out1 = 0;
  if (signalok() == true)
  { 
    Green = 0; 
    delay_us(200); 
    Green = 1; 
    delay_us(100); 
  } 
}

 

 

The Green pin is being put to 0 after the Out1 = 0. If I swap the lines - first Out1 = 0 then Green=1 then ofcourse Green stays 1.

 

I have tried to use a latch but still did not work
gplatch = gpio;
gplatch.5 = 0;
gpio = gplatch;

 

Any clues please?

Edited by Moonwalker

Share this post


Link to post
Share on other sites

As mentioned by RichardC in a previous post

 

Whenever you want to write to an output, a mirror (register) should be used, then you may write to the output through this mirror, like the example below:

#define Green   1
#define Out1    5

unsigned char gpio_mirror;

// usage...

gpio_mirror.Green = 1;          // to set pin hi
gpio = gpio_mirror;

gpio_mirror.Green = 0;          // to set pin lo
gpio = gpio_mirror;

// same methode to Out1 pin

Except for devices with LATx

 

br

Share this post


Link to post
Share on other sites

Another way to do the same with less code on set/clear output, imagining that the Green output is a led with cathode connected to the ground

This is also faster than previous example because just one instruction is needed to change the output state

#include <system.h>

#define GREEN   1             // Green pin

gpio   =  (1<<GREEN);         // precondition(HI) when triso.1 = 0 (as output)
trisio = ~(1<<GREEN);         // all pins = inputs except for GREEN pin = output

// macro
#define SET_GREEN_HI   ( trisio &= ~(1<<GREEN))  // <=> trisio.GREEN=0
#define SET_GREEN_LO   ( trisio |=  (1<<GREEN))  // <=> trisio.GREEN=1

void main( void )
{
    SET_GREEN_HI;             // turn Green out = high
    SET_GREEN_LO;             // turn Green out = low
}

reedited:

Forgot to mention that this issue only happens when u want to modify one or more port pin state(not the entire port).

This means if u write the entire port, mirror is not needed, but as a rule for devices without latx i use to write everything through the mirror.

 

hope this helps,

 

br

Edited by joli

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×