So I implemented a simple PWM on a PIC 12F617. Had to use the Compare peripheral with interrupts since I couldn't generate 50hz with the PWM module (too low frequency). I set a value to the CCPR1 register and when TMR1 reaches that value, an interrupt is firing in which I either set a pin to 1 or 0 to generate the duty cycle I want.
Now I also bitbang I2C in the main loop and here's the weird thing. I tested both PWM and I2C separately and they work fine. Once I enable them both, I2C gets completely messed (can see it on the scope), it looks like it can't pull the line low so it basically is oscillating a few millivolts below VCC when it wants to pull it down, while on other occassions it is just oscillating all over the place.
And now the even weirdest thing. While I2C alone works and stops when I enable PWM, if I disable PWM again, it won't go back to where it was before! At first I thought it was slave device acting up, but power cycling everything wont do anything. After a few hours of fiddling here and there looking for ghosts, breaking the whole circuit and assembling it again it starts to work again. So I enable PWM again and sure enough, everything is screwed again! I disable PWM and back to square 1, everything is messed and just doesn't want to work. I spent all day trying to find out whats going on, I've done this 4 times already and everytime the same story.
Anyone had this happen to them? Any advice on how to prevent PWM making everything go crazy?
Answer
From my comment above:
If only software bugs were involved in your problem, then power-cycling everything would restore normal operation. Therefore based on your story so far, there might be more to it than just software - providing an accurate schematic would help.
It has now been confirmed that the problem is more than a software problem, so I'm "promoting" this comment to an answer.
In your follow-up question "Is my GPIO pin fried?", a hardware fault has now been confirmed with at least GPIO pin GP2 on the PIC.
No comments:
Post a Comment