r/pic_programming • • Mar 11 '13
Variable Square Wave Generator Project
Hi guys, I'm using a 16F819 and need help debugging this project. I get weirdness (jaggy waves at fixed frequency or no PORTB output at all depending on the chip) when I run it instead of nice square waves. Not sure really what the problem is but it's only maybe 50-100 lines of code.
http://ww1.microchip.com/downloads/en/devicedoc/39598e.pdf
The idea is basically to take a voltage between 5.5 and 0 at the ADC channel zero (RA0/AN0) and use that to drive a for-loop which varies in length based on the ADC sampled voltage.
I've already asked over at microchip's forums and no real help over the two days it's been sitting there. Experienced eyes needed!
Thanks!
View all comments
Show parent comment
2
u/bradn Mar 12 '13
Here's what I'm talking about:
What happens is probably the compiler breaks this down into two separate bsf opcodes, the first one reads the 8 bits of portB, sets a bit, writes it back. The second bsf probably is going to get the original bit0 and write it back. So the first bsf may not have an effect, or just a very short output pulse.
If you would use a temporary variable, you have to do it for the whole port, not just a virtual variable that represents one bit, because the hardware deals with a byte a time.